Skip to content

Commit

Permalink
refactor : 향 키워드 직접입력 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
imenuuu committed Nov 6, 2024
1 parent 0cb11cb commit 8d97b12
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,15 @@ public TastingNoteResponse.TasteAnalysisDTO TasteAnalysis(List<TastingNote> 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<Map.Entry<String, Integer>> sortCountry = new ArrayList<>(wineCountByCountry.entrySet());
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -367,9 +375,11 @@ private List<String> SmellKeywordList(List<SmellKeywordTastingNote> smellKeyword
List<String> 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;
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ public static class CreateTastingNoteDTO {
@Schema(name = "isPublic", description = "공개여부", required = false)
private Boolean isPublic = Boolean.FALSE;

private List<String> directKeywordList;


public Boolean getBuyAgain() {
return buyAgain;
}

}

@Getter
Expand Down Expand Up @@ -172,6 +176,12 @@ public static class UpdateTastingNoteDTO {
@Schema(name = "deleteSmellKeywordList 삭제사항 있을 경우 작성해주세요",description = "향 키워드 리스트", required = false)
private List<SmellKeyword> deleteSmellKeywordList;

@Schema(name = "directKeywordList 추가사항 있을 경우 작성해주세요",description = "직접 입력한 키워드 리스트", required = false)
private List<String> directKeywordList;

@Schema(name = "deleteDirectKeywordList 삭제사항 있을 경우 작성해주세요",description = "직접 입력한 키워드 리스트", required = false)
private List<String> deleteDirectKeywordList;

@Schema(name = "deleteImgLists 삭제사항 있을 경우 작성해주세요",description = "테이스팅 노트 이미지 리스트", required = false)
private List<Long> deleteImgList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<SmellKeywordTastingNote> 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<SmellKeywordTastingNote> smellKeywordTastingNoteList = new ArrayList<>();
for(SmellKeyword smellKeyword : request.getSmellKeywordList()){
smellKeywordTastingNoteList.add(tastingNoteConvertor.SmellKeyword(smellKeyword, tastingNote));
smellKeywordTastingNoteList.add(tastingNoteConvertor.toSmellKeyword(smellKeyword, tastingNote));
}
smellKeywordTastingNoteRepository.saveAll(smellKeywordTastingNoteList);
}
Expand Down Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
@NoArgsConstructor
@DynamicUpdate
@DynamicInsert
@ToString
public class SmellKeywordTastingNote {

@Id
@Column(name = "id")
@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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface SmellKeywordTastingNoteRepository extends JpaRepository<SmellKeywordTastingNote, Long> {
void deleteByTastingNoteAndSmellKeyword(TastingNote tastingNote, SmellKeyword smellKeyword);
void deleteByTastingNoteAndSmellKeyword(TastingNote tastingNote, String smellKeyword);

void deleteByTastingNoteAndSmellKeywordIn(TastingNote tastingNote, List<SmellKeyword> deleteSmellKeywordList);
void deleteByTastingNoteAndSmellKeywordIn(TastingNote tastingNote, List<String> deleteSmellKeywordList);
}

0 comments on commit 8d97b12

Please sign in to comment.