Skip to content

Commit 9b5c6d8

Browse files
authored
release: 1.5.0 (#161)
2 parents d17b95b + a20fec0 commit 9b5c6d8

File tree

5 files changed

+90
-2
lines changed

5 files changed

+90
-2
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Check solve today quiz
2+
3+
오늘의 푼 퀴즈 정보를 조회합니다.
4+
5+
## Request
6+
### Http method: `GET`
7+
### URL: `https://api.gitanimals.org/quizs/context/today`
8+
### Request header
9+
- Authorization: `{token}`
10+
11+
## Response
12+
13+
오늘 풀었다면 아래와 같이 응답됩니다.
14+
15+
Response Status 200
16+
17+
```json
18+
{
19+
"isSolved": true,
20+
"contextId": "12345",
21+
"prize": 12345, // 오늘 획득한 prize가 응답된다. 획득한 돈이 없다면 (ex. FAIL) 0
22+
"result": "FAIL" // FAIL, SOLVING, SUCCESS, FAIL, DONE
23+
}
24+
```
25+
26+
오늘의 퀴즈를 아직 풀지 않았다면 아래와 같이 응답됩니다.
27+
28+
Response Status 200
29+
30+
```json
31+
{
32+
"isSolved": false
33+
}
34+
```

src/main/kotlin/org/gitanimals/quiz/app/SolveQuizFacade.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.gitanimals.quiz.app
22

33
import org.gitanimals.quiz.app.request.CreateSolveQuizRequest
44
import org.gitanimals.quiz.app.response.QuizContextResponse
5+
import org.gitanimals.quiz.app.response.TodaySolvedContextResponse
56
import org.gitanimals.quiz.domain.approved.QuizService
67
import org.gitanimals.quiz.domain.context.QuizSolveContext
78
import org.gitanimals.quiz.domain.context.QuizSolveContextService
@@ -64,6 +65,13 @@ class SolveQuizFacade(
6465
quizSolveContextService.stopQuizByIdAndUserId(id = id, userId = userId)
6566
}
6667

68+
fun getTodaySolvedContextResult(token: String): TodaySolvedContextResponse {
69+
val userId = identityApi.getUserByToken(token).id.toLong()
70+
val quizSolveContext = quizSolveContextService.findTodaySolvedContext(userId)
71+
72+
return TodaySolvedContextResponse.from(quizSolveContext)
73+
}
74+
6775
private companion object {
6876
private val quizLevels =
6977
listOf(Level.EASY, Level.EASY, Level.MEDIUM, Level.DIFFICULT, Level.DIFFICULT)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.gitanimals.quiz.app.response
2+
3+
import org.gitanimals.quiz.domain.context.QuizSolveContext
4+
import org.gitanimals.quiz.domain.context.QuizSolveContextStatus
5+
6+
data class TodaySolvedContextResponse(
7+
val isSolved: Boolean,
8+
val contextId: String?,
9+
val prize: Int?,
10+
val result: QuizSolveContextStatus?,
11+
) {
12+
13+
companion object {
14+
15+
fun from(quizSolveContext: QuizSolveContext?): TodaySolvedContextResponse {
16+
if (quizSolveContext == null) {
17+
return TodaySolvedContextResponse(
18+
isSolved = false,
19+
contextId = null,
20+
prize = null,
21+
result = null,
22+
)
23+
}
24+
25+
return TodaySolvedContextResponse(
26+
isSolved = true,
27+
contextId = quizSolveContext.id.toString(),
28+
prize = quizSolveContext.getPrize(),
29+
result = quizSolveContext.getStatus(),
30+
)
31+
}
32+
}
33+
}

src/main/kotlin/org/gitanimals/quiz/controller/QuizContextController.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,10 @@ class QuizContextController(
6262
@PathVariable("contextId") contextId: Long,
6363
) = solveQuizFacade.stopQuiz(token = token, id = contextId)
6464

65+
66+
@ResponseStatus(HttpStatus.OK)
67+
@GetMapping("/quizs/context/today")
68+
fun getTodaySolvedContextResult(
69+
@RequestHeader(HttpHeaders.AUTHORIZATION) token: String,
70+
) = solveQuizFacade.getTodaySolvedContextResult(token)
6571
}

src/main/kotlin/org/gitanimals/quiz/domain/context/QuizSolveContextService.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class QuizSolveContextService(
1313
private val quizSolveContextRepository: QuizSolveContextRepository,
1414
) {
1515

16-
// @Transactional
16+
// @Transactional
1717
fun createQuizSolveContext(
1818
userId: Long,
1919
category: Category,
2020
quizs: List<Quiz>,
2121
): QuizSolveContext {
22-
val now = LocalDate.ofInstant(instant(), ZoneId.of("Asia/Seoul"))
22+
val now = LocalDate.ofInstant(instant(), ZoneId.of("UTC"))
2323
quizSolveContextRepository.findQuizSolveContextByUserIdAndSolvedAt(userId, now)?.let {
2424
quizSolveContextRepository.deleteAll() // 전체삭제 QA끝나고 지운다.
2525
// throw IllegalArgumentException("Already solve daily quiz.")
@@ -57,6 +57,13 @@ class QuizSolveContextService(
5757
quizSolveContext.stopSolve()
5858
}
5959

60+
@Transactional(readOnly = true)
61+
fun findTodaySolvedContext(userId: Long): QuizSolveContext?{
62+
val now = LocalDate.ofInstant(instant(), ZoneId.of("UTC"))
63+
64+
return quizSolveContextRepository.findQuizSolveContextByUserIdAndSolvedAt(userId, now)
65+
}
66+
6067
private fun getQuizSolveContextByIdAndUserIdWithLock(
6168
id: Long,
6269
userId: Long

0 commit comments

Comments
 (0)