Compare commits

..

No commits in common. "0c01aeec5009b5558bd77c44ff4f534cda39b91d" and "892206744dbea54f8ab2d4556260a7ce8dc7a506" have entirely different histories.

3 changed files with 20 additions and 40 deletions

View File

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

View File

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

View File

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