Skip to content

Commit

Permalink
feat : kuddy top5를 추출 쿼리 조건 추가
Browse files Browse the repository at this point in the history
쿼리 실행 시점 7일 이내의 리뷰 점수를 반영
Related to: #134
  • Loading branch information
june0216 committed Oct 6, 2023
1 parent 110f43e commit 9702305
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -39,7 +40,6 @@ public class Top5KuddyService {
private final ReviewRepository reviewRepository;
private final JPAQueryFactory queryFactory;
private final CacheManager contentCacheManager;

public List<Profile> findTopKuddies() {
// 점수 계산
NumberExpression<Integer> reviewScore = new CaseBuilder()
Expand All @@ -55,12 +55,17 @@ public List<Profile> findTopKuddies() {
// RoleType이 "KUDDY"인 멤버만
BooleanExpression isKuddyRole = member.roleType.eq(RoleType.KUDDY);

// 오늘 기준 7일 전 날짜
LocalDate sevenDaysAgo = LocalDate.now().minusDays(7);

BooleanExpression isWithinLastSevenDays = review.createdDate.after(sevenDaysAgo.atStartOfDay());

JPAQuery<Tuple> query = queryFactory
.select(review.meetup.kuddy, reviewScore.sum().as("totalScore"))
.from(review)
.leftJoin(review.meetup.kuddy, member)
.leftJoin(member.profile, profile)
.where(isHighLevelKuddy.and(isKuddyRole)) // 조건: 높은 레벨의 Kuddy만 + RoleType이 "KUDDY"인 경우
.where(isHighLevelKuddy.and(isKuddyRole).and(isWithinLastSevenDays)) // 조건: 높은 레벨의 Kuddy만 + RoleType이 "KUDDY"인 경우 + 최근 7일 이내의 리뷰
.groupBy(member.id)
.orderBy(
// 점수 높은 순, 그리고 최신 리뷰 날짜 순
Expand All @@ -76,6 +81,7 @@ public List<Profile> findTopKuddies() {
.collect(Collectors.toList());
}


@Cacheable(value="topKuddies",cacheManager = "contentCacheManager")
public Top5KuddyListResDto getTop5Kuddy(){
List<Profile> profiles = findTopKuddies(); // 캐시에 데이터가 없으면 실행
Expand Down

0 comments on commit 9702305

Please sign in to comment.