diff --git a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java index 4bada09..f50bede 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/repository/WineRepositoryImpl.java @@ -120,7 +120,7 @@ public List findRecommendWines(Member member) { .otherwise(0.0)) .desc() ) - .limit(10) + .limit(20) .fetch(); } diff --git a/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java b/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java index 4232000..126da86 100644 --- a/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java +++ b/src/main/java/com/drinkeg/drinkeg/wine/service/WineServiceImpl.java @@ -66,7 +66,14 @@ public HomeResponseDTO getHomeResponse(PrincipalDetail principalDetail) { Member member = memberRepository.findByUsername(principalDetail.getUsername()).orElseThrow( () -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND)); + // max 20개의 추천 와인을 찾는다. List recommendWines = wineRepository.findRecommendWines(member); + + // 만약 추천 와인의 수가 5개를 넘어간다면, 랜덤으로 5개의 와인만 반환한다. + if (recommendWines.size() > 5) { + Collections.shuffle(recommendWines); + recommendWines = recommendWines.subList(0, 5); + } return HomeResponseDTO.create(member, recommendWines); }