Skip to content

Commit cf45a09

Browse files
committed
feat: testSecret이 없으면 호출불가능하도록 수정한다
1 parent 4d549e6 commit cf45a09

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
package org.gitanimals.quiz.controller
22

33
import org.gitanimals.quiz.domain.context.QuizSolveContextRepository
4+
import org.springframework.beans.factory.annotation.Value
45
import org.springframework.web.bind.annotation.DeleteMapping
5-
import org.springframework.web.bind.annotation.RequestParam
6+
import org.springframework.web.bind.annotation.RequestHeader
67
import org.springframework.web.bind.annotation.RestController
78

89
@RestController
910
class QuizQaController(
1011
private val quizSolveContextRepository: QuizSolveContextRepository,
12+
@Value("\${test.secret}") private val testSecret: String,
1113
) {
1214

1315
@DeleteMapping("/quizs/qa/context")
1416
fun deleteQuizContext(
15-
@RequestParam("userId") userId: Long,
16-
) = quizSolveContextRepository.deleteByUserId(userId)
17+
@RequestHeader("Test-Secret") testSecret: String
18+
) {
19+
require(testSecret == this.testSecret) { "Not matched testSecret" }
20+
21+
quizSolveContextRepository.deleteAll()
22+
}
1723
}

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

-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@ interface QuizSolveContextRepository : JpaRepository<QuizSolveContext, Long> {
2525
id: Long,
2626
userId: Long,
2727
): QuizSolveContext?
28-
29-
fun deleteByUserId(userId: Long)
3028
}

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ 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 {
2222
val now = LocalDate.ofInstant(instant(), ZoneId.of("UTC"))
2323
quizSolveContextRepository.findQuizSolveContextByUserIdAndSolvedAt(userId, now)?.let {
24-
quizSolveContextRepository.deleteAll() // 전체삭제 QA끝나고 지운다.
25-
// throw IllegalArgumentException("Already solve daily quiz.")
24+
throw IllegalArgumentException("Already solve daily quiz.")
2625
}
2726

2827
val quizSolveContext = QuizSolveContext.of(
@@ -58,7 +57,7 @@ class QuizSolveContextService(
5857
}
5958

6059
@Transactional(readOnly = true)
61-
fun findTodaySolvedContext(userId: Long): QuizSolveContext?{
60+
fun findTodaySolvedContext(userId: Long): QuizSolveContext? {
6261
val now = LocalDate.ofInstant(instant(), ZoneId.of("UTC"))
6362

6463
return quizSolveContextRepository.findQuizSolveContextByUserIdAndSolvedAt(userId, now)

0 commit comments

Comments
 (0)