관리자 - 이벤트 배너 서비스
- 이미지 host를 Querydsl 코드에서 추가 - 시작 전인 이벤트도 보이도록 수정
This commit is contained in:
		| @@ -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.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.jpa.impl.JPAQueryFactory | ||||
| import kr.co.vividnext.sodalive.event.Event | ||||
| import kr.co.vividnext.sodalive.event.QEvent.event | ||||
| import org.springframework.beans.factory.annotation.Value | ||||
| import org.springframework.data.jpa.repository.JpaRepository | ||||
| import java.time.LocalDateTime | ||||
|  | ||||
| @@ -16,22 +19,23 @@ interface AdminEventBannerQueryRepository { | ||||
| } | ||||
|  | ||||
| class AdminEventBannerQueryRepositoryImpl( | ||||
|     private val queryFactory: JPAQueryFactory | ||||
|     private val queryFactory: JPAQueryFactory, | ||||
|     @Value("\${cloud.aws.cloud-front.host}") | ||||
|     private val cloudFrontHost: String | ||||
| ) : AdminEventBannerQueryRepository { | ||||
|     override fun getEventList(): List<GetAdminEventResponse> { | ||||
|         val now = LocalDateTime.now() | ||||
|         val where = event.isActive.isTrue | ||||
|             .and(event.startDate.loe(now)) | ||||
|             .and(event.endDate.goe(now)) | ||||
|  | ||||
|         return queryFactory | ||||
|             .select( | ||||
|                 QGetAdminEventResponse( | ||||
|                     event.id, | ||||
|                     event.title, | ||||
|                     event.thumbnailImage, | ||||
|                     event.detailImage, | ||||
|                     event.popupImage, | ||||
|                     getProcessedUrlExpression(event.thumbnailImage), | ||||
|                     getProcessedUrlExpression(event.detailImage), | ||||
|                     getProcessedUrlExpression(event.popupImage), | ||||
|                     getFormattedDate(event.startDate), | ||||
|                     getFormattedDate(event.endDate), | ||||
|                     event.link, | ||||
| @@ -58,4 +62,11 @@ class AdminEventBannerQueryRepositoryImpl( | ||||
|             "%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, | ||||
|  | ||||
|     @Value("\${cloud.aws.s3.bucket}") | ||||
|     private val bucket: String, | ||||
|     @Value("\${cloud.aws.cloud-front.host}") | ||||
|     private val cloudFrontHost: String | ||||
|     private val bucket: String | ||||
| ) { | ||||
|     @Transactional | ||||
|     fun save( | ||||
| @@ -201,22 +199,5 @@ class AdminEventBannerService( | ||||
|  | ||||
|     fun getEventList(): List<GetAdminEventResponse> { | ||||
|         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( | ||||
|     val id: Long, | ||||
|     val title: String? = null, | ||||
|     var thumbnailImageUrl: String, | ||||
|     var detailImageUrl: String? = null, | ||||
|     var popupImageUrl: String? = null, | ||||
|     var startDate: String, | ||||
|     var endDate: String, | ||||
|     val thumbnailImageUrl: String, | ||||
|     val detailImageUrl: String? = null, | ||||
|     val popupImageUrl: String? = null, | ||||
|     val startDate: String, | ||||
|     val endDate: String, | ||||
|     val link: String? = null, | ||||
|     val isAdult: Boolean? = null, | ||||
|     val isPopup: Boolean | ||||
|   | ||||
		Reference in New Issue
	
	Block a user