From 4075b2e62a00727e3e83ec7cdd2754c8213f169c Mon Sep 17 00:00:00 2001 From: Lee junbeom Date: Wed, 10 Jul 2024 23:00:34 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=B6=94=EC=B2=9C=EB=B0=9B=EC=95=98?= =?UTF-8?q?=EB=8D=98=20=EA=BD=83=EC=9D=98=20=EB=AA=A9=EB=A1=9D=EC=9D=84=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=ED=95=A0=20=EB=95=8C=20order=20=EA=B0=92=20?= =?UTF-8?q?=EB=B3=80=ED=95=98=EB=8A=94=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MatchingFlowerController.java | 60 +++++++------- .../matchingFlower/dto/HarmonyRecentDto.java | 32 ++++++++ .../fiurinee/domain/member/entity/Member.java | 5 ++ .../domain/member/service/MemberService.java | 6 ++ .../controller/PreferListController.java | 14 +++- .../controller/RecommendFlowerController.java | 81 +++++++++---------- .../dto/RecommendFlowerDto.java | 31 +++++++ .../entity/RecommendFlower.java | 3 + 8 files changed, 159 insertions(+), 73 deletions(-) diff --git a/src/main/java/com/example/fiurinee/domain/matchingFlower/controller/MatchingFlowerController.java b/src/main/java/com/example/fiurinee/domain/matchingFlower/controller/MatchingFlowerController.java index 6d81f9c..c8a7f9b 100644 --- a/src/main/java/com/example/fiurinee/domain/matchingFlower/controller/MatchingFlowerController.java +++ b/src/main/java/com/example/fiurinee/domain/matchingFlower/controller/MatchingFlowerController.java @@ -75,7 +75,7 @@ public ResponseEntity> preferHarmony(@PathVariable("id") List preferLists = byId.getPreferLists(); for (PreferList preferList : preferLists) { - List harmonyRecentDtos = HarmonyRecentDto.of(preferList.getPreferOrder(), byId); + List harmonyRecentDtos = HarmonyRecentDto.preferOf(preferList.getPreferOrder(), byId); if(harmonyRecentDtos != null) { re.add(harmonyRecentDtos.get(0)); re.add(harmonyRecentDtos.get(1)); @@ -90,45 +90,45 @@ public ResponseEntity> preferHarmony(@PathVariable("id") // public boolean test(){ // MatchingFlower build1 = MatchingFlower.builder() // .flower(flowerService.findByNameAndFlowerLanguage("검은포플라", "용기")) -// .recommendFlower(recommendFlowerService.findById(1L)) +// .recommendFlower(recommendFlowerService.findById(4L)) // .build(); // // matchingFlowerService.save(build1); // // MatchingFlower build2 = MatchingFlower.builder() // .flower(flowerService.findByNameAndFlowerLanguage("군자란", "고귀")) -// .recommendFlower(recommendFlowerService.findById(1L)) +// .recommendFlower(recommendFlowerService.findById(4L)) // .build(); // // matchingFlowerService.save(build2); // -// MatchingFlower build3 = MatchingFlower.builder() -// .flower(flowerService.findByNameAndFlowerLanguage("나도풍란", "인내")) -// .recommendFlower(recommendFlowerService.findById(2L)) -// .build(); -// -// matchingFlowerService.save(build3); -// -// MatchingFlower build4 = MatchingFlower.builder() -// .flower(flowerService.findByNameAndFlowerLanguage("노랑 히야신", "승부")) -// .recommendFlower(recommendFlowerService.findById(2L)) -// .build(); -// -// matchingFlowerService.save(build4); -// -// MatchingFlower build5 = MatchingFlower.builder() -// .flower(flowerService.findByNameAndFlowerLanguage("노랑수선화", "사랑에 답하여")) -// .recommendFlower(recommendFlowerService.findById(3L)) -// .build(); -// -// matchingFlowerService.save(build5); -// -// MatchingFlower build6 = MatchingFlower.builder() -// .flower(flowerService.findByNameAndFlowerLanguage("노랑제비꽃", "수줍은 사랑")) -// .recommendFlower(recommendFlowerService.findById(3L)) -// .build(); -// -// matchingFlowerService.save(build6); +//// MatchingFlower build3 = MatchingFlower.builder() +//// .flower(flowerService.findByNameAndFlowerLanguage("나도풍란", "인내")) +//// .recommendFlower(recommendFlowerService.findById(2L)) +//// .build(); +//// +//// matchingFlowerService.save(build3); +//// +//// MatchingFlower build4 = MatchingFlower.builder() +//// .flower(flowerService.findByNameAndFlowerLanguage("노랑 히야신", "승부")) +//// .recommendFlower(recommendFlowerService.findById(2L)) +//// .build(); +//// +//// matchingFlowerService.save(build4); +//// +//// MatchingFlower build5 = MatchingFlower.builder() +//// .flower(flowerService.findByNameAndFlowerLanguage("노랑수선화", "사랑에 답하여")) +//// .recommendFlower(recommendFlowerService.findById(3L)) +//// .build(); +//// +//// matchingFlowerService.save(build5); +//// +//// MatchingFlower build6 = MatchingFlower.builder() +//// .flower(flowerService.findByNameAndFlowerLanguage("노랑제비꽃", "수줍은 사랑")) +//// .recommendFlower(recommendFlowerService.findById(3L)) +//// .build(); +//// +//// matchingFlowerService.save(build6); // // // diff --git a/src/main/java/com/example/fiurinee/domain/matchingFlower/dto/HarmonyRecentDto.java b/src/main/java/com/example/fiurinee/domain/matchingFlower/dto/HarmonyRecentDto.java index 4177edc..abed4bd 100644 --- a/src/main/java/com/example/fiurinee/domain/matchingFlower/dto/HarmonyRecentDto.java +++ b/src/main/java/com/example/fiurinee/domain/matchingFlower/dto/HarmonyRecentDto.java @@ -60,5 +60,37 @@ public static List of(Long order, Member member){ return dtoList; + } + + public static List preferOf(Long order, Member member){ + List recommendFlowers = member.getRecommendFlowers(); + if(recommendFlowers.size() < order){ + return null; + } + RecommendFlower recommendFlower = recommendFlowers.get(order.intValue()); + + List matchingFlowers = recommendFlower.getMatchingFlowers(); + if(matchingFlowers.size() < 2){ + return null; + } + + List dtoList= new ArrayList<>(); + for(int i = 0 ;i<2;i++){ + HarmonyRecentDto harmonyRecentDto = new HarmonyRecentDto(); + Flower flower = matchingFlowers.get(i).getFlower(); + harmonyRecentDto.harmonyFlower = flower.getName(); + harmonyRecentDto.order = (long) (order.intValue()); + harmonyRecentDto.period = String.format("%02d", flower.getPeriod() / 100); + harmonyRecentDto.explain = flower.getExplain(); + harmonyRecentDto.image = flower.getImage(); + harmonyRecentDto.flower_language = flower.getFlowerLanguage(); + + dtoList.add(harmonyRecentDto); + + } + + return dtoList; + + } } diff --git a/src/main/java/com/example/fiurinee/domain/member/entity/Member.java b/src/main/java/com/example/fiurinee/domain/member/entity/Member.java index 96ef04a..7d8e607 100644 --- a/src/main/java/com/example/fiurinee/domain/member/entity/Member.java +++ b/src/main/java/com/example/fiurinee/domain/member/entity/Member.java @@ -46,6 +46,7 @@ public class Member { private List anniversaries; @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) + @OrderBy("createAt DESC") // createAt 필드를 기준으로 내림차순 정렬 private List recommendFlowers; @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) @@ -83,4 +84,8 @@ public void updatePhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; } + public void updaterecommendFlower(List nnew){ + this.recommendFlowers = nnew; + } + } diff --git a/src/main/java/com/example/fiurinee/domain/member/service/MemberService.java b/src/main/java/com/example/fiurinee/domain/member/service/MemberService.java index 3075550..737eed7 100644 --- a/src/main/java/com/example/fiurinee/domain/member/service/MemberService.java +++ b/src/main/java/com/example/fiurinee/domain/member/service/MemberService.java @@ -3,6 +3,7 @@ import com.example.fiurinee.domain.member.dto.MemberResponseDTO; import com.example.fiurinee.domain.member.entity.Member; import com.example.fiurinee.domain.member.repository.MemberRepository; +import com.example.fiurinee.domain.recommendFlower.entity.RecommendFlower; import com.example.fiurinee.global.exception.CustomException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -51,5 +52,10 @@ public List findAll() { } + @Transactional + public void updateRecommendFlower(Member member, List nnew){ + member.updaterecommendFlower(nnew); + } + } diff --git a/src/main/java/com/example/fiurinee/domain/preferList/controller/PreferListController.java b/src/main/java/com/example/fiurinee/domain/preferList/controller/PreferListController.java index f1a410a..8e99dbb 100644 --- a/src/main/java/com/example/fiurinee/domain/preferList/controller/PreferListController.java +++ b/src/main/java/com/example/fiurinee/domain/preferList/controller/PreferListController.java @@ -12,6 +12,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.List; + @RestController @RequiredArgsConstructor @Slf4j @@ -32,10 +34,14 @@ public Boolean savePrefer(@PathVariable("id") Long id, .build(); preferListService.save(build); - RecommendFlower recommendFlower = byId.getRecommendFlowers().get(Math.toIntExact(order)); + List recommendFlowers = byId.getRecommendFlowers(); + + RecommendFlower recommendFlower = recommendFlowers.get(order.intValue()); recommendFlowerService.editPrefer(recommendFlower,true); + memberService.updateRecommendFlower(byId,recommendFlowers); + return true; } @@ -47,10 +53,14 @@ public Boolean deletePrefer(@PathVariable("id") Long id, preferListService.delete(preferListService.findByMemberAndOrder(byId,order)); - RecommendFlower recommendFlower = byId.getRecommendFlowers().get(Math.toIntExact(order)); + List recommendFlowers = byId.getRecommendFlowers(); + + RecommendFlower recommendFlower = recommendFlowers.get(order.intValue()); recommendFlowerService.editPrefer(recommendFlower,false); + memberService.updateRecommendFlower(byId,recommendFlowers); + return true; } } diff --git a/src/main/java/com/example/fiurinee/domain/recommendFlower/controller/RecommendFlowerController.java b/src/main/java/com/example/fiurinee/domain/recommendFlower/controller/RecommendFlowerController.java index f3b653e..8f1351f 100644 --- a/src/main/java/com/example/fiurinee/domain/recommendFlower/controller/RecommendFlowerController.java +++ b/src/main/java/com/example/fiurinee/domain/recommendFlower/controller/RecommendFlowerController.java @@ -78,7 +78,7 @@ public ResponseEntity> preferFlower(@PathVariable("id") List re = new ArrayList<>(); for (PreferList preferList : preferLists) { - RecommendFlowerDto recommendFlowerDto = RecommendFlowerDto.of(preferList.getPreferOrder(), byId); + RecommendFlowerDto recommendFlowerDto = RecommendFlowerDto.preferOf(preferList.getPreferOrder(), byId); if(recommendFlowerDto == null){ }else{ re.add(recommendFlowerDto); @@ -94,61 +94,60 @@ public ResponseEntity healthyCheck(){ } //----------------------------------------------------------------------------------------------------------------- // @GetMapping("/save/test") -// public RecommendFlower dd(){ +// public void dd(){ // RecommendFlower build = RecommendFlower.builder() -// .flower(flowerService.findByNameAndFlowerLanguage("토마토", "완성된 아름다움")) -// .prefer(true) -// .member(memberService.findById(7L)) +// .flower(flowerService.findByNameAndFlowerLanguage("감국", "그윽한 향기")) +// .prefer(false) +// .member(memberService.findById(2L)) // .build(); // // // recommendFlowerService.saveRecommendFlower(build); // -// RecommendFlower build1 = RecommendFlower.builder() -// .flower(flowerService.findByNameAndFlowerLanguage("나도풍란", "인내")) -// .prefer(true) -// .member(memberService.findById(7L)) -// .build(); -// +//// RecommendFlower build1 = RecommendFlower.builder() +//// .flower(flowerService.findByNameAndFlowerLanguage("나도풍란", "인내")) +//// .prefer(true) +//// .member(memberService.findById(2L)) +//// .build(); +//// +//// +//// recommendFlowerService.saveRecommendFlower(build1); +//// +//// RecommendFlower build2 = RecommendFlower.builder() +//// .flower(flowerService.findByNameAndFlowerLanguage("군자란", "고귀")) +//// .prefer(true) +//// .member(memberService.findById(2L)) +//// .build(); +//// +//// recommendFlowerService.saveRecommendFlower(build2); // -// recommendFlowerService.saveRecommendFlower(build1); -// -// RecommendFlower build2 = RecommendFlower.builder() -// .flower(flowerService.findByNameAndFlowerLanguage("군자란", "고귀")) -// .prefer(true) -// .member(memberService.findById(7L)) -// .build(); -// -// recommendFlowerService.saveRecommendFlower(build2); -// -// return memberService.findById(7L).getRecommendFlowers().get(0); // } -// + // @GetMapping("/test/test") // public void pp(){ // // RecommendComment comment = RecommendComment.builder() -// .content("이것은 추천 멘트1") -// .member(memberService.findById(7L)) -// .prefer(true) +// .content("44444444") +// .member(memberService.findById(2L)) +// .prefer(false) // .build(); // // recommendCommentService.saveRecommendComment(comment); // -// RecommendComment comment1 = RecommendComment.builder() -// .content("이것은 추천 멘트2") -// .member(memberService.findById(7L)) -// .prefer(true) -// .build(); -// -// recommendCommentService.saveRecommendComment(comment1); -// -// RecommendComment comment2 = RecommendComment.builder() -// .content("이것은 추천 멘트3") -// .member(memberService.findById(7L)) -// .prefer(true) -// .build(); -// -// recommendCommentService.saveRecommendComment(comment2); +//// RecommendComment comment1 = RecommendComment.builder() +//// .content("222222222222") +//// .member(memberService.findById(2L)) +//// .prefer(false) +//// .build(); +//// +//// recommendCommentService.saveRecommendComment(comment1); +//// +//// RecommendComment comment2 = RecommendComment.builder() +//// .content("333333333333") +//// .member(memberService.findById(2L)) +//// .prefer(false) +//// .build(); +//// +//// recommendCommentService.saveRecommendComment(comment2); // } } diff --git a/src/main/java/com/example/fiurinee/domain/recommendFlower/dto/RecommendFlowerDto.java b/src/main/java/com/example/fiurinee/domain/recommendFlower/dto/RecommendFlowerDto.java index b310a06..df147ff 100644 --- a/src/main/java/com/example/fiurinee/domain/recommendFlower/dto/RecommendFlowerDto.java +++ b/src/main/java/com/example/fiurinee/domain/recommendFlower/dto/RecommendFlowerDto.java @@ -69,4 +69,35 @@ public static RecommendFlowerDto of(Long order, Member member){ return recommendFlowerDto; } + + public static RecommendFlowerDto preferOf(Long order, Member member){ + List recommendFlowers = member.getRecommendFlowers(); + if(recommendFlowers.size() < order){ + return null; + } + RecommendFlower recommendFlower = recommendFlowers.get(order.intValue()); + Flower flower = recommendFlower.getFlower(); + + RecommendFlowerDto recommendFlowerDto = new RecommendFlowerDto(); + recommendFlowerDto.order = (long) (order.intValue()); + recommendFlowerDto.recommendFlower = flower.getName(); + recommendFlowerDto.period = String.format("%02d", flower.getPeriod() / 100); + recommendFlowerDto.flower_language = flower.getFlowerLanguage(); + recommendFlowerDto.explain = flower.getExplain(); + recommendFlowerDto.image = flower.getImage(); + + List inputMessages = member.getInputMessages(); + InputMessage inputMessage = inputMessages.get(order.intValue()); + + recommendFlowerDto.inputMessage = inputMessage.getContent(); + recommendFlowerDto.create_at = inputMessage.getCreateAt().toString().substring(0,10); + + List recommendComments = member.getRecommendComments(); + RecommendComment recommendComment = recommendComments.get(order.intValue()); + + recommendFlowerDto.recommendMessage = recommendComment.getContent(); + recommendFlowerDto.prefer = recommendFlower.getPrefer(); + + return recommendFlowerDto; + } } diff --git a/src/main/java/com/example/fiurinee/domain/recommendFlower/entity/RecommendFlower.java b/src/main/java/com/example/fiurinee/domain/recommendFlower/entity/RecommendFlower.java index 59b9057..5ac5fad 100644 --- a/src/main/java/com/example/fiurinee/domain/recommendFlower/entity/RecommendFlower.java +++ b/src/main/java/com/example/fiurinee/domain/recommendFlower/entity/RecommendFlower.java @@ -6,6 +6,7 @@ import jakarta.persistence.*; import lombok.*; +import java.sql.Timestamp; import java.util.List; @Entity @@ -28,6 +29,8 @@ public class RecommendFlower { private Boolean prefer; + private Timestamp createAt; + @OneToMany(mappedBy = "recommendFlower", cascade = CascadeType.ALL) private List matchingFlowers;