관리자 - 이벤트 배너 등록 #93

Merged
klaus merged 1 commits from test into main 2023-11-21 16:21:20 +00:00
3 changed files with 40 additions and 20 deletions

View File

@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.event
import kr.co.vividnext.sodalive.common.ApiResponse
import kr.co.vividnext.sodalive.member.Member
import kr.co.vividnext.sodalive.member.MemberRole
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.DeleteMapping
@ -20,7 +21,17 @@ class EventController(private val service: EventService) {
@GetMapping
fun getEventList(
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = ApiResponse.ok(service.getEventList(member?.auth != null))
) = run {
ApiResponse.ok(
service.getEventList(
if (member?.role == MemberRole.ADMIN) {
null
} else {
member?.auth != null
}
)
)
}
@GetMapping("/popup")
fun getEventPopup(
@ -35,9 +46,10 @@ class EventController(private val service: EventService) {
@RequestParam(value = "popup", required = false) popup: MultipartFile? = null,
@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
) = ApiResponse.ok(
service.save(thumbnail, detail, popup, link, title, isPopup),
service.save(thumbnail, detail, popup, link, title, isAdult, isPopup),
"등록되었습니다."
)
@ -50,9 +62,10 @@ class EventController(private val service: EventService) {
@RequestParam(value = "popup", required = false) popup: MultipartFile? = null,
@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
) = ApiResponse.ok(
service.update(id, thumbnail, detail, popup, link, title, isPopup),
service.update(id, thumbnail, detail, popup, link, title, isAdult, isPopup),
"수정되었습니다."
)

View File

@ -9,25 +9,27 @@ import org.springframework.stereotype.Repository
interface EventRepository : JpaRepository<Event, Long>, EventQueryRepository
interface EventQueryRepository {
fun getEventList(isAdult: Boolean): List<EventItem>
fun getEventList(isAdult: Boolean? = null): List<EventItem>
fun getMainEventPopup(isAdult: Boolean): EventItem?
}
@Repository
class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : EventQueryRepository {
override fun getEventList(isAdult: Boolean): 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)
)
if (isAdult != null) {
where = if (isAdult) {
where.and(
event.isAdult.isNull
.or(event.isAdult.isTrue)
)
} else {
where.and(
event.isAdult.isNull
.or(event.isAdult.isFalse)
)
}
}
return queryFactory

View File

@ -20,7 +20,8 @@ class EventService(
@Value("\${cloud.aws.cloud-front.host}")
private val cloudFrontHost: String
) {
fun getEventList(isAdult: Boolean): GetEventResponse {
@Transactional(readOnly = true)
fun getEventList(isAdult: Boolean? = null): GetEventResponse {
val eventList = repository.getEventList(isAdult)
.asSequence()
.map {
@ -43,6 +44,7 @@ class EventService(
return GetEventResponse(0, eventList)
}
@Transactional(readOnly = true)
fun getEventPopup(isAdult: Boolean): EventItem? {
val eventPopup = repository.getMainEventPopup(isAdult)
@ -70,6 +72,7 @@ class EventService(
popup: MultipartFile? = null,
link: String? = null,
title: String? = null,
isAdult: Boolean? = null,
isPopup: Boolean
): Long {
if (detail == null && link.isNullOrBlank()) throw SodaException("상세이미지 혹은 링크를 등록하세요")
@ -81,6 +84,7 @@ class EventService(
popupImage = null,
link = link,
title = title,
isAdult = isAdult,
isPopup = isPopup
)
)
@ -137,14 +141,11 @@ class EventService(
popup: MultipartFile? = null,
link: String? = null,
title: String? = null,
isAdult: Boolean? = null,
isPopup: Boolean? = null
) {
if (id <= 0) throw SodaException("잘못된 요청입니다.")
if (thumbnail == null && detail == null && link.isNullOrBlank() && title.isNullOrBlank()) {
throw SodaException("수정할 내용을 입력하세요.")
}
val event = repository.findByIdOrNull(id)
?: throw SodaException("잘못된 요청입니다.")
@ -192,6 +193,10 @@ class EventService(
if (isPopup != null) {
event.isPopup = isPopup
}
if (isAdult != event.isAdult) {
event.isAdult = isAdult
}
}
@Transactional