-
Notifications
You must be signed in to change notification settings - Fork 3
feat : 내 랭킹 조회, 타겟 랭킹 조회 구현 #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Walkthrough랭킹 시스템에 사용자 중심 랭킹 조회 기능이 추가되었습니다. 새로운 DTO와 서비스 메서드가 도입되어, 지정한 사용자 또는 현재 로그인한 사용자의 랭킹 주변 정보를 조회할 수 있는 API 엔드포인트가 구현되었습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Controller
participant FacadeService
participant RedisRankingService
participant DB
Client->>Controller: GET /me/around?period=...
Controller->>FacadeService: getRanking(period, userId)
FacadeService->>RedisRankingService: getRanking(redisKey, userId)
RedisRankingService->>RedisRankingService: 사용자 랭크 조회 (reverseRank)
RedisRankingService->>RedisRankingService: 주변 랭킹 조회 (reverseRangeWithScores)
RedisRankingService->>DB: 사용자 닉네임 일괄 조회
RedisRankingService-->>FacadeService: TargetRankingResponse 리스트 반환
FacadeService-->>Controller: TargetRankingResponse 리스트 반환
Controller-->>Client: TargetRankingResponse 리스트 반환
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (10)
src/main/java/org/ezcode/codetest/application/ranking/dto/TargetRankingResponse.java (2)
6-6: 필드명 개선 권장
ranks보다는rank가 더 적절한 필드명입니다. 단수형이 일반적이고 다른 코드에서도 rank로 사용되고 있습니다.- int ranks, + int rank,
8-8: 코드 일관성을 위한 주석 언어 통일 고려한국어 주석이 프로젝트의 다른 부분과 일관성을 유지하는지 확인해보세요. 프로젝트에서 영어 주석을 주로 사용한다면 통일하는 것이 좋겠습니다.
src/main/java/org/ezcode/codetest/application/ranking/service/RankingFacadeService.java (2)
40-40: 에러 메시지 언어 일관성 검토한국어 에러 메시지가 프로젝트의 다른 예외 메시지들과 언어적으로 일관성을 유지하는지 확인해보세요. 국제화를 고려한다면 영어 메시지 사용을 권장합니다.
34-44: 입력 검증 강화 권장
userId가 null이거나 음수일 경우에 대한 검증을 추가하는 것이 좋겠습니다.public List<TargetRankingResponse> getRanking(String period, Long userId) { + if (userId == null || userId <= 0) { + throw new IllegalArgumentException("유효하지 않은 사용자 ID입니다."); + } LocalDate baseMonday = LocalDate.now().with(DayOfWeek.MONDAY);src/main/java/org/ezcode/codetest/infrastructure/ranking/redis/RedisRankingService.java (2)
91-91: 성능 최적화 권장스트림 내부에서 매번
reverseRank를 호출하는 것은 비효율적입니다. 이미start,end인덱스를 알고 있으므로 계산으로 순위를 구할 수 있습니다.return range.stream().map(tuple -> { Long id = Long.parseLong(tuple.getValue()); - Long rank = redisTemplate.opsForZSet().reverseRank(key, tuple.getValue()); + int currentIndex = (int) (start + Arrays.asList(range.toArray()).indexOf(tuple)); + int calculatedRank = currentIndex + 1; return new TargetRankingResponse( id, nicknameMap.getOrDefault(id, "알 수 없음"), - rank != null ? rank.intValue() + 1 : -1, + calculatedRank, tuple.getScore() != null ? tuple.getScore().intValue() : 0, id.equals(userId) ); }).sorted(Comparator.comparingInt(TargetRankingResponse::ranks)).toList();
82-87: 코드 간소화 권장사용자 ID와 닉네임 매핑 로직을 더 간단하게 표현할 수 있습니다.
Map<Long, String> nicknameMap = userJpaRepository.findAllById( - ids.stream().map(Long::parseLong).toList() -).stream().collect(Collectors.toMap( - u -> u.getId(), - u -> u.getNickname() -)); + ids.stream().map(Long::parseLong).toList() +).stream().collect(Collectors.toMap( + user -> user.getId(), + user -> user.getNickname() +));src/main/java/org/ezcode/codetest/presentation/ranking/RankingController.java (4)
45-46: 주석 언어 일관성 검토한국어 주석이 프로젝트의 다른 컨트롤러 주석들과 언어적으로 일관성을 유지하는지 확인해보세요.
48-53: 입력 매개변수 검증 추가 권장
period매개변수에 대한 검증을 컨트롤러 레벨에서 추가하는 것이 좋겠습니다.@RequestParam에 required=true를 명시하거나 validation 어노테이션을 사용해보세요.@GetMapping("/me/around") public List<TargetRankingResponse> getMyRanking( - @RequestParam("period") String period, + @RequestParam(value = "period", required = true) String period, @AuthenticationPrincipal AuthUser authUser ) {
55-61: 경로 변수 검증 강화 권장
userId경로 변수가 유효한 양수인지 검증하는 로직을 추가하는 것이 좋겠습니다.@GetMapping("/{userId}/around") public List<TargetRankingResponse> getTargetAroundRanking( - @RequestParam("period") String period, - @PathVariable Long userId + @RequestParam(value = "period", required = true) String period, + @PathVariable @Min(1) Long userId ) {
@Min어노테이션을 사용하려면@Valid어노테이션도 메서드에 추가해야 합니다.
47-61: API 응답 통일성 고려다른 랭킹 엔드포인트들과 달리 이 두 엔드포인트는
ResponseEntity를 사용하지 않습니다. 일관성을 위해ResponseEntity<List<TargetRankingResponse>>로 반환하는 것을 고려해보세요.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/main/java/org/ezcode/codetest/application/ranking/dto/TargetRankingResponse.java(1 hunks)src/main/java/org/ezcode/codetest/application/ranking/service/RankingFacadeService.java(2 hunks)src/main/java/org/ezcode/codetest/infrastructure/ranking/redis/RedisRankingService.java(2 hunks)src/main/java/org/ezcode/codetest/presentation/ranking/RankingController.java(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build
작업 내용
변경 사항
트러블 슈팅
해결해야 할 문제
참고 사항
코드 리뷰 전 확인 체크리스트
type :)Summary by CodeRabbit