이벤트

- 시작날짜, 종료날짜 추가
This commit is contained in:
2024-10-30 23:19:13 +09:00
parent 7f1fadf068
commit b8299bc139
3 changed files with 49 additions and 7 deletions

View File

@@ -9,6 +9,9 @@ import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.multipart.MultipartFile
import java.time.LocalDate
import java.time.ZoneId
import java.time.format.DateTimeFormatter
@Service
class EventService(
@@ -73,10 +76,23 @@ class EventService(
link: String? = null,
title: String? = null,
isAdult: Boolean? = null,
isPopup: Boolean
isPopup: Boolean,
startDateString: String,
endDateString: String
): Long {
if (detail == null && link.isNullOrBlank()) throw SodaException("상세이미지 혹은 링크를 등록하세요")
val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
val startDate = LocalDate.parse(startDateString, dateTimeFormatter).atTime(0, 0)
.atZone(ZoneId.of("Asia/Seoul"))
.withZoneSameInstant(ZoneId.of("UTC"))
.toLocalDateTime()
val endDate = LocalDate.parse(endDateString, dateTimeFormatter).atTime(23, 59, 59)
.atZone(ZoneId.of("Asia/Seoul"))
.withZoneSameInstant(ZoneId.of("UTC"))
.toLocalDateTime()
val event = repository.save(
Event(
thumbnailImage = "",
@@ -85,7 +101,9 @@ class EventService(
link = link,
title = title,
isAdult = isAdult,
isPopup = isPopup
isPopup = isPopup,
startDate = startDate,
endDate = endDate
)
)
@@ -142,7 +160,9 @@ class EventService(
link: String? = null,
title: String? = null,
isAdult: Boolean? = null,
isPopup: Boolean? = null
isPopup: Boolean? = null,
startDateString: String? = null,
endDateString: String? = null
) {
if (id <= 0) throw SodaException("잘못된 요청입니다.")
@@ -197,6 +217,21 @@ class EventService(
if (isAdult != event.isAdult) {
event.isAdult = isAdult
}
val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
if (startDateString != null) {
event.startDate = LocalDate.parse(startDateString, dateTimeFormatter).atTime(0, 0)
.atZone(ZoneId.of("Asia/Seoul"))
.withZoneSameInstant(ZoneId.of("UTC"))
.toLocalDateTime()
}
if (endDateString != null) {
event.endDate = LocalDate.parse(endDateString, dateTimeFormatter).atTime(23, 59, 59)
.atZone(ZoneId.of("Asia/Seoul"))
.withZoneSameInstant(ZoneId.of("UTC"))
.toLocalDateTime()
}
}
@Transactional