-
Notifications
You must be signed in to change notification settings - Fork 3
[feat] 마이페이지 조회 기능 #119
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
[feat] 마이페이지 조회 기능 #119
Changes from 4 commits
85f3934
449f3b7
e81b2ce
fd7fe2b
d1d2df3
45972ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| import io.f1.backend.domain.stat.dto.StatPageResponse; | ||
| import io.f1.backend.domain.stat.dto.StatResponse; | ||
| import io.f1.backend.domain.stat.dto.StatWithNicknameAndUserId; | ||
| import io.f1.backend.domain.user.dto.MyPageInfo; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
|
|
@@ -27,6 +28,7 @@ | |
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class StatRedisRepository { | ||
|
|
||
| private static final String STAT_RANK = "stat:rank"; | ||
| private static final String STAT_USER = "stat:user:%d"; | ||
| private static final String STAT_NICKNAME = "stat:%s"; | ||
|
|
@@ -149,4 +151,23 @@ private static String getStatNickname(String nickname) { | |
| private long getUserIdFromNickname(String nickname) { | ||
| return ((Number) requireNonNull(valueOps.get(getStatNickname(nickname)))).longValue(); | ||
| } | ||
|
|
||
| public MyPageInfo getStatByUserId(long userId) { | ||
| String statUserKey = getStatUserKey(userId); | ||
|
|
||
| Long rank = zSetOps.reverseRank(STAT_RANK, userId); | ||
| Double score = zSetOps.score(STAT_RANK, userId); | ||
| Map<Object, Object> statMap = hashOps.entries(statUserKey); | ||
|
|
||
| if (rank == null || score == null || statMap.isEmpty()) { | ||
| throw new IllegalStateException("User not found in Redis: " + userId); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 왜 여기는 customException을 쓰지 않으신건지 궁금합니다!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 구조가 Redis 조회 -> 없으면 -> MySQL 조회로 넘어가게 되는데, 위 코드에서 던진 예외를 아래의 코드로 처리를 합니다. 그래서 해당 예외는 프론트로 내려가지 않기 때문에 CustomException 처리를 하지 않았습니다 ! try {
return redisRepository.getStatByUserId(userId);
} catch (Exception e) {
log.error("Redis miss, fallback to MySQL for userId={}", userId, e);
} |
||
| } | ||
|
|
||
| return new MyPageInfo( | ||
| (String) statMap.get("nickname"), | ||
| rank + 1, | ||
| (long) statMap.get("totalGames"), | ||
| (long) statMap.get("winningGames"), | ||
| score.longValue()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| package io.f1.backend.domain.user.dto; | ||
|
|
||
| public record MyPageInfo(String nickname, long rank, long score, long totalGames, long winningGames) {} |
Uh oh!
There was an error while loading. Please reload this page.