Merge pull request '관리자 - 이벤트 배너 등록' (#93) from test into main
Reviewed-on: #93
This commit is contained in:
		| @@ -2,6 +2,7 @@ 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 | ||||||
| @@ -20,7 +21,17 @@ 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? | ||||||
|     ) = ApiResponse.ok(service.getEventList(member?.auth != null)) |     ) = run { | ||||||
|  |         ApiResponse.ok( | ||||||
|  |             service.getEventList( | ||||||
|  |                 if (member?.role == MemberRole.ADMIN) { | ||||||
|  |                     null | ||||||
|  |                 } else { | ||||||
|  |                     member?.auth != null | ||||||
|  |                 } | ||||||
|  |             ) | ||||||
|  |         ) | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @GetMapping("/popup") |     @GetMapping("/popup") | ||||||
|     fun getEventPopup( |     fun getEventPopup( | ||||||
| @@ -35,9 +46,10 @@ 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, 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 = "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, isPopup), |         service.update(id, thumbnail, detail, popup, link, title, isAdult, isPopup), | ||||||
|         "수정되었습니다." |         "수정되었습니다." | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -9,15 +9,16 @@ 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): List<EventItem> |     fun getEventList(isAdult: Boolean? = null): 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 | ||||||
| @@ -29,6 +30,7 @@ class EventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Even | |||||||
|                         .or(event.isAdult.isFalse) |                         .or(event.isAdult.isFalse) | ||||||
|                 ) |                 ) | ||||||
|             } |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|         return queryFactory |         return queryFactory | ||||||
|             .select( |             .select( | ||||||
|   | |||||||
| @@ -20,7 +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(isAdult: Boolean): GetEventResponse { |     @Transactional(readOnly = true) | ||||||
|  |     fun getEventList(isAdult: Boolean? = null): GetEventResponse { | ||||||
|         val eventList = repository.getEventList(isAdult) |         val eventList = repository.getEventList(isAdult) | ||||||
|             .asSequence() |             .asSequence() | ||||||
|             .map { |             .map { | ||||||
| @@ -43,6 +44,7 @@ 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) | ||||||
|  |  | ||||||
| @@ -70,6 +72,7 @@ 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("상세이미지 혹은 링크를 등록하세요") | ||||||
| @@ -81,6 +84,7 @@ class EventService( | |||||||
|                 popupImage = null, |                 popupImage = null, | ||||||
|                 link = link, |                 link = link, | ||||||
|                 title = title, |                 title = title, | ||||||
|  |                 isAdult = isAdult, | ||||||
|                 isPopup = isPopup |                 isPopup = isPopup | ||||||
|             ) |             ) | ||||||
|         ) |         ) | ||||||
| @@ -137,14 +141,11 @@ 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("잘못된 요청입니다.") | ||||||
|  |  | ||||||
| @@ -192,6 +193,10 @@ class EventService( | |||||||
|         if (isPopup != null) { |         if (isPopup != null) { | ||||||
|             event.isPopup = isPopup |             event.isPopup = isPopup | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         if (isAdult != event.isAdult) { | ||||||
|  |             event.isAdult = isAdult | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Transactional |     @Transactional | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user