Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api-Release-v0.0.4-2 #115

Merged
merged 7 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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();
}

Expand All @@ -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))
Expand All @@ -329,6 +340,18 @@ public TastingNoteResponse.TastingNoteDTO toTastingNote(TastingNote tastingNote,
.build();
}

private List<String> toDirectKeywordList(List<SmellKeywordTastingNote> smellKeywordTastingNotes) {
List<String> directKeywordList = new ArrayList<>();

for(SmellKeywordTastingNote smellKeywordTastingNote : smellKeywordTastingNotes){
if(smellKeywordTastingNote.getDirectYN().equals("Y")){
directKeywordList.add(smellKeywordTastingNote.getSmellKeyword());
}
}

return directKeywordList;
}

private List<TastingNoteResponse.TastingNoteImage> toTastingNoteImageRes(List<TastingNoteImage> tastingNoteImages) {
List<TastingNoteResponse.TastingNoteImage> tastingNoteImageList = new ArrayList<>();

Expand Down Expand Up @@ -363,13 +386,25 @@ private TastingNoteResponse.MyWineTaste MyWineTaste(TastingNote tastingNote) {
.build();
}

private List<String> SmellKeywordList(List<SmellKeywordTastingNote> smellKeywordTastingNotes) {
private List<String> toSmellKeywordList(List<SmellKeywordTastingNote> smellKeywordTastingNotes) {
List<String> smellKeywordList = new ArrayList<>();

for(SmellKeywordTastingNote smellKeywordTastingNote : smellKeywordTastingNotes){
if(smellKeywordTastingNote.getDirectYN().equals("N")){
smellKeywordList.add(SmellKeyword.findByValue(smellKeywordTastingNote.getSmellKeyword()).getValue());
}
}

return smellKeywordList;
}

private List<String> toKorSmellKeywordList(List<SmellKeywordTastingNote> smellKeywordTastingNotes) {
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("N")){
smellKeywordList.add(SmellKeyword.findByValue(smellKeywordTastingNote.getSmellKeyword()).getName());
}
}

return smellKeywordList;
Expand Down Expand Up @@ -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();
}
}
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 @@ -38,6 +38,8 @@ public static class TastingNoteListDTO {
private String userNickname;
@Schema(description = "노트 생성 날짜")
private String noteDate;
@Schema(description = "썸네일")
private String thumbnail;
}

@NoArgsConstructor
Expand Down Expand Up @@ -116,6 +118,11 @@ public static class TastingNoteDTO {

private List<String> smellKeywordList;

@Schema(description = "한국어 향 리스트")
private List<String> korSmellKeywordList;

private List<String> directKeywordList;

@Schema(description = "내가 느낀 와인의 맛")
private MyWineTaste myWineTaste;

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
@@ -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;
Expand All @@ -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;
}
}
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Page<TastingNote> 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());

Expand Down
Loading