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..52fffb6 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(); } @@ -367,9 +375,11 @@ private List SmellKeywordList(List smellKeyword 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("Y")){ + smellKeywordList.add(smellKeywordTastingNote.getSmellKeyword()); + }else { + smellKeywordList.add(SmellKeyword.findByValue(smellKeywordTastingNote.getSmellKeyword()).getValue()); + } } return smellKeywordList; @@ -439,4 +449,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/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 6bf3060..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 @@ -60,4 +60,13 @@ public enum SmellKeyword { private final String type; private final String value; 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); }