Merge pull request 'test' (#231) from test into main

Reviewed-on: #231
This commit is contained in:
klaus 2024-10-31 03:09:13 +00:00
commit f68f24cb2c
6 changed files with 94 additions and 7 deletions

View File

@ -14,6 +14,8 @@ import org.springframework.cache.annotation.Cacheable
import org.springframework.data.domain.Pageable import org.springframework.data.domain.Pageable
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional import org.springframework.transaction.annotation.Transactional
import java.time.ZoneId
import java.time.format.DateTimeFormatter
@Service @Service
class AudioContentMainService( class AudioContentMainService(
@ -107,6 +109,17 @@ class AudioContentMainService(
type = it.type, type = it.type,
thumbnailImageUrl = "$imageHost/${it.thumbnailImage}", thumbnailImageUrl = "$imageHost/${it.thumbnailImage}",
eventItem = if (it.type == AudioContentBannerType.EVENT && it.event != null) { 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( EventItem(
id = it.event!!.id!!, id = it.event!!.id!!,
thumbnailImageUrl = if (!it.event!!.thumbnailImage.startsWith("https://")) { thumbnailImageUrl = if (!it.event!!.thumbnailImage.startsWith("https://")) {
@ -123,6 +136,8 @@ class AudioContentMainService(
it.event!!.detailImage it.event!!.detailImage
}, },
popupImageUrl = null, popupImageUrl = null,
startDate = startDate,
endDate = endDate,
link = it.event!!.link, link = it.event!!.link,
title = it.event!!.title, title = it.event!!.title,
isPopup = false isPopup = false

View File

@ -1,6 +1,7 @@
package kr.co.vividnext.sodalive.event package kr.co.vividnext.sodalive.event
import kr.co.vividnext.sodalive.common.BaseEntity import kr.co.vividnext.sodalive.common.BaseEntity
import java.time.LocalDateTime
import javax.persistence.Column import javax.persistence.Column
import javax.persistence.Entity import javax.persistence.Entity
@ -20,6 +21,8 @@ data class Event(
var isAdult: Boolean? = null, var isAdult: Boolean? = null,
@Column(nullable = false) @Column(nullable = false)
var isPopup: Boolean = false, var isPopup: Boolean = false,
var startDate: LocalDateTime,
var endDate: LocalDateTime,
@Column(nullable = false) @Column(nullable = false)
var isActive: Boolean = true var isActive: Boolean = true
) : BaseEntity() ) : BaseEntity()

View File

@ -47,9 +47,11 @@ class EventController(private val service: EventService) {
@RequestParam(value = "link", required = false) link: String? = null, @RequestParam(value = "link", required = false) link: String? = null,
@RequestParam(value = "title", required = false) title: String? = null, @RequestParam(value = "title", required = false) title: String? = null,
@RequestParam(value = "isAdult", required = false) isAdult: Boolean? = 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( ) = 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 = "link", required = false) link: String? = null,
@RequestParam(value = "title", required = false) title: String? = null, @RequestParam(value = "title", required = false) title: String? = null,
@RequestParam(value = "isAdult", required = false) isAdult: Boolean? = 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( ) = ApiResponse.ok(
service.update(id, thumbnail, detail, popup, link, title, isAdult, isPopup), service.update(id, thumbnail, detail, popup, link, title, isAdult, isPopup, startDate, endDate),
"수정되었습니다." "수정되었습니다."
) )

View File

@ -1,9 +1,13 @@
package kr.co.vividnext.sodalive.event 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 com.querydsl.jpa.impl.JPAQueryFactory
import kr.co.vividnext.sodalive.event.QEvent.event import kr.co.vividnext.sodalive.event.QEvent.event
import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository import org.springframework.stereotype.Repository
import java.time.LocalDateTime
@Repository @Repository
interface EventRepository : JpaRepository<Event, Long>, EventQueryRepository interface EventRepository : JpaRepository<Event, Long>, EventQueryRepository
@ -16,7 +20,10 @@ interface EventQueryRepository {
@Repository @Repository
class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : EventQueryRepository { class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : EventQueryRepository {
override fun getEventList(isAdult: Boolean?): List<EventItem> { override fun getEventList(isAdult: Boolean?): List<EventItem> {
val now = LocalDateTime.now()
var where = event.isActive.isTrue var where = event.isActive.isTrue
.and(event.startDate.loe(now))
.and(event.endDate.goe(now))
if (isAdult != null) { if (isAdult != null) {
where = if (isAdult) { where = if (isAdult) {
@ -40,6 +47,8 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even
event.thumbnailImage, event.thumbnailImage,
event.detailImage, event.detailImage,
event.popupImage, event.popupImage,
getFormattedDate(event.startDate),
getFormattedDate(event.endDate),
event.link, event.link,
event.isAdult, event.isAdult,
event.isPopup event.isPopup
@ -52,9 +61,12 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even
} }
override fun getMainEventPopup(isAdult: Boolean): EventItem? { override fun getMainEventPopup(isAdult: Boolean): EventItem? {
val now = LocalDateTime.now()
var where = event.isActive.isTrue var where = event.isActive.isTrue
.and(event.isPopup.isTrue) .and(event.isPopup.isTrue)
.and(event.popupImage.isNotNull) .and(event.popupImage.isNotNull)
.and(event.startDate.loe(now))
.and(event.endDate.goe(now))
where = if (isAdult) { where = if (isAdult) {
where.and( where.and(
@ -76,6 +88,8 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even
event.thumbnailImage, event.thumbnailImage,
event.detailImage, event.detailImage,
event.popupImage, event.popupImage,
getFormattedDate(event.startDate),
getFormattedDate(event.endDate),
event.link, event.link,
event.isAdult, event.isAdult,
event.isPopup event.isPopup
@ -86,4 +100,18 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even
.orderBy(event.id.desc()) .orderBy(event.id.desc())
.fetchFirst() .fetchFirst()
} }
private fun getFormattedDate(dateTimePath: DateTimePath<LocalDateTime>): 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"
)
}
} }

View File

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

View File

@ -16,6 +16,8 @@ data class EventItem @QueryProjection constructor(
@JsonProperty("thumbnailImageUrl") var thumbnailImageUrl: String, @JsonProperty("thumbnailImageUrl") var thumbnailImageUrl: String,
@JsonProperty("detailImageUrl") var detailImageUrl: String? = null, @JsonProperty("detailImageUrl") var detailImageUrl: String? = null,
@JsonProperty("popupImageUrl") var popupImageUrl: String? = null, @JsonProperty("popupImageUrl") var popupImageUrl: String? = null,
@JsonProperty("startDate") var startDate: String,
@JsonProperty("endDate") var endDate: String,
@JsonProperty("link") val link: String? = null, @JsonProperty("link") val link: String? = null,
@JsonProperty("isAdult") val isAdult: Boolean? = null, @JsonProperty("isAdult") val isAdult: Boolean? = null,
@JsonProperty("isPopup") val isPopup: Boolean @JsonProperty("isPopup") val isPopup: Boolean