관리자 - 이벤트 배너 서비스
- 이미지 host를 Querydsl 코드에서 추가 - 시작 전인 이벤트도 보이도록 수정
This commit is contained in:
parent
327b0149d9
commit
dd138bff86
|
@ -2,10 +2,13 @@ package kr.co.vividnext.sodalive.admin.event.banner
|
||||||
|
|
||||||
import com.querydsl.core.types.dsl.DateTimePath
|
import com.querydsl.core.types.dsl.DateTimePath
|
||||||
import com.querydsl.core.types.dsl.Expressions
|
import com.querydsl.core.types.dsl.Expressions
|
||||||
|
import com.querydsl.core.types.dsl.StringExpression
|
||||||
|
import com.querydsl.core.types.dsl.StringPath
|
||||||
import com.querydsl.core.types.dsl.StringTemplate
|
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.Event
|
import kr.co.vividnext.sodalive.event.Event
|
||||||
import kr.co.vividnext.sodalive.event.QEvent.event
|
import kr.co.vividnext.sodalive.event.QEvent.event
|
||||||
|
import org.springframework.beans.factory.annotation.Value
|
||||||
import org.springframework.data.jpa.repository.JpaRepository
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
|
@ -16,22 +19,23 @@ interface AdminEventBannerQueryRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
class AdminEventBannerQueryRepositoryImpl(
|
class AdminEventBannerQueryRepositoryImpl(
|
||||||
private val queryFactory: JPAQueryFactory
|
private val queryFactory: JPAQueryFactory,
|
||||||
|
@Value("\${cloud.aws.cloud-front.host}")
|
||||||
|
private val cloudFrontHost: String
|
||||||
) : AdminEventBannerQueryRepository {
|
) : AdminEventBannerQueryRepository {
|
||||||
override fun getEventList(): List<GetAdminEventResponse> {
|
override fun getEventList(): List<GetAdminEventResponse> {
|
||||||
val now = LocalDateTime.now()
|
val now = LocalDateTime.now()
|
||||||
val where = event.isActive.isTrue
|
val where = event.isActive.isTrue
|
||||||
.and(event.startDate.loe(now))
|
.and(event.startDate.loe(now))
|
||||||
.and(event.endDate.goe(now))
|
|
||||||
|
|
||||||
return queryFactory
|
return queryFactory
|
||||||
.select(
|
.select(
|
||||||
QGetAdminEventResponse(
|
QGetAdminEventResponse(
|
||||||
event.id,
|
event.id,
|
||||||
event.title,
|
event.title,
|
||||||
event.thumbnailImage,
|
getProcessedUrlExpression(event.thumbnailImage),
|
||||||
event.detailImage,
|
getProcessedUrlExpression(event.detailImage),
|
||||||
event.popupImage,
|
getProcessedUrlExpression(event.popupImage),
|
||||||
getFormattedDate(event.startDate),
|
getFormattedDate(event.startDate),
|
||||||
getFormattedDate(event.endDate),
|
getFormattedDate(event.endDate),
|
||||||
event.link,
|
event.link,
|
||||||
|
@ -58,4 +62,11 @@ class AdminEventBannerQueryRepositoryImpl(
|
||||||
"%Y-%m-%d"
|
"%Y-%m-%d"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getProcessedUrlExpression(path: StringPath): StringExpression {
|
||||||
|
return Expressions.stringTemplate(
|
||||||
|
"CASE WHEN {0} LIKE '$cloudFrontHost%' THEN {0} ELSE CONCAT('$cloudFrontHost', {0}) END",
|
||||||
|
path
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,7 @@ class AdminEventBannerService(
|
||||||
private val s3Uploader: S3Uploader,
|
private val s3Uploader: S3Uploader,
|
||||||
|
|
||||||
@Value("\${cloud.aws.s3.bucket}")
|
@Value("\${cloud.aws.s3.bucket}")
|
||||||
private val bucket: String,
|
private val bucket: String
|
||||||
@Value("\${cloud.aws.cloud-front.host}")
|
|
||||||
private val cloudFrontHost: String
|
|
||||||
) {
|
) {
|
||||||
@Transactional
|
@Transactional
|
||||||
fun save(
|
fun save(
|
||||||
|
@ -201,22 +199,5 @@ class AdminEventBannerService(
|
||||||
|
|
||||||
fun getEventList(): List<GetAdminEventResponse> {
|
fun getEventList(): List<GetAdminEventResponse> {
|
||||||
return repository.getEventList()
|
return repository.getEventList()
|
||||||
.asSequence()
|
|
||||||
.map {
|
|
||||||
if (!it.thumbnailImageUrl.startsWith("https://")) {
|
|
||||||
it.thumbnailImageUrl = "$cloudFrontHost/${it.thumbnailImageUrl}"
|
|
||||||
}
|
|
||||||
|
|
||||||
if (it.detailImageUrl != null && !it.detailImageUrl!!.startsWith("https://")) {
|
|
||||||
it.detailImageUrl = "$cloudFrontHost/${it.detailImageUrl}"
|
|
||||||
}
|
|
||||||
|
|
||||||
if (it.popupImageUrl != null && !it.popupImageUrl!!.startsWith("https://")) {
|
|
||||||
it.popupImageUrl = "$cloudFrontHost/${it.popupImageUrl}"
|
|
||||||
}
|
|
||||||
|
|
||||||
it
|
|
||||||
}
|
|
||||||
.toList()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,11 @@ import com.querydsl.core.annotations.QueryProjection
|
||||||
data class GetAdminEventResponse @QueryProjection constructor(
|
data class GetAdminEventResponse @QueryProjection constructor(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val title: String? = null,
|
val title: String? = null,
|
||||||
var thumbnailImageUrl: String,
|
val thumbnailImageUrl: String,
|
||||||
var detailImageUrl: String? = null,
|
val detailImageUrl: String? = null,
|
||||||
var popupImageUrl: String? = null,
|
val popupImageUrl: String? = null,
|
||||||
var startDate: String,
|
val startDate: String,
|
||||||
var endDate: String,
|
val endDate: String,
|
||||||
val link: String? = null,
|
val link: String? = null,
|
||||||
val isAdult: Boolean? = null,
|
val isAdult: Boolean? = null,
|
||||||
val isPopup: Boolean
|
val isPopup: Boolean
|
||||||
|
|
Loading…
Reference in New Issue