Skip to content

Commit

Permalink
Merge pull request #89 from mash-up-kr/xonmin/update-Qset-opentime
Browse files Browse the repository at this point in the history
feat : update qset opentime
  • Loading branch information
xonmin authored Aug 15, 2024
2 parents 1f8bc03 + a626be5 commit 9e5e0ee
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
27 changes: 14 additions & 13 deletions _endpoint_test/admin.http
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 2 additions & 0 deletions api/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 * * *"
Expand Down
6 changes: 0 additions & 6 deletions service/src/main/kotlin/com/mashup/dojo/domain/QuestionSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
18 changes: 11 additions & 7 deletions service/src/main/kotlin/com/mashup/dojo/service/QuestionService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.mashup.dojo.Status
import com.mashup.dojo.domain.ImageId
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
Expand Down Expand Up @@ -87,6 +86,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,
Expand Down Expand Up @@ -184,17 +187,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
Expand All @@ -218,6 +221,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)
Expand Down

0 comments on commit 9e5e0ee

Please sign in to comment.