From caa2e352f2e0055e0ac9454133a01848fb6c7667 Mon Sep 17 00:00:00 2001 From: xonmin Date: Thu, 15 Aug 2024 18:08:49 +0900 Subject: [PATCH 1/2] update : QSet openTime to application.yaml --- api/src/main/resources/application.yaml | 2 ++ .../com/mashup/dojo/domain/QuestionSet.kt | 6 ------ .../com/mashup/dojo/service/QuestionService.kt | 17 ++++++++++------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/api/src/main/resources/application.yaml b/api/src/main/resources/application.yaml index f994ce6c..67f031b9 100644 --- a/api/src/main/resources/application.yaml +++ b/api/src/main/resources/application.yaml @@ -8,6 +8,8 @@ dojo: questionSet: size: 12 friend-ratio: 0.6 # percent + open-time-1: "08:00:00" + open-time-2: "23:00:00" scheduler: cron: "0 0 9,21 * * *" diff --git a/service/src/main/kotlin/com/mashup/dojo/domain/QuestionSet.kt b/service/src/main/kotlin/com/mashup/dojo/domain/QuestionSet.kt index da77c99f..4992a8b3 100644 --- a/service/src/main/kotlin/com/mashup/dojo/domain/QuestionSet.kt +++ b/service/src/main/kotlin/com/mashup/dojo/domain/QuestionSet.kt @@ -2,7 +2,6 @@ package com.mashup.dojo.domain import com.mashup.dojo.UUIDGenerator import java.time.LocalDateTime -import java.time.LocalTime @JvmInline value class QuestionSetId(val value: String) @@ -43,8 +42,3 @@ enum class PublishStatus { ACTIVE, // 운영중 UPCOMING, // 예정 } - -object PublishedTime { - val OPEN_TIME_1: LocalTime = LocalTime.of(8, 0, 0) - val OPEN_TIME_2: LocalTime = LocalTime.of(11, 0, 0) -} diff --git a/service/src/main/kotlin/com/mashup/dojo/service/QuestionService.kt b/service/src/main/kotlin/com/mashup/dojo/service/QuestionService.kt index 2d12b003..b4785e43 100644 --- a/service/src/main/kotlin/com/mashup/dojo/service/QuestionService.kt +++ b/service/src/main/kotlin/com/mashup/dojo/service/QuestionService.kt @@ -13,7 +13,6 @@ import com.mashup.dojo.domain.ImageId import com.mashup.dojo.domain.Member import com.mashup.dojo.domain.MemberId import com.mashup.dojo.domain.PublishStatus -import com.mashup.dojo.domain.PublishedTime import com.mashup.dojo.domain.Question import com.mashup.dojo.domain.QuestionCategory import com.mashup.dojo.domain.QuestionId @@ -84,6 +83,10 @@ class DefaultQuestionService( private val questionSetSize: Int, @Value("\${dojo.questionSet.friend-ratio}") private val friendQuestionRatio: Float, + @Value("\${dojo.questionSet.open-time-1}") + private val openTime1: LocalTime, + @Value("\${dojo.questionSet.open-time-2}") + private val openTime2: LocalTime, override val questionRepository: QuestionRepository, override val questionSetRepository: QuestionSetRepository, override val questionSheetRepository: QuestionSheetRepository, @@ -181,17 +184,17 @@ class DefaultQuestionService( val today = LocalDate.now() when { - now.isBefore(PublishedTime.OPEN_TIME_1) -> today.atTime(PublishedTime.OPEN_TIME_1) - now.isBefore(PublishedTime.OPEN_TIME_2) -> today.atTime(PublishedTime.OPEN_TIME_2) - else -> today.plusDays(1).atTime(PublishedTime.OPEN_TIME_1) + now.isBefore(openTime1) -> today.atTime(openTime1) + now.isBefore(openTime2) -> today.atTime(openTime2) + else -> today.plusDays(1).atTime(openTime1) } } val endTime = - if (publishedTime.toLocalTime() == PublishedTime.OPEN_TIME_1) { - publishedTime.toLocalDate().atTime(PublishedTime.OPEN_TIME_2) + if (publishedTime.toLocalTime() == openTime1) { + publishedTime.toLocalDate().atTime(openTime2) } else { // publishedTime.toLocalTime() == PublishedTime.OPEN_TIME_2 - publishedTime.toLocalDate().plusDays(1).atTime(PublishedTime.OPEN_TIME_1) + publishedTime.toLocalDate().plusDays(1).atTime(openTime1) } // 우선 만들어지는 시점이 다음 투표 이전에 만들어질 QSet 을 만든다고 가정, 따라서 해당 QSet 은 바로 다음 발행될 QSet From a626be52d5144cdf721718b8d0db524b44fb214e Mon Sep 17 00:00:00 2001 From: xonmin Date: Thu, 15 Aug 2024 18:30:17 +0900 Subject: [PATCH 2/2] update : create Custom QSet required condition --- _endpoint_test/admin.http | 27 ++++++++++--------- .../mashup/dojo/service/QuestionService.kt | 1 + 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/_endpoint_test/admin.http b/_endpoint_test/admin.http index 95db7131..0f52557e 100644 --- a/_endpoint_test/admin.http +++ b/_endpoint_test/admin.http @@ -15,18 +15,19 @@ Content-Type: application/json { "questionIds": [ - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - "10", - "11", - "12" + "5f20cba4-82a3-4a6c-803d-fb974a12175a", + "7f714458-cd89-4ca8-b478-577555ca1183", + "7480d122-9710-43b7-a6ec-a0cd7227b034", + "d784a52d-cbe4-4dc8-88e1-c1b3f7e73eab", + "cf68eff6-4df1-48bb-b3e3-3d8ec9e8fa62", + "8fe58eb4-0a7e-47f9-8a4d-6e6b87e828df", + "8aa76435-214d-4b86-93b1-d503f9f023db", + "6c859372-8217-4e75-89e9-6615fd8f45d5", + "5fb8a8d0-a368-478e-8314-a050d841bc3b", + "511b79d5-fc4f-4d48-b41e-4b62b3798645", + "43893c72-f4e8-4dad-9be5-e3085cbd933d", + "0fe67252-ced8-4c0c-9457-64dcdf7aa051" ], - "publishedAt": "2024-08-20T21:00:00" + "publishedAt": "2024-08-20T23:00:00", + "endAt": "2024-08-21T08:00:00" } diff --git a/service/src/main/kotlin/com/mashup/dojo/service/QuestionService.kt b/service/src/main/kotlin/com/mashup/dojo/service/QuestionService.kt index b4785e43..5b3569e7 100644 --- a/service/src/main/kotlin/com/mashup/dojo/service/QuestionService.kt +++ b/service/src/main/kotlin/com/mashup/dojo/service/QuestionService.kt @@ -218,6 +218,7 @@ class DefaultQuestionService( ): QuestionSet { require(questionIds.size == questionSetSize) { "questions size for QuestionSet must be $questionSetSize" } require(publishedAt >= LocalDateTime.now()) { "publishedAt must be in the future" } + require(endAt > publishedAt) { "endAt must be later than publishedAt " } val questionOrders = questionIds.mapIndexed { idx, qId -> QuestionOrder(qId, idx + 1) } val questionSet = QuestionSet.create(questionOrders, publishedAt, endAt)