Skip to content

Commit

Permalink
fix: 추천받았던 꽃의 목록을 반환할 때 order 값 변하는 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ss7622 committed Jul 10, 2024
1 parent 9c62ab4 commit 4075b2e
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public ResponseEntity<List<HarmonyRecentDto>> preferHarmony(@PathVariable("id")
List<PreferList> preferLists = byId.getPreferLists();

for (PreferList preferList : preferLists) {
List<HarmonyRecentDto> harmonyRecentDtos = HarmonyRecentDto.of(preferList.getPreferOrder(), byId);
List<HarmonyRecentDto> harmonyRecentDtos = HarmonyRecentDto.preferOf(preferList.getPreferOrder(), byId);
if(harmonyRecentDtos != null) {
re.add(harmonyRecentDtos.get(0));
re.add(harmonyRecentDtos.get(1));
Expand All @@ -90,45 +90,45 @@ public ResponseEntity<List<HarmonyRecentDto>> 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);
//
//
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,37 @@ public static List<HarmonyRecentDto> of(Long order, Member member){
return dtoList;


}

public static List<HarmonyRecentDto> preferOf(Long order, Member member){
List<RecommendFlower> recommendFlowers = member.getRecommendFlowers();
if(recommendFlowers.size() < order){
return null;
}
RecommendFlower recommendFlower = recommendFlowers.get(order.intValue());

List<MatchingFlower> matchingFlowers = recommendFlower.getMatchingFlowers();
if(matchingFlowers.size() < 2){
return null;
}

List<HarmonyRecentDto> 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;


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class Member {
private List<Anniversary> anniversaries;

@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
@OrderBy("createAt DESC") // createAt 필드를 기준으로 내림차순 정렬
private List<RecommendFlower> recommendFlowers;

@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
Expand Down Expand Up @@ -83,4 +84,8 @@ public void updatePhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

public void updaterecommendFlower(List<RecommendFlower> nnew){
this.recommendFlowers = nnew;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,5 +52,10 @@ public List<Member> findAll() {

}

@Transactional
public void updateRecommendFlower(Member member, List<RecommendFlower> nnew){
member.updaterecommendFlower(nnew);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Slf4j
Expand All @@ -32,10 +34,14 @@ public Boolean savePrefer(@PathVariable("id") Long id,
.build();
preferListService.save(build);

RecommendFlower recommendFlower = byId.getRecommendFlowers().get(Math.toIntExact(order));
List<RecommendFlower> recommendFlowers = byId.getRecommendFlowers();

RecommendFlower recommendFlower = recommendFlowers.get(order.intValue());

recommendFlowerService.editPrefer(recommendFlower,true);

memberService.updateRecommendFlower(byId,recommendFlowers);

return true;

}
Expand All @@ -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<RecommendFlower> recommendFlowers = byId.getRecommendFlowers();

RecommendFlower recommendFlower = recommendFlowers.get(order.intValue());

recommendFlowerService.editPrefer(recommendFlower,false);

memberService.updateRecommendFlower(byId,recommendFlowers);

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public ResponseEntity<List<RecommendFlowerDto>> preferFlower(@PathVariable("id")
List<RecommendFlowerDto> 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);
Expand All @@ -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);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,35 @@ public static RecommendFlowerDto of(Long order, Member member){

return recommendFlowerDto;
}

public static RecommendFlowerDto preferOf(Long order, Member member){
List<RecommendFlower> 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<InputMessage> inputMessages = member.getInputMessages();
InputMessage inputMessage = inputMessages.get(order.intValue());

recommendFlowerDto.inputMessage = inputMessage.getContent();
recommendFlowerDto.create_at = inputMessage.getCreateAt().toString().substring(0,10);

List<RecommendComment> recommendComments = member.getRecommendComments();
RecommendComment recommendComment = recommendComments.get(order.intValue());

recommendFlowerDto.recommendMessage = recommendComment.getContent();
recommendFlowerDto.prefer = recommendFlower.getPrefer();

return recommendFlowerDto;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.persistence.*;
import lombok.*;

import java.sql.Timestamp;
import java.util.List;

@Entity
Expand All @@ -28,6 +29,8 @@ public class RecommendFlower {

private Boolean prefer;

private Timestamp createAt;

@OneToMany(mappedBy = "recommendFlower", cascade = CascadeType.ALL)
private List<MatchingFlower> matchingFlowers;

Expand Down

0 comments on commit 4075b2e

Please sign in to comment.