diff --git a/Winey-API/src/main/java/com/example/wineyapi/tastingNote/convertor/TastingNoteConvertor.java b/Winey-API/src/main/java/com/example/wineyapi/tastingNote/convertor/TastingNoteConvertor.java index 42409a7..a9ada15 100644 --- a/Winey-API/src/main/java/com/example/wineyapi/tastingNote/convertor/TastingNoteConvertor.java +++ b/Winey-API/src/main/java/com/example/wineyapi/tastingNote/convertor/TastingNoteConvertor.java @@ -101,8 +101,15 @@ public TastingNoteResponse.TasteAnalysisDTO TasteAnalysis(List tast } wineCountByType.put(wine.getType().getValue(), wineCountByType.getOrDefault(wine.getType().getValue() ,0)+1); for(SmellKeywordTastingNote smellKeywordTastingNote : tastingNote.getSmellKeywordTastingNote()) { - wineCountBySmell.put(smellKeywordTastingNote.getSmellKeyword().getName(), wineCountBySmell.getOrDefault(smellKeywordTastingNote.getSmellKeyword().getName(), 0) + 1); + wineCountBySmell.put( + smellKeywordTastingNote.getDirectYN().equals("N") ? + SmellKeyword.findByValue(smellKeywordTastingNote.getSmellKeyword()).getName() : smellKeywordTastingNote.getSmellKeyword(), + wineCountBySmell.getOrDefault(smellKeywordTastingNote.getDirectYN().equals("N") ? + SmellKeyword.findByValue(smellKeywordTastingNote.getSmellKeyword()).getName() : smellKeywordTastingNote.getSmellKeyword(), + 0) + + 1); } + System.out.println("wineCountBySmell = " + wineCountBySmell); } List> sortCountry = new ArrayList<>(wineCountByCountry.entrySet()); @@ -251,10 +258,11 @@ public TastingNote CreateTastingNote(TastingNoteRequest.CreateTastingNoteDTO req .build(); } - public SmellKeywordTastingNote SmellKeyword(SmellKeyword smellKeyword, TastingNote tastingNote) { + public SmellKeywordTastingNote toSmellKeyword(SmellKeyword smellKeyword, TastingNote tastingNote) { return SmellKeywordTastingNote.builder() - .smellKeyword(smellKeyword) + .smellKeyword(smellKeyword.getValue()) .tastingNote(tastingNote) + .directYN("N") .build(); } @@ -293,6 +301,7 @@ private TastingNoteResponse.TastingNoteListDTO toTastingNoteListDTO(TastingNote .tastingNoteNo(tastingNoteNo.get(result.getId())) .userNickname(result.getUser() != null ? result.getUser().getNickName() : "알 수 없음") .noteDate(result.getCreatedAt().toLocalDate().toString()) + .thumbnail(!result.getTastingNoteImages().isEmpty() ? result.getTastingNoteImages().get(0).getUrl() : null) .build(); } @@ -317,7 +326,9 @@ public TastingNoteResponse.TastingNoteDTO toTastingNote(TastingNote tastingNote, .varietal(wine.getVarietal()) .price(tastingNote.getPrice()) .officialAlcohol(tastingNote.getOfficialAlcohol()) - .smellKeywordList(SmellKeywordList(smellKeywordTastingNotes)) + .smellKeywordList(toSmellKeywordList(smellKeywordTastingNotes)) + .korSmellKeywordList(toKorSmellKeywordList(smellKeywordTastingNotes)) + .directKeywordList(toDirectKeywordList(smellKeywordTastingNotes)) .myWineTaste(MyWineTaste(tastingNote)) .defaultWineTaste(DefaultWineTaste(wine)) .tastingNoteImage(toTastingNoteImageRes(tastingNoteImages)) @@ -329,6 +340,18 @@ public TastingNoteResponse.TastingNoteDTO toTastingNote(TastingNote tastingNote, .build(); } + private List toDirectKeywordList(List smellKeywordTastingNotes) { + List directKeywordList = new ArrayList<>(); + + for(SmellKeywordTastingNote smellKeywordTastingNote : smellKeywordTastingNotes){ + if(smellKeywordTastingNote.getDirectYN().equals("Y")){ + directKeywordList.add(smellKeywordTastingNote.getSmellKeyword()); + } + } + + return directKeywordList; + } + private List toTastingNoteImageRes(List tastingNoteImages) { List tastingNoteImageList = new ArrayList<>(); @@ -363,13 +386,25 @@ private TastingNoteResponse.MyWineTaste MyWineTaste(TastingNote tastingNote) { .build(); } - private List SmellKeywordList(List smellKeywordTastingNotes) { + private List toSmellKeywordList(List smellKeywordTastingNotes) { + List smellKeywordList = new ArrayList<>(); + + for(SmellKeywordTastingNote smellKeywordTastingNote : smellKeywordTastingNotes){ + if(smellKeywordTastingNote.getDirectYN().equals("N")){ + smellKeywordList.add(SmellKeyword.findByValue(smellKeywordTastingNote.getSmellKeyword()).getValue()); + } + } + + return smellKeywordList; + } + + private List toKorSmellKeywordList(List smellKeywordTastingNotes) { List smellKeywordList = new ArrayList<>(); for(SmellKeywordTastingNote smellKeywordTastingNote : smellKeywordTastingNotes){ - System.out.println(smellKeywordTastingNote.getId()); - System.out.println(smellKeywordTastingNote.getSmellKeyword()); - smellKeywordList.add(smellKeywordTastingNote.getSmellKeyword().getName()); + if(smellKeywordTastingNote.getDirectYN().equals("N")){ + smellKeywordList.add(SmellKeyword.findByValue(smellKeywordTastingNote.getSmellKeyword()).getName()); + } } return smellKeywordList; @@ -439,4 +474,12 @@ public void updateTastingNote(TastingNote tastingNote, TastingNoteRequest.Update Boolean isPublic = request.getIsPublic(); if(isPublic != null) tastingNote.setIsPublic(request.getIsPublic()); } + + public SmellKeywordTastingNote toDirectSmellKeyword(String smellKeyword, TastingNote tastingNote) { + return SmellKeywordTastingNote.builder() + .smellKeyword(smellKeyword) + .tastingNote(tastingNote) + .directYN("Y") + .build(); + } } diff --git a/Winey-API/src/main/java/com/example/wineyapi/tastingNote/dto/TastingNoteRequest.java b/Winey-API/src/main/java/com/example/wineyapi/tastingNote/dto/TastingNoteRequest.java index a6a530b..c69b7c2 100644 --- a/Winey-API/src/main/java/com/example/wineyapi/tastingNote/dto/TastingNoteRequest.java +++ b/Winey-API/src/main/java/com/example/wineyapi/tastingNote/dto/TastingNoteRequest.java @@ -90,9 +90,13 @@ public static class CreateTastingNoteDTO { @Schema(name = "isPublic", description = "공개여부", required = false) private Boolean isPublic = Boolean.FALSE; + private List directKeywordList; + + public Boolean getBuyAgain() { return buyAgain; } + } @Getter @@ -172,6 +176,12 @@ public static class UpdateTastingNoteDTO { @Schema(name = "deleteSmellKeywordList 삭제사항 있을 경우 작성해주세요",description = "향 키워드 리스트", required = false) private List deleteSmellKeywordList; + @Schema(name = "directKeywordList 추가사항 있을 경우 작성해주세요",description = "직접 입력한 키워드 리스트", required = false) + private List directKeywordList; + + @Schema(name = "deleteDirectKeywordList 삭제사항 있을 경우 작성해주세요",description = "직접 입력한 키워드 리스트", required = false) + private List deleteDirectKeywordList; + @Schema(name = "deleteImgLists 삭제사항 있을 경우 작성해주세요",description = "테이스팅 노트 이미지 리스트", required = false) private List deleteImgList; diff --git a/Winey-API/src/main/java/com/example/wineyapi/tastingNote/dto/TastingNoteResponse.java b/Winey-API/src/main/java/com/example/wineyapi/tastingNote/dto/TastingNoteResponse.java index dceae36..765c743 100644 --- a/Winey-API/src/main/java/com/example/wineyapi/tastingNote/dto/TastingNoteResponse.java +++ b/Winey-API/src/main/java/com/example/wineyapi/tastingNote/dto/TastingNoteResponse.java @@ -38,6 +38,8 @@ public static class TastingNoteListDTO { private String userNickname; @Schema(description = "노트 생성 날짜") private String noteDate; + @Schema(description = "썸네일") + private String thumbnail; } @NoArgsConstructor @@ -116,6 +118,11 @@ public static class TastingNoteDTO { private List smellKeywordList; + @Schema(description = "한국어 향 리스트") + private List korSmellKeywordList; + + private List directKeywordList; + @Schema(description = "내가 느낀 와인의 맛") private MyWineTaste myWineTaste; diff --git a/Winey-API/src/main/java/com/example/wineyapi/tastingNote/service/TastingNoteServiceImpl.java b/Winey-API/src/main/java/com/example/wineyapi/tastingNote/service/TastingNoteServiceImpl.java index 028ccd4..f3732ca 100644 --- a/Winey-API/src/main/java/com/example/wineyapi/tastingNote/service/TastingNoteServiceImpl.java +++ b/Winey-API/src/main/java/com/example/wineyapi/tastingNote/service/TastingNoteServiceImpl.java @@ -35,6 +35,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import static com.example.wineydomain.tastingNote.exception.GetTastingNoteErrorCode.*; import static com.example.wineydomain.tastingNote.exception.UploadTastingNoteErrorCode.NOT_FOUNT_WINE; @@ -115,14 +116,25 @@ public void updateTastingNote(User user, TastingNoteRequest.UpdateTastingNoteDTO } private void updateTastingNoteSmellKeyword(TastingNoteRequest.UpdateTastingNoteDTO request, TastingNote tastingNote) { - if(request.getDeleteSmellKeywordList() != null) smellKeywordTastingNoteRepository.deleteByTastingNoteAndSmellKeywordIn(tastingNote, request.getDeleteSmellKeywordList()); + if(request.getDeleteSmellKeywordList() != null) smellKeywordTastingNoteRepository.deleteByTastingNoteAndSmellKeywordIn(tastingNote, request.getDeleteSmellKeywordList().stream().map(SmellKeyword::getValue).collect( + Collectors.toList())); if(request.getSmellKeywordList() != null) updateSmellKeyword(request, tastingNote); + if (request.getDirectKeywordList() != null) updateDirectKeyword(request, tastingNote); + if (request.getDeleteDirectKeywordList() != null) smellKeywordTastingNoteRepository.deleteByTastingNoteAndSmellKeywordIn(tastingNote, request.getDeleteDirectKeywordList()); + } + + private void updateDirectKeyword(TastingNoteRequest.UpdateTastingNoteDTO request, TastingNote tastingNote) { + List smellKeywordTastingNoteList = new ArrayList<>(); + for(String smellKeyword : request.getDirectKeywordList()){ + smellKeywordTastingNoteList.add(tastingNoteConvertor.toDirectSmellKeyword(smellKeyword, tastingNote)); + } + smellKeywordTastingNoteRepository.saveAll(smellKeywordTastingNoteList); } private void updateSmellKeyword(TastingNoteRequest.UpdateTastingNoteDTO request, TastingNote tastingNote) { List smellKeywordTastingNoteList = new ArrayList<>(); for(SmellKeyword smellKeyword : request.getSmellKeywordList()){ - smellKeywordTastingNoteList.add(tastingNoteConvertor.SmellKeyword(smellKeyword, tastingNote)); + smellKeywordTastingNoteList.add(tastingNoteConvertor.toSmellKeyword(smellKeyword, tastingNote)); } smellKeywordTastingNoteRepository.saveAll(smellKeywordTastingNoteList); } @@ -162,7 +174,12 @@ public TastingNoteResponse.CreateTastingNoteDTO createTastingNote(User user, Tas if(request.getSmellKeywordList() != null) { for (SmellKeyword smellKeyword : request.getSmellKeywordList()) { - smellKeywordTastingNoteRepository.save(tastingNoteConvertor.SmellKeyword(smellKeyword, tastingNote)); + smellKeywordTastingNoteRepository.save(tastingNoteConvertor.toSmellKeyword(smellKeyword, tastingNote)); + } + } + if (request.getDirectKeywordList() !=null ){ + for (String smellKeyword : request.getDirectKeywordList()) { + smellKeywordTastingNoteRepository.save(tastingNoteConvertor.toDirectSmellKeyword(smellKeyword, tastingNote)); } } diff --git a/Winey-Domain/src/main/java/com/example/wineydomain/tastingNote/entity/SmellKeyword.java b/Winey-Domain/src/main/java/com/example/wineydomain/tastingNote/entity/SmellKeyword.java index d61e2d5..4ff0f16 100644 --- a/Winey-Domain/src/main/java/com/example/wineydomain/tastingNote/entity/SmellKeyword.java +++ b/Winey-Domain/src/main/java/com/example/wineydomain/tastingNote/entity/SmellKeyword.java @@ -1,10 +1,7 @@ package com.example.wineydomain.tastingNote.entity; -import java.util.Arrays; - import com.example.wineydomain.common.model.BaseEntity; import com.fasterxml.jackson.annotation.JsonCreator; - import lombok.*; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; @@ -16,28 +13,60 @@ public enum SmellKeyword { FRUIT("FRUIT","FRUIT","과일향"), BERRY("FRUIT","BERRY", "베리류"), - LEMONANDLIME("FRUIT","LEMONANDLIME","레몬/라임"), - APPLEPEAR("FRUIT","APPLEPEAR","사과/배"), - PEACHPLUM("FRUIT","PEACHPLUM","복숭아/자두"), + LEMON("FRUIT","LEMON","레몬"), + LIME("FRUIT","LIME","라임"), + APPLE("FRUIT","APPLE","사과"), + PEAR("FRUIT","PEAR","배"), + PEACH("FRUIT","PEACH","복숭아"), + PLUM("FRUIT","PLUM","자두"), TROPICALFRUIT("FRUIT","TROPICALFRUIT","열대과일"), FLOWER("NATURAL", "FLOWER","꽃향"), + ACACIA("NATURAL", "ACACIA", "아카시아"), + ROSE("NATURAL", "ROSE", "장미"), + LAVENDER("NATURAL", "LAVENDER", "라벤더"), GRASSWOOD("NATURAL", "GRASSWOOD","풀/나무"), - NATURAL("NATURAL","NATURAL","자연향"), + PINE("NATURAL", "PINE", "솔향"), + PEPPER("NATURAL", "PEPPER", "피망"), + ONION("NATURAL", "ONION", "양파"), + CORN("NATURAL", "CORN", "옥수수"), HERB("NATURAL","HERB","허브향"), + MUSHROOM("NATURAL", "MUSHROOM", "버섯"), + MOSS("NATURAL", "MOSS", "이끼"), OAK("OAK","OAK","오크향"), SPICE("OAK","SPICE","향신료"), + PEPPERSPICE("OAK","PEPPERSPICE","후추"), + CINNAMON("OAK", "CINNAMON", "계피"), NUTS("OAK","NUTS","견과류"), VANILLA("OAK","VANILLA","바닐라"), + CARAMEL("OAK", "CARAMEL", "캐러멜"), CHOCOLATE("OAK","CHOCOLATE","초콜릿"), + TOAST("OAK", "TOAST", "토스트"), + COFFEE("OAK", "COFFEE", "커피"), + COCONUT("OAK", "COCONUT", "코코넛"), + SMOKE("OAK", "SMOKE", "연기"), FLINT("OTHER","FLINT","부싯돌"), BREAD("OTHER", "BREAD","빵"), RUBBER("OTHER","RUBBER","고무"), - EARTHASH("OTHER","EARTHASH","흙/재"), - MEDICINE("OTHER", "MEDICINE","약품"); - - private final String type; + SWEAT("OTHER", "SWEAT", "땀"), + LEATHER("OTHER", "LEATHER", "가죽"), + VINEGAR("OTHER", "VINEGAR", "식초"), + REMOVER("OTHER", "REMOVER", "리무버"), + CIGARETTE("OTHER", "CIGARETTE", "담배"), + HONEY("OTHER", "HONEY", "꿀"), + BUTTER("OTHER", "BUTTER", "버터"), + MEDICINE("OTHER", "MEDICINE","약품"), + EARTHASH("OTHER","EARTHASH","흙/재"); - private final String value; + private final String type; + private final String value; + private final String name; - private final String name; + public static SmellKeyword findByValue(String value) { + for (SmellKeyword keyword : SmellKeyword.values()) { + if (keyword.getValue().equals(value)) { + return keyword; + } + } + return null; + } } diff --git a/Winey-Domain/src/main/java/com/example/wineydomain/tastingNote/entity/SmellKeywordTastingNote.java b/Winey-Domain/src/main/java/com/example/wineydomain/tastingNote/entity/SmellKeywordTastingNote.java index 0101676..089057b 100644 --- a/Winey-Domain/src/main/java/com/example/wineydomain/tastingNote/entity/SmellKeywordTastingNote.java +++ b/Winey-Domain/src/main/java/com/example/wineydomain/tastingNote/entity/SmellKeywordTastingNote.java @@ -15,6 +15,7 @@ @NoArgsConstructor @DynamicUpdate @DynamicInsert +@ToString public class SmellKeywordTastingNote { @Id @@ -22,10 +23,11 @@ public class SmellKeywordTastingNote { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Enumerated(EnumType.STRING) - private SmellKeyword smellKeyword; + private String smellKeyword; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "tastingNoteId", nullable = false) private TastingNote tastingNote; + + private String directYN; } diff --git a/Winey-Domain/src/main/java/com/example/wineydomain/tastingNote/repository/SmellKeywordTastingNoteRepository.java b/Winey-Domain/src/main/java/com/example/wineydomain/tastingNote/repository/SmellKeywordTastingNoteRepository.java index 4b96959..2e67ac4 100644 --- a/Winey-Domain/src/main/java/com/example/wineydomain/tastingNote/repository/SmellKeywordTastingNoteRepository.java +++ b/Winey-Domain/src/main/java/com/example/wineydomain/tastingNote/repository/SmellKeywordTastingNoteRepository.java @@ -9,7 +9,7 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface SmellKeywordTastingNoteRepository extends JpaRepository { - void deleteByTastingNoteAndSmellKeyword(TastingNote tastingNote, SmellKeyword smellKeyword); + void deleteByTastingNoteAndSmellKeyword(TastingNote tastingNote, String smellKeyword); - void deleteByTastingNoteAndSmellKeywordIn(TastingNote tastingNote, List deleteSmellKeywordList); + void deleteByTastingNoteAndSmellKeywordIn(TastingNote tastingNote, List deleteSmellKeywordList); } diff --git a/Winey-Domain/src/main/java/com/example/wineydomain/tastingNote/repository/TastingNoteRepositoryImpl.java b/Winey-Domain/src/main/java/com/example/wineydomain/tastingNote/repository/TastingNoteRepositoryImpl.java index 3c43168..fd4cc17 100644 --- a/Winey-Domain/src/main/java/com/example/wineydomain/tastingNote/repository/TastingNoteRepositoryImpl.java +++ b/Winey-Domain/src/main/java/com/example/wineydomain/tastingNote/repository/TastingNoteRepositoryImpl.java @@ -94,7 +94,7 @@ public Page findTastingNotesByWine(Wine wine, User user, Integer pa .and(qTastingNote.isDeleted.eq(false)) .and(qTastingNote.isPublic.eq(true) .or(qTastingNote.user.eq(user)) - ) + ).and(qTastingNote.user.ne(user)) ) .orderBy(qTastingNote.id.desc());