Skip to content
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

[Feature] #103 - 이전 모의고사 결과 조회 API 구현 #104

Merged
merged 1 commit into from
Mar 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -42,4 +42,11 @@ public ApiResponse<MockTestResultResponse> getMockTestResult(@PathVariable Long
MockTestResultResponse response = mockTestService.getMockTestResult(mockTestId);
return ApiResponse.onSuccess(response);
}

@GetMapping("/previous/result")
@Operation(summary = "이전 모의고사 결과 조회", description = "가장 최근에 완료한 이전 모의고사 결과를 조회합니다.")
public ApiResponse<MockTestResultResponse> getPreviousMockTestResult(Authentication authentication) {
MockTestResultResponse response = mockTestService.getPreviousMockTestResult(authentication.getName());
return ApiResponse.onSuccess(response);
}
}
Original file line number Diff line number Diff line change
@@ -26,4 +26,6 @@ public interface MockTestRepository extends JpaRepository<MockTest, Long> {
Optional<MockTest> findTopByUser_UserIdAndMockTestIdLessThanOrderByMockTestIdDesc(Long userId, Long mockTestId);

List<MockTest> findByUser_UserIdAndMockTestIdLessThan(Long userId, Long mockTestId);

Optional<MockTest> findTopByUser_UserIdAndIsCompletedTrueOrderByCreatedDateDesc(Long userId);
}
Original file line number Diff line number Diff line change
@@ -9,4 +9,5 @@ public interface MockTestService {
CreateMockTestResponse startMockTest(String userId);
SubmitMockTestResponse submitMockTest(Long mockTestId, SubmitMockTestRequest request);
MockTestResultResponse getMockTestResult(Long mockTestId);
MockTestResultResponse getPreviousMockTestResult(String userId);
}
15 changes: 15 additions & 0 deletions src/main/java/dgu/sw/domain/quiz/service/MockTestServiceImpl.java
Original file line number Diff line number Diff line change
@@ -197,4 +197,19 @@ public MockTestResultResponse getMockTestResult(Long mockTestId) {
.questionResults(questionResults)
.build();
}

@Override
public MockTestResultResponse getPreviousMockTestResult(String userId) {
Long uid = Long.valueOf(userId);

// 유저가 푼 가장 최근(제일 마지막) 이전 모의고사
Optional<MockTest> previousMockTestOpt = mockTestRepository
.findTopByUser_UserIdAndIsCompletedTrueOrderByCreatedDateDesc(uid);

MockTest mockTest = previousMockTestOpt
.orElseThrow(() -> new QuizException(ErrorStatus.MOCK_TEST_NOT_FOUND));

return getMockTestResult(mockTest.getMockTestId());
}

}
3 changes: 2 additions & 1 deletion src/main/java/dgu/sw/global/status/ErrorStatus.java
Original file line number Diff line number Diff line change
@@ -57,7 +57,8 @@ public enum ErrorStatus implements BaseErrorCode {
OAUTH_ACCESS_DENIED(HttpStatus.UNAUTHORIZED, "OAUTH4004", "OAuth 인증에 실패했습니다."),

// 모의고사 관련 에러
MOCK_TEST_NOT_COMPLETED(HttpStatus.BAD_REQUEST, "MOCK4001", "아직 제출되지 않은 모의고사입니다.");
MOCK_TEST_NOT_COMPLETED(HttpStatus.BAD_REQUEST, "MOCK4001", "아직 제출되지 않은 모의고사입니다."),
MOCK_TEST_NOT_FOUND(HttpStatus.NOT_FOUND, "MOCK4002", "해당 모의고사를 찾을 수 없습니다.");

private final HttpStatus httpStatus;
private final String code;