From b8299bc139a410d6b18e859f03cc6a82493ec4de Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 30 Oct 2024 23:19:13 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20-=20=EC=8B=9C?= =?UTF-8?q?=EC=9E=91=EB=82=A0=EC=A7=9C,=20=EC=A2=85=EB=A3=8C=EB=82=A0?= =?UTF-8?q?=EC=A7=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kr/co/vividnext/sodalive/event/Event.kt | 3 ++ .../sodalive/event/EventController.kt | 12 ++++-- .../vividnext/sodalive/event/EventService.kt | 41 +++++++++++++++++-- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/event/Event.kt b/src/main/kotlin/kr/co/vividnext/sodalive/event/Event.kt index 8f0f1e9..83f8e60 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/event/Event.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/event/Event.kt @@ -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() diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/event/EventController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/event/EventController.kt index 0509ab5..20bf6d1 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/event/EventController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/event/EventController.kt @@ -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), "수정되었습니다." ) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/event/EventService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/event/EventService.kt index 56e0f43..42c16a4 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/event/EventService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/event/EventService.kt @@ -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 From 116aea3431ddfaba663806a6cdae8e2ee5fed118 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 30 Oct 2024 23:23:27 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20-=20=EC=8B=9C=EC=9E=91=EB=82=A0=EC=A7=9C,=20?= =?UTF-8?q?=EC=A2=85=EB=A3=8C=EB=82=A0=EC=A7=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kr/co/vividnext/sodalive/event/EventRepository.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/event/EventRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/event/EventRepository.kt index a751ebe..c733b3c 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/event/EventRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/event/EventRepository.kt @@ -4,6 +4,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory import kr.co.vividnext.sodalive.event.QEvent.event import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository +import java.time.LocalDateTime @Repository interface EventRepository : JpaRepository, EventQueryRepository @@ -16,7 +17,10 @@ interface EventQueryRepository { @Repository class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : EventQueryRepository { override fun getEventList(isAdult: Boolean?): List { + val now = LocalDateTime.now() var where = event.isActive.isTrue + .and(event.startDate.loe(now)) + .and(event.endDate.goe(now)) if (isAdult != null) { where = if (isAdult) { @@ -52,9 +56,12 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even } override fun getMainEventPopup(isAdult: Boolean): EventItem? { + val now = LocalDateTime.now() var where = event.isActive.isTrue .and(event.isPopup.isTrue) .and(event.popupImage.isNotNull) + .and(event.startDate.loe(now)) + .and(event.endDate.goe(now)) where = if (isAdult) { where.and( From 85f14edc0a383be936bb7e343c230d87584d89fa Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 30 Oct 2024 23:28:36 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20-=20=EC=8B=9C=EC=9E=91=EB=82=A0=EC=A7=9C,=20?= =?UTF-8?q?=EC=A2=85=EB=A3=8C=EB=82=A0=EC=A7=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sodalive/content/main/AudioContentMainService.kt | 2 ++ .../kotlin/kr/co/vividnext/sodalive/event/EventRepository.kt | 4 ++++ .../kotlin/kr/co/vividnext/sodalive/event/GetEventResponse.kt | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/content/main/AudioContentMainService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/content/main/AudioContentMainService.kt index db2c22a..1ef9df8 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/content/main/AudioContentMainService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/content/main/AudioContentMainService.kt @@ -123,6 +123,8 @@ class AudioContentMainService( it.event!!.detailImage }, popupImageUrl = null, + startDate = it.event!!.startDate, + endDate = it.event!!.endDate, link = it.event!!.link, title = it.event!!.title, isPopup = false diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/event/EventRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/event/EventRepository.kt index c733b3c..544a8cc 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/event/EventRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/event/EventRepository.kt @@ -44,6 +44,8 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even event.thumbnailImage, event.detailImage, event.popupImage, + event.startDate, + event.endDate, event.link, event.isAdult, event.isPopup @@ -83,6 +85,8 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even event.thumbnailImage, event.detailImage, event.popupImage, + event.startDate, + event.endDate, event.link, event.isAdult, event.isPopup diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/event/GetEventResponse.kt b/src/main/kotlin/kr/co/vividnext/sodalive/event/GetEventResponse.kt index b557f50..cf29019 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/event/GetEventResponse.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/event/GetEventResponse.kt @@ -3,6 +3,7 @@ package kr.co.vividnext.sodalive.event import com.fasterxml.jackson.annotation.JsonIgnoreProperties import com.fasterxml.jackson.annotation.JsonProperty import com.querydsl.core.annotations.QueryProjection +import java.time.LocalDateTime data class GetEventResponse( @JsonProperty("totalCount") val totalCount: Int, @@ -16,6 +17,8 @@ data class EventItem @QueryProjection constructor( @JsonProperty("thumbnailImageUrl") var thumbnailImageUrl: String, @JsonProperty("detailImageUrl") var detailImageUrl: String? = null, @JsonProperty("popupImageUrl") var popupImageUrl: String? = null, + @JsonProperty("startDate") var startDate: LocalDateTime, + @JsonProperty("endDate") var endDate: LocalDateTime, @JsonProperty("link") val link: String? = null, @JsonProperty("isAdult") val isAdult: Boolean? = null, @JsonProperty("isPopup") val isPopup: Boolean From baeea79e66db22f8e47dbe8e897be79f2ac9b3fa Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 30 Oct 2024 23:55:07 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20-=20=EC=8B=9C=EC=9E=91=EB=82=A0=EC=A7=9C,=20?= =?UTF-8?q?=EC=A2=85=EB=A3=8C=EB=82=A0=EC=A7=9C=20format=20'yyyy-MM-dd'?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../content/main/AudioContentMainService.kt | 17 +++++++++++-- .../sodalive/event/EventRepository.kt | 25 ++++++++++++++++--- .../sodalive/event/GetEventResponse.kt | 5 ++-- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/content/main/AudioContentMainService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/content/main/AudioContentMainService.kt index 1ef9df8..598b8b2 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/content/main/AudioContentMainService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/content/main/AudioContentMainService.kt @@ -14,6 +14,8 @@ import org.springframework.cache.annotation.Cacheable import org.springframework.data.domain.Pageable import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional +import java.time.ZoneId +import java.time.format.DateTimeFormatter @Service class AudioContentMainService( @@ -107,6 +109,17 @@ class AudioContentMainService( type = it.type, thumbnailImageUrl = "$imageHost/${it.thumbnailImage}", eventItem = if (it.type == AudioContentBannerType.EVENT && it.event != null) { + val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") + val startDate = it.event!!.startDate + .atZone(ZoneId.of("UTC")) + .withZoneSameInstant(ZoneId.of("Asia/Seoul")) + .format(dateTimeFormatter) + + val endDate = it.event!!.endDate + .atZone(ZoneId.of("UTC")) + .withZoneSameInstant(ZoneId.of("Asia/Seoul")) + .format(dateTimeFormatter) + EventItem( id = it.event!!.id!!, thumbnailImageUrl = if (!it.event!!.thumbnailImage.startsWith("https://")) { @@ -123,8 +136,8 @@ class AudioContentMainService( it.event!!.detailImage }, popupImageUrl = null, - startDate = it.event!!.startDate, - endDate = it.event!!.endDate, + startDate = startDate, + endDate = endDate, link = it.event!!.link, title = it.event!!.title, isPopup = false diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/event/EventRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/event/EventRepository.kt index 544a8cc..8f40b49 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/event/EventRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/event/EventRepository.kt @@ -1,5 +1,8 @@ package kr.co.vividnext.sodalive.event +import com.querydsl.core.types.dsl.DateTimePath +import com.querydsl.core.types.dsl.Expressions +import com.querydsl.core.types.dsl.StringTemplate import com.querydsl.jpa.impl.JPAQueryFactory import kr.co.vividnext.sodalive.event.QEvent.event import org.springframework.data.jpa.repository.JpaRepository @@ -44,8 +47,8 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even event.thumbnailImage, event.detailImage, event.popupImage, - event.startDate, - event.endDate, + getFormattedDate(event.startDate), + getFormattedDate(event.endDate), event.link, event.isAdult, event.isPopup @@ -85,8 +88,8 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even event.thumbnailImage, event.detailImage, event.popupImage, - event.startDate, - event.endDate, + getFormattedDate(event.startDate), + getFormattedDate(event.endDate), event.link, event.isAdult, event.isPopup @@ -97,4 +100,18 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even .orderBy(event.id.desc()) .fetchFirst() } + + private fun getFormattedDate(dateTimePath: DateTimePath): StringTemplate { + return Expressions.stringTemplate( + "DATE_FORMAT({0}, {1})", + Expressions.dateTimeTemplate( + LocalDateTime::class.java, + "CONVERT_TZ({0},{1},{2})", + dateTimePath, + "UTC", + "Asia/Seoul" + ), + "%Y-%m-%d" + ) + } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/event/GetEventResponse.kt b/src/main/kotlin/kr/co/vividnext/sodalive/event/GetEventResponse.kt index cf29019..80c4ef8 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/event/GetEventResponse.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/event/GetEventResponse.kt @@ -3,7 +3,6 @@ package kr.co.vividnext.sodalive.event import com.fasterxml.jackson.annotation.JsonIgnoreProperties import com.fasterxml.jackson.annotation.JsonProperty import com.querydsl.core.annotations.QueryProjection -import java.time.LocalDateTime data class GetEventResponse( @JsonProperty("totalCount") val totalCount: Int, @@ -17,8 +16,8 @@ data class EventItem @QueryProjection constructor( @JsonProperty("thumbnailImageUrl") var thumbnailImageUrl: String, @JsonProperty("detailImageUrl") var detailImageUrl: String? = null, @JsonProperty("popupImageUrl") var popupImageUrl: String? = null, - @JsonProperty("startDate") var startDate: LocalDateTime, - @JsonProperty("endDate") var endDate: LocalDateTime, + @JsonProperty("startDate") var startDate: String, + @JsonProperty("endDate") var endDate: String, @JsonProperty("link") val link: String? = null, @JsonProperty("isAdult") val isAdult: Boolean? = null, @JsonProperty("isPopup") val isPopup: Boolean