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.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,6 +136,8 @@ class AudioContentMainService(
it.event!!.detailImage
},
popupImageUrl = null,
startDate = startDate,
endDate = endDate,
link = it.event!!.link,
title = it.event!!.title,
isPopup = false

View File

@ -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()

View File

@ -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),
"수정되었습니다."
)

View File

@ -1,9 +1,13 @@
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
import org.springframework.stereotype.Repository
import java.time.LocalDateTime
@Repository
interface EventRepository : JpaRepository<Event, Long>, EventQueryRepository
@ -16,7 +20,10 @@ interface EventQueryRepository {
@Repository
class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : EventQueryRepository {
override fun getEventList(isAdult: Boolean?): List<EventItem> {
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) {
@ -40,6 +47,8 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even
event.thumbnailImage,
event.detailImage,
event.popupImage,
getFormattedDate(event.startDate),
getFormattedDate(event.endDate),
event.link,
event.isAdult,
event.isPopup
@ -52,9 +61,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(
@ -76,6 +88,8 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even
event.thumbnailImage,
event.detailImage,
event.popupImage,
getFormattedDate(event.startDate),
getFormattedDate(event.endDate),
event.link,
event.isAdult,
event.isPopup
@ -86,4 +100,18 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even
.orderBy(event.id.desc())
.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.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

View File

@ -16,6 +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: String,
@JsonProperty("endDate") var endDate: String,
@JsonProperty("link") val link: String? = null,
@JsonProperty("isAdult") val isAdult: Boolean? = null,
@JsonProperty("isPopup") val isPopup: Boolean