From fcc58decd294a6d6ba9416ea632ac4b7c4dd04a4 Mon Sep 17 00:00:00 2001 From: haeun1107 Date: Fri, 21 Mar 2025 13:53:08 +0900 Subject: [PATCH] =?UTF-8?q?[Feature]=20#95=20-=20=EC=96=B4=EC=A0=9C=20?= =?UTF-8?q?=ED=91=BC=20=ED=80=B4=EC=A6=88=20=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../quiz/controller/QuizController.java | 8 ++++++ .../domain/quiz/converter/QuizConverter.java | 14 ++++++++++ .../java/dgu/sw/domain/quiz/dto/QuizDTO.java | 9 +++++++ .../quiz/repository/UserQuizRepository.java | 3 +++ .../sw/domain/quiz/service/QuizService.java | 2 ++ .../domain/quiz/service/QuizServiceImpl.java | 27 ++++++++++++++++--- 6 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/main/java/dgu/sw/domain/quiz/controller/QuizController.java b/src/main/java/dgu/sw/domain/quiz/controller/QuizController.java index bf7b1f4..c11d521 100644 --- a/src/main/java/dgu/sw/domain/quiz/controller/QuizController.java +++ b/src/main/java/dgu/sw/domain/quiz/controller/QuizController.java @@ -1,5 +1,6 @@ package dgu.sw.domain.quiz.controller; +import dgu.sw.domain.quiz.dto.QuizDTO.QuizResponse.YesterdayQuizResponse; import dgu.sw.domain.quiz.dto.QuizDTO.QuizResponse.QuizMainPageResponse; import dgu.sw.domain.quiz.dto.QuizDTO.QuizResponse.QuizSearchResponse; import dgu.sw.domain.quiz.dto.QuizDTO.QuizResponse.QuizReviewResponse; @@ -93,4 +94,11 @@ public ApiResponse getQuizMainInfo(Authentication authenti QuizMainPageResponse response = quizService.getQuizMainPageData(authentication.getName()); return ApiResponse.onSuccess(response); } + + @GetMapping("/yesterday") + @Operation(summary = "어제 푼 퀴즈 조회", description = "어제 푼 퀴즈 목록을 반환합니다.") + public ApiResponse> getYesterdayQuizzes(Authentication authentication) { + List response = quizService.getYesterdaySolvedQuizzes(authentication.getName()); + return ApiResponse.onSuccess(response); + } } \ No newline at end of file diff --git a/src/main/java/dgu/sw/domain/quiz/converter/QuizConverter.java b/src/main/java/dgu/sw/domain/quiz/converter/QuizConverter.java index 970527d..5b6f949 100644 --- a/src/main/java/dgu/sw/domain/quiz/converter/QuizConverter.java +++ b/src/main/java/dgu/sw/domain/quiz/converter/QuizConverter.java @@ -1,5 +1,6 @@ package dgu.sw.domain.quiz.converter; +import dgu.sw.domain.quiz.dto.QuizDTO.QuizResponse.YesterdayQuizResponse; import dgu.sw.domain.quiz.dto.QuizDTO.QuizResponse.QuizSearchResponse; import dgu.sw.domain.quiz.dto.QuizDTO.QuizResponse.QuizListResponse; import dgu.sw.domain.quiz.dto.QuizDTO.QuizResponse.QuizDetailResponse; @@ -22,6 +23,7 @@ public static UserQuiz toUserQuiz(User user, Quiz quiz, boolean isCorrect) { .isLocked(false) .isReviewed(false) .solvedDate(LocalDate.now()) + .retriedToday(false) .build(); } @@ -94,4 +96,16 @@ public static QuizSearchResponse toQuizSearchResponse(Quiz quiz, boolean isLocke .build(); } + public static YesterdayQuizResponse toYesterdayQuizResponse( + Quiz quiz, + boolean isInReviewList, + boolean retriedToday + ) { + return YesterdayQuizResponse.builder() + .quizId(quiz.getQuizId()) + .question(quiz.getQuestion()) + .isInReviewList(isInReviewList) + .retriedToday(retriedToday) + .build(); + } } \ No newline at end of file diff --git a/src/main/java/dgu/sw/domain/quiz/dto/QuizDTO.java b/src/main/java/dgu/sw/domain/quiz/dto/QuizDTO.java index 3a71ac0..83c136f 100644 --- a/src/main/java/dgu/sw/domain/quiz/dto/QuizDTO.java +++ b/src/main/java/dgu/sw/domain/quiz/dto/QuizDTO.java @@ -87,5 +87,14 @@ public static class QuizMainPageResponse { private Double topPercentile; private List top5WrongQuizzes; } + + @Getter + @Builder + public static class YesterdayQuizResponse { + private Long quizId; + private String question; + private boolean isInReviewList; + private boolean retriedToday; + } } } \ No newline at end of file diff --git a/src/main/java/dgu/sw/domain/quiz/repository/UserQuizRepository.java b/src/main/java/dgu/sw/domain/quiz/repository/UserQuizRepository.java index 867cbd7..e6549f6 100644 --- a/src/main/java/dgu/sw/domain/quiz/repository/UserQuizRepository.java +++ b/src/main/java/dgu/sw/domain/quiz/repository/UserQuizRepository.java @@ -26,4 +26,7 @@ public interface UserQuizRepository extends JpaRepository { List findTop5MostWrongOnDate(@Param("date") LocalDate date); boolean existsByUser_UserIdAndQuiz_QuizIdAndSolvedDate(Long userId, Long quizId, LocalDate solvedDate); + + List findByUser_UserIdAndSolvedDate(Long userId, LocalDate solvedDate); + } diff --git a/src/main/java/dgu/sw/domain/quiz/service/QuizService.java b/src/main/java/dgu/sw/domain/quiz/service/QuizService.java index 7ba0d46..b371668 100644 --- a/src/main/java/dgu/sw/domain/quiz/service/QuizService.java +++ b/src/main/java/dgu/sw/domain/quiz/service/QuizService.java @@ -1,5 +1,6 @@ package dgu.sw.domain.quiz.service; +import dgu.sw.domain.quiz.dto.QuizDTO.QuizResponse.YesterdayQuizResponse; import dgu.sw.domain.quiz.dto.QuizDTO.QuizResponse.QuizMainPageResponse; import dgu.sw.domain.quiz.dto.QuizDTO.QuizResponse.QuizReviewResponse; import dgu.sw.domain.quiz.dto.QuizDTO.QuizRequest.SubmitQuizRequest; @@ -19,4 +20,5 @@ public interface QuizService { List searchQuizzes(String userId, String keyword); List getReviewList(String userId); QuizMainPageResponse getQuizMainPageData(String userId); + List getYesterdaySolvedQuizzes(String userId); } diff --git a/src/main/java/dgu/sw/domain/quiz/service/QuizServiceImpl.java b/src/main/java/dgu/sw/domain/quiz/service/QuizServiceImpl.java index d7abfdd..fabecfd 100644 --- a/src/main/java/dgu/sw/domain/quiz/service/QuizServiceImpl.java +++ b/src/main/java/dgu/sw/domain/quiz/service/QuizServiceImpl.java @@ -1,6 +1,7 @@ package dgu.sw.domain.quiz.service; import dgu.sw.domain.quiz.converter.QuizConverter; +import dgu.sw.domain.quiz.dto.QuizDTO.QuizResponse.YesterdayQuizResponse; import dgu.sw.domain.quiz.dto.QuizDTO.QuizResponse.QuizMainPageResponse; import dgu.sw.domain.quiz.dto.QuizDTO.QuizResponse.QuizSearchResponse; import dgu.sw.domain.quiz.dto.QuizDTO.QuizResponse.QuizReviewResponse; @@ -133,7 +134,6 @@ public QuizResultResponse submitQuizAnswer(String userId, Long quizId, SubmitQui if (existingUserQuiz != null) { existingUserQuiz.updateCorrect(isCorrect); - existingUserQuiz.updateSolvedDate(LocalDate.now()); // retriedToday 체크 boolean solvedYesterday = userQuizRepository.existsByUser_UserIdAndQuiz_QuizIdAndSolvedDate( @@ -147,9 +147,6 @@ public QuizResultResponse submitQuizAnswer(String userId, Long quizId, SubmitQui User user = userRepository.findByUserId(Long.valueOf(userId)); UserQuiz userQuiz = QuizConverter.toUserQuiz(user, quiz, isCorrect); - userQuiz.updateSolvedDate(LocalDate.now()); - userQuiz.updateRetriedToday(false); // retriedToday 기본값 false - userQuizRepository.save(userQuiz); } @@ -296,4 +293,26 @@ public QuizMainPageResponse getQuizMainPageData(String userId) { .top5WrongQuizzes(top5Responses) .build(); } + + @Override + public List getYesterdaySolvedQuizzes(String userId) { + Long uid = Long.valueOf(userId); + LocalDate yesterday = LocalDate.now().minusDays(1); + + List solvedQuizzes = userQuizRepository.findByUser_UserIdAndSolvedDate(uid, yesterday); + + if (solvedQuizzes.isEmpty()) { + throw new QuizException(ErrorStatus.QUIZ_SEARCH_NO_RESULTS); + } + + return solvedQuizzes.stream() + .map(userQuiz -> { + Quiz quiz = userQuiz.getQuiz(); + boolean isInReviewList = quizReviewListRepository.existsByUser_UserIdAndQuiz_QuizId(uid, quiz.getQuizId()); + boolean retriedToday = Boolean.TRUE.equals(userQuiz.getRetriedToday()); + + return QuizConverter.toYesterdayQuizResponse(quiz, isInReviewList, retriedToday); + }) + .collect(Collectors.toList()); + } } \ No newline at end of file