Merge pull request '이벤트 배너, 팝업' (#92) from test into main

Reviewed-on: #92
This commit is contained in:
klaus 2023-11-21 12:59:30 +00:00
commit 892206744d
5 changed files with 53 additions and 16 deletions

View File

@ -16,6 +16,8 @@ data class Event(
var link: String?, var link: String?,
@Column(nullable = true) @Column(nullable = true)
var title: String?, var title: String?,
@Column(nullable = true)
var isAdult: Boolean? = null,
@Column(nullable = false) @Column(nullable = false)
var isPopup: Boolean = false, var isPopup: Boolean = false,
@Column(nullable = false) @Column(nullable = false)

View File

@ -1,7 +1,9 @@
package kr.co.vividnext.sodalive.event package kr.co.vividnext.sodalive.event
import kr.co.vividnext.sodalive.common.ApiResponse import kr.co.vividnext.sodalive.common.ApiResponse
import kr.co.vividnext.sodalive.member.Member
import org.springframework.security.access.prepost.PreAuthorize import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.DeleteMapping import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PathVariable
@ -16,10 +18,14 @@ import org.springframework.web.multipart.MultipartFile
@RequestMapping("/event") @RequestMapping("/event")
class EventController(private val service: EventService) { class EventController(private val service: EventService) {
@GetMapping @GetMapping
fun getEventList() = ApiResponse.ok(service.getEventList()) fun getEventList(
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = ApiResponse.ok(service.getEventList(member?.auth != null))
@GetMapping("/popup") @GetMapping("/popup")
fun getEventPopup() = ApiResponse.ok(service.getEventPopup()) fun getEventPopup(
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = ApiResponse.ok(service.getEventPopup(member?.auth != null))
@PostMapping @PostMapping
@PreAuthorize("hasRole('ADMIN')") @PreAuthorize("hasRole('ADMIN')")

View File

@ -9,13 +9,27 @@ import org.springframework.stereotype.Repository
interface EventRepository : JpaRepository<Event, Long>, EventQueryRepository interface EventRepository : JpaRepository<Event, Long>, EventQueryRepository
interface EventQueryRepository { interface EventQueryRepository {
fun getEventList(): List<EventItem> fun getEventList(isAdult: Boolean): List<EventItem>
fun getMainEventPopup(): EventItem? fun getMainEventPopup(isAdult: Boolean): EventItem?
} }
@Repository @Repository
class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : EventQueryRepository { class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : EventQueryRepository {
override fun getEventList(): List<EventItem> { override fun getEventList(isAdult: Boolean): List<EventItem> {
var where = event.isActive.isTrue
where = if (isAdult) {
where.and(
event.isAdult.isNull
.or(event.isAdult.isTrue)
)
} else {
where.and(
event.isAdult.isNull
.or(event.isAdult.isFalse)
)
}
return queryFactory return queryFactory
.select( .select(
QEventItem( QEventItem(
@ -25,16 +39,33 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even
event.detailImage, event.detailImage,
event.popupImage, event.popupImage,
event.link, event.link,
event.isAdult,
event.isPopup event.isPopup
) )
) )
.from(event) .from(event)
.where(event.isActive.isTrue) .where(where)
.orderBy(event.id.desc()) .orderBy(event.id.desc())
.fetch() .fetch()
} }
override fun getMainEventPopup(): EventItem? { override fun getMainEventPopup(isAdult: Boolean): EventItem? {
var where = event.isActive.isTrue
.and(event.isPopup.isTrue)
.and(event.popupImage.isNotNull)
where = if (isAdult) {
where.and(
event.isAdult.isNull
.or(event.isAdult.isTrue)
)
} else {
where.and(
event.isAdult.isNull
.or(event.isAdult.isFalse)
)
}
return queryFactory return queryFactory
.select( .select(
QEventItem( QEventItem(
@ -44,15 +75,12 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even
event.detailImage, event.detailImage,
event.popupImage, event.popupImage,
event.link, event.link,
event.isAdult,
event.isPopup event.isPopup
) )
) )
.from(event) .from(event)
.where( .where(where)
event.isActive.isTrue
.and(event.isPopup.isTrue)
.and(event.popupImage.isNotNull)
)
.orderBy(event.id.desc()) .orderBy(event.id.desc())
.fetchFirst() .fetchFirst()
} }

View File

@ -20,8 +20,8 @@ class EventService(
@Value("\${cloud.aws.cloud-front.host}") @Value("\${cloud.aws.cloud-front.host}")
private val cloudFrontHost: String private val cloudFrontHost: String
) { ) {
fun getEventList(): GetEventResponse { fun getEventList(isAdult: Boolean): GetEventResponse {
val eventList = repository.getEventList() val eventList = repository.getEventList(isAdult)
.asSequence() .asSequence()
.map { .map {
if (!it.thumbnailImageUrl.startsWith("https://")) { if (!it.thumbnailImageUrl.startsWith("https://")) {
@ -43,8 +43,8 @@ class EventService(
return GetEventResponse(0, eventList) return GetEventResponse(0, eventList)
} }
fun getEventPopup(): EventItem? { fun getEventPopup(isAdult: Boolean): EventItem? {
val eventPopup = repository.getMainEventPopup() val eventPopup = repository.getMainEventPopup(isAdult)
if (eventPopup != null) { if (eventPopup != null) {
if (!eventPopup.thumbnailImageUrl.startsWith("https://")) { if (!eventPopup.thumbnailImageUrl.startsWith("https://")) {

View File

@ -17,5 +17,6 @@ data class EventItem @QueryProjection constructor(
@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("link") val link: String? = null, @JsonProperty("link") val link: String? = null,
@JsonProperty("isAdult") val isAdult: Boolean? = null,
@JsonProperty("isPopup") val isPopup: Boolean @JsonProperty("isPopup") val isPopup: Boolean
) )