Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ public Set<ZSetOperations.TypedTuple<String>> getRanking() {
}
}

public Set<ZSetOperations.TypedTuple<String>> getTopRanking(int limit) {
try {
return redisTemplate.opsForZSet().reverseRangeWithScores(RANKING_KEY, 0, limit - 1);
} catch (DataAccessException e) {
log.warn("[Ranking] Redis 조회 실패, 빈 셋 반환", e);
return Collections.emptySet();
}
}

private int getLikeMultiplier() {
if (!doubleEventEnabled) {
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import kr.co.knuserver.presentation.booth.dto.BoothInfoResponseDto;
import kr.co.knuserver.presentation.booth.dto.BoothListResponseDto;
import kr.co.knuserver.presentation.booth.dto.BoothRankingResponseDto;
import kr.co.knuserver.presentation.booth.dto.BoothTop3ResponseDto;
import org.springframework.data.redis.core.ZSetOperations;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
Expand Down Expand Up @@ -96,7 +97,31 @@ public List<BoothRankingResponseDto> getBoothRanking() {
.toList();
}


public List<BoothTop3ResponseDto> getTop3BoothRanking() {
Set<ZSetOperations.TypedTuple<String>> rawRanking = boothLikeService.getTopRanking(10);
if (rawRanking == null || rawRanking.isEmpty()) {
return List.of();
}

BoothRanking boothRanking = new BoothRanking(rawRanking);
if (boothRanking.isEmpty()) {
return List.of();
}

List<Booth> booths = boothRepository.findAllById(boothRanking.boothIds());

return booths.stream()
.map(booth -> new BoothTop3ResponseDto(
booth.getId(),
booth.getName(),
boothRanking.getLikeCount(booth.getId())
))
.sorted(Comparator.comparingLong(BoothTop3ResponseDto::likeCount).reversed()
.thenComparingLong(BoothTop3ResponseDto::boothId))
.limit(3)
.toList();
}

public CursorPaginationResponse<BoothListResponseDto> searchBoothsByKeyword2(String keyword, Long lastId, int size) {
Pageable pageable = PageRequest.of(0, size + 1);
List<Booth> booths;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import kr.co.knuserver.presentation.booth.dto.BoothInfoResponseDto;
import kr.co.knuserver.presentation.booth.dto.BoothListResponseDto;
import kr.co.knuserver.presentation.booth.dto.BoothRankingResponseDto;
import kr.co.knuserver.presentation.booth.dto.BoothTop3ResponseDto;
import kr.co.knuserver.presentation.booth.dto.BoothUpdateRequestDto;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -80,9 +81,17 @@ public ResponseEntity<ApiResponse<CursorPaginationResponse<BoothListResponseDto>
.body(ApiResponse.success(result));
}

@Override
@GetMapping("/ranking")
public ResponseEntity<ApiResponse<List<BoothRankingResponseDto>>> getBoothRanking() {
List<BoothRankingResponseDto> result = boothQueryService.getBoothRanking();
return ResponseEntity.ok(ApiResponse.success(result));
}

@Override
@GetMapping("/ranking/top3")
public ResponseEntity<ApiResponse<List<BoothTop3ResponseDto>>> getTop3BoothRanking() {
List<BoothTop3ResponseDto> result = boothQueryService.getTop3BoothRanking();
return ResponseEntity.ok(ApiResponse.success(result));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import kr.co.knuserver.presentation.booth.dto.BoothCountResponseDto;
import kr.co.knuserver.presentation.booth.dto.BoothInfoResponseDto;
import kr.co.knuserver.presentation.booth.dto.BoothListResponseDto;
import kr.co.knuserver.presentation.booth.dto.BoothRankingResponseDto;
import kr.co.knuserver.presentation.booth.dto.BoothTop3ResponseDto;
import kr.co.knuserver.presentation.booth.dto.BoothUpdateRequestDto;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -60,4 +62,16 @@ ResponseEntity<kr.co.knuserver.global.exception.ApiResponse<CursorPaginationResp
@Parameter(description = "페이지 크기 (기본값: 10)")
@RequestParam(name = "size", required = false, defaultValue = "10") int size
);

@Operation(summary = "가두모집 부스 좋아요 랭킹 전체 조회", description = "좋아요 수 기준 전체 부스 랭킹을 반환합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "랭킹 조회 성공")
})
ResponseEntity<kr.co.knuserver.global.exception.ApiResponse<List<BoothRankingResponseDto>>> getBoothRanking();

@Operation(summary = "가두모집 부스 좋아요 TOP 3 조회", description = "좋아요 수 기준 상위 3개 부스를 반환합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "TOP 3 랭킹 조회 성공")
})
ResponseEntity<kr.co.knuserver.global.exception.ApiResponse<List<BoothTop3ResponseDto>>> getTop3BoothRanking();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package kr.co.knuserver.presentation.booth.dto;

public record BoothTop3ResponseDto(
Long boothId,
String boothName,
long likeCount
) {}
Loading