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

๐Ÿงฉ:: ํ‘ผ ๋ฌธ์ œ ๋‚ ์งœ ์ˆœ์œผ๋กœ ์ •๋ ฌ๋˜๋„๋ก ์ˆ˜์ • #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Expand Up @@ -21,6 +21,7 @@ class GetQuizService (
val quiz: Quiz = quizRepository.findQuizById(quizId)

currentUser.todaySolvedCounts + 1

return GetQuizResponse.of(quiz, currentUser.todaySolvedCounts)
}
}
Original file line number Diff line number Diff line change
@@ -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<GetLastSolvedQuizResponse> {
val response = getLastQuizListService.execute(userId)
return ResponseEntity.ok(response)
}
}
}
Original file line number Diff line number Diff line change
@@ -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<QuizDto>
val quizzesByDate: Map<String, List<QuizDto>>
) {
data class QuizDto(
val id: Long,
Expand All @@ -16,4 +17,13 @@ data class GetLastSolvedQuizResponse(
val reason: String,
val solvedAt: LocalDateTime
)
}

companion object {
fun fromQuizList(quizzes: List<QuizDto>): GetLastSolvedQuizResponse {
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
val quizzesByDate = quizzes.sortedByDescending { it.solvedAt }
.groupBy { it.solvedAt.format(formatter) }
return GetLastSolvedQuizResponse(quizzesByDate)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}