Merge pull request '이벤트 배너, 팝업' (#92) from test into main
Reviewed-on: #92
This commit is contained in:
commit
892206744d
|
@ -16,6 +16,8 @@ data class Event(
|
|||
var link: String?,
|
||||
@Column(nullable = true)
|
||||
var title: String?,
|
||||
@Column(nullable = true)
|
||||
var isAdult: Boolean? = null,
|
||||
@Column(nullable = false)
|
||||
var isPopup: Boolean = false,
|
||||
@Column(nullable = false)
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package kr.co.vividnext.sodalive.event
|
||||
|
||||
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.core.annotation.AuthenticationPrincipal
|
||||
import org.springframework.web.bind.annotation.DeleteMapping
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
|
@ -16,10 +18,14 @@ import org.springframework.web.multipart.MultipartFile
|
|||
@RequestMapping("/event")
|
||||
class EventController(private val service: EventService) {
|
||||
@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")
|
||||
fun getEventPopup() = ApiResponse.ok(service.getEventPopup())
|
||||
fun getEventPopup(
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = ApiResponse.ok(service.getEventPopup(member?.auth != null))
|
||||
|
||||
@PostMapping
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
|
|
|
@ -9,13 +9,27 @@ import org.springframework.stereotype.Repository
|
|||
interface EventRepository : JpaRepository<Event, Long>, EventQueryRepository
|
||||
|
||||
interface EventQueryRepository {
|
||||
fun getEventList(): List<EventItem>
|
||||
fun getMainEventPopup(): EventItem?
|
||||
fun getEventList(isAdult: Boolean): List<EventItem>
|
||||
fun getMainEventPopup(isAdult: Boolean): EventItem?
|
||||
}
|
||||
|
||||
@Repository
|
||||
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
|
||||
.select(
|
||||
QEventItem(
|
||||
|
@ -25,16 +39,33 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even
|
|||
event.detailImage,
|
||||
event.popupImage,
|
||||
event.link,
|
||||
event.isAdult,
|
||||
event.isPopup
|
||||
)
|
||||
)
|
||||
.from(event)
|
||||
.where(event.isActive.isTrue)
|
||||
.where(where)
|
||||
.orderBy(event.id.desc())
|
||||
.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
|
||||
.select(
|
||||
QEventItem(
|
||||
|
@ -44,15 +75,12 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even
|
|||
event.detailImage,
|
||||
event.popupImage,
|
||||
event.link,
|
||||
event.isAdult,
|
||||
event.isPopup
|
||||
)
|
||||
)
|
||||
.from(event)
|
||||
.where(
|
||||
event.isActive.isTrue
|
||||
.and(event.isPopup.isTrue)
|
||||
.and(event.popupImage.isNotNull)
|
||||
)
|
||||
.where(where)
|
||||
.orderBy(event.id.desc())
|
||||
.fetchFirst()
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ class EventService(
|
|||
@Value("\${cloud.aws.cloud-front.host}")
|
||||
private val cloudFrontHost: String
|
||||
) {
|
||||
fun getEventList(): GetEventResponse {
|
||||
val eventList = repository.getEventList()
|
||||
fun getEventList(isAdult: Boolean): GetEventResponse {
|
||||
val eventList = repository.getEventList(isAdult)
|
||||
.asSequence()
|
||||
.map {
|
||||
if (!it.thumbnailImageUrl.startsWith("https://")) {
|
||||
|
@ -43,8 +43,8 @@ class EventService(
|
|||
return GetEventResponse(0, eventList)
|
||||
}
|
||||
|
||||
fun getEventPopup(): EventItem? {
|
||||
val eventPopup = repository.getMainEventPopup()
|
||||
fun getEventPopup(isAdult: Boolean): EventItem? {
|
||||
val eventPopup = repository.getMainEventPopup(isAdult)
|
||||
|
||||
if (eventPopup != null) {
|
||||
if (!eventPopup.thumbnailImageUrl.startsWith("https://")) {
|
||||
|
|
|
@ -17,5 +17,6 @@ data class EventItem @QueryProjection constructor(
|
|||
@JsonProperty("detailImageUrl") var detailImageUrl: String? = null,
|
||||
@JsonProperty("popupImageUrl") var popupImageUrl: String? = null,
|
||||
@JsonProperty("link") val link: String? = null,
|
||||
@JsonProperty("isAdult") val isAdult: Boolean? = null,
|
||||
@JsonProperty("isPopup") val isPopup: Boolean
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue