parent
7f1fadf068
commit
b8299bc139
|
@ -1,6 +1,7 @@
|
|||
package kr.co.vividnext.sodalive.event
|
||||
|
||||
import kr.co.vividnext.sodalive.common.BaseEntity
|
||||
import java.time.LocalDateTime
|
||||
import javax.persistence.Column
|
||||
import javax.persistence.Entity
|
||||
|
||||
|
@ -20,6 +21,8 @@ data class Event(
|
|||
var isAdult: Boolean? = null,
|
||||
@Column(nullable = false)
|
||||
var isPopup: Boolean = false,
|
||||
var startDate: LocalDateTime,
|
||||
var endDate: LocalDateTime,
|
||||
@Column(nullable = false)
|
||||
var isActive: Boolean = true
|
||||
) : BaseEntity()
|
||||
|
|
|
@ -47,9 +47,11 @@ class EventController(private val service: EventService) {
|
|||
@RequestParam(value = "link", required = false) link: String? = null,
|
||||
@RequestParam(value = "title", required = false) title: String? = null,
|
||||
@RequestParam(value = "isAdult", required = false) isAdult: Boolean? = null,
|
||||
@RequestParam(value = "isPopup") isPopup: Boolean
|
||||
@RequestParam(value = "isPopup") isPopup: Boolean,
|
||||
@RequestParam(value = "startDate") startDate: String,
|
||||
@RequestParam(value = "endDate") endDate: String
|
||||
) = ApiResponse.ok(
|
||||
service.save(thumbnail, detail, popup, link, title, isAdult, isPopup),
|
||||
service.save(thumbnail, detail, popup, link, title, isAdult, isPopup, startDate, endDate),
|
||||
"등록되었습니다."
|
||||
)
|
||||
|
||||
|
@ -63,9 +65,11 @@ class EventController(private val service: EventService) {
|
|||
@RequestParam(value = "link", required = false) link: String? = null,
|
||||
@RequestParam(value = "title", required = false) title: String? = null,
|
||||
@RequestParam(value = "isAdult", required = false) isAdult: Boolean? = null,
|
||||
@RequestParam(value = "isPopup", required = false) isPopup: Boolean? = null
|
||||
@RequestParam(value = "isPopup", required = false) isPopup: Boolean? = null,
|
||||
@RequestParam(value = "startDate", required = false) startDate: String? = null,
|
||||
@RequestParam(value = "endDate", required = false) endDate: String? = null
|
||||
) = ApiResponse.ok(
|
||||
service.update(id, thumbnail, detail, popup, link, title, isAdult, isPopup),
|
||||
service.update(id, thumbnail, detail, popup, link, title, isAdult, isPopup, startDate, endDate),
|
||||
"수정되었습니다."
|
||||
)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue