diff --git a/src/main/kotlin/scul/projectscul/domain/quiz/service/GetQuizService.kt b/src/main/kotlin/scul/projectscul/domain/quiz/service/GetQuizService.kt index cd2b9d6..98232b7 100644 --- a/src/main/kotlin/scul/projectscul/domain/quiz/service/GetQuizService.kt +++ b/src/main/kotlin/scul/projectscul/domain/quiz/service/GetQuizService.kt @@ -21,6 +21,7 @@ class GetQuizService ( val quiz: Quiz = quizRepository.findQuizById(quizId) currentUser.todaySolvedCounts + 1 + return GetQuizResponse.of(quiz, currentUser.todaySolvedCounts) } } diff --git a/src/main/kotlin/scul/projectscul/domain/solvedQuiz/presentation/SolvedQuizController.kt b/src/main/kotlin/scul/projectscul/domain/solvedQuiz/presentation/SolvedQuizController.kt index 56c9609..650127b 100644 --- a/src/main/kotlin/scul/projectscul/domain/solvedQuiz/presentation/SolvedQuizController.kt +++ b/src/main/kotlin/scul/projectscul/domain/solvedQuiz/presentation/SolvedQuizController.kt @@ -1,22 +1,22 @@ package scul.projectscul.domain.solvedQuiz.presentation import org.jetbrains.annotations.NotNull -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 +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.* import scul.projectscul.domain.solvedQuiz.service.GetLastQuizListService +import scul.projectscul.domain.solvedQuiz.presentation.response.GetLastSolvedQuizResponse import java.util.* -@RequestMapping("/scul/user") +@RequestMapping("/scul/solved") @RestController class SolvedQuizController ( private val getLastQuizListService: GetLastQuizListService ){ - @GetMapping("/solved/{user-id}") + @GetMapping("/{user-id}") fun getLastQuizList( @PathVariable("user-id") @NotNull userId: UUID - ) { - getLastQuizListService.execute(userId) + ): ResponseEntity { + val response = getLastQuizListService.execute(userId) + return ResponseEntity.ok(response) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/scul/projectscul/domain/solvedQuiz/presentation/response/GetLastSolvedQuizResponse.kt b/src/main/kotlin/scul/projectscul/domain/solvedQuiz/presentation/response/GetLastSolvedQuizResponse.kt index 9af63c2..8817c0e 100644 --- a/src/main/kotlin/scul/projectscul/domain/solvedQuiz/presentation/response/GetLastSolvedQuizResponse.kt +++ b/src/main/kotlin/scul/projectscul/domain/solvedQuiz/presentation/response/GetLastSolvedQuizResponse.kt @@ -1,9 +1,10 @@ package scul.projectscul.domain.solvedQuiz.presentation.response import java.time.LocalDateTime +import java.time.format.DateTimeFormatter data class GetLastSolvedQuizResponse( - val quizzes: List + val quizzesByDate: Map> ) { data class QuizDto( val id: Long, @@ -16,4 +17,13 @@ data class GetLastSolvedQuizResponse( val reason: String, val solvedAt: LocalDateTime ) -} \ No newline at end of file + + companion object { + fun fromQuizList(quizzes: List): GetLastSolvedQuizResponse { + val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") + val quizzesByDate = quizzes.sortedByDescending { it.solvedAt } + .groupBy { it.solvedAt.format(formatter) } + return GetLastSolvedQuizResponse(quizzesByDate) + } + } +} diff --git a/src/main/kotlin/scul/projectscul/domain/solvedQuiz/service/GetLastQuizListService.kt b/src/main/kotlin/scul/projectscul/domain/solvedQuiz/service/GetLastQuizListService.kt index 0344be2..2a69321 100644 --- a/src/main/kotlin/scul/projectscul/domain/solvedQuiz/service/GetLastQuizListService.kt +++ b/src/main/kotlin/scul/projectscul/domain/solvedQuiz/service/GetLastQuizListService.kt @@ -14,20 +14,19 @@ class GetLastQuizListService( fun execute(userId: UUID): GetLastSolvedQuizResponse { val solvedQuizzes = userQuizSolveRepository.findByUserId(userId) - return GetLastSolvedQuizResponse( - quizzes = solvedQuizzes.map { userQuizSolve -> - GetLastSolvedQuizResponse.QuizDto( - id = userQuizSolve.quiz.id, - quiz = userQuizSolve.quiz.quiz, - answer = userQuizSolve.quiz.answer, - choice1 = userQuizSolve.quiz.choice1, - choice2 = userQuizSolve.quiz.choice2, - choice3 = userQuizSolve.quiz.choice3, - choice4 = userQuizSolve.quiz.choice4, - reason = userQuizSolve.quiz.reason, - solvedAt = userQuizSolve.solvedAt - ) - } - ) + val quizDtos = solvedQuizzes.map { userQuizSolve -> + GetLastSolvedQuizResponse.QuizDto( + id = userQuizSolve.quiz.id, + quiz = userQuizSolve.quiz.quiz, + answer = userQuizSolve.quiz.answer, + choice1 = userQuizSolve.quiz.choice1, + choice2 = userQuizSolve.quiz.choice2, + choice3 = userQuizSolve.quiz.choice3, + choice4 = userQuizSolve.quiz.choice4, + reason = userQuizSolve.quiz.reason, + solvedAt = userQuizSolve.solvedAt + ) + } + return GetLastSolvedQuizResponse.fromQuizList(quizDtos) } -} \ No newline at end of file +}