-
Notifications
You must be signed in to change notification settings - Fork 3
feat : 점수 조회 API #89
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 : 점수 조회 API #89
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package org.ezcode.codetest.application.ranking.dto; | ||
|
|
||
| public record PointResponse ( | ||
| int points | ||
| ){} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package org.ezcode.codetest.application.ranking.service; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.ezcode.codetest.domain.submission.repository.UserProblemResultRepository; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class PointService { | ||
|
|
||
| private final UserProblemResultRepository userProblemResultRepository; | ||
|
|
||
| public int getTotalPoints(Long userId) { | ||
| return userProblemResultRepository.sumPointByUserId(userId).orElse(0); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package org.ezcode.codetest.presentation.ranking; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.ezcode.codetest.application.ranking.dto.PointResponse; | ||
| import org.ezcode.codetest.application.ranking.service.PointService; | ||
| import org.ezcode.codetest.domain.user.model.entity.AuthUser; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/points") | ||
| @RequiredArgsConstructor | ||
| public class PointController { | ||
| private final PointService pointService; | ||
|
|
||
| @GetMapping("/me") | ||
| public ResponseEntity<PointResponse> getMyPoint(@AuthenticationPrincipal AuthUser authUser) { | ||
| Long userId = authUser.getId(); | ||
| int totalPoints = pointService.getTotalPoints(userId); | ||
| return ResponseEntity.ok(new PointResponse(totalPoints)); | ||
| } | ||
|
|
||
| @GetMapping("/{userId}") | ||
| public ResponseEntity<PointResponse> getUserPoint(@PathVariable Long userId) { | ||
| int totalPoint = pointService.getTotalPoints(userId); | ||
| return ResponseEntity.ok(new PointResponse(totalPoint)); | ||
| } | ||
|
Comment on lines
+27
to
+31
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. 🛠️ Refactor suggestion 보안 및 입력 검증 개선 필요 다른 사용자의 점수 조회에 대한 권한 검사가 없고, 다음과 같은 개선사항을 고려해주세요:
@GetMapping("/{userId}")
public ResponseEntity<PointResponse> getUserPoint(@PathVariable Long userId) {
+ if (userId == null || userId <= 0) {
+ return ResponseEntity.badRequest().build();
+ }
int totalPoints = pointService.getTotalPoints(userId);
return ResponseEntity.ok(new PointResponse(totalPoints));
}
🤖 Prompt for AI Agents
Contributor
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. 다른 사람 프로필 들어갔을때 티어 보이게 하려는거라 아무나 조회 가능해 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. @pokerbearkr 아, 프로필 페이지에서 티어 표시용이군요! 그럼 공개 API로 설계된 것이 맞네요. 권한 검사는 필요 없다는 점 이해했습니다. 다만 기본적인 입력 검증은 여전히 권장합니다: @GetMapping("/{userId}")
public ResponseEntity<PointResponse> getUserPoint(@PathVariable Long userId) {
if (userId == null || userId <= 0) {
return ResponseEntity.badRequest().build();
}
int totalPoint = pointService.getTotalPoints(userId);
return ResponseEntity.ok(new PointResponse(totalPoint));
}이렇게 하면 잘못된 userId가 들어왔을 때 더 명확한 에러 응답을 줄 수 있어요. ✏️ Learnings added
|
||
| } | ||
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.
🛠️ Refactor suggestion
입력 검증 및 예외 처리 개선 필요
userId가 null일 경우에 대한 검증이 없습니다. 또한 데이터베이스 호출 시 발생할 수 있는 예외에 대한 명시적인 처리를 고려해보세요.다음과 같이 입력 검증을 추가하는 것을 권장합니다:
public int getTotalPoints(Long userId) { + if (userId == null) { + throw new IllegalArgumentException("사용자 ID는 null일 수 없습니다"); + } return userProblemResultRepository.sumPointByUserId(userId).orElse(0); }📝 Committable suggestion
🤖 Prompt for AI Agents