From 889490f0d0dc37d087e4280afdb474894b4cb5ba Mon Sep 17 00:00:00 2001 From: hyerinhwang-sailin Date: Tue, 3 Dec 2024 21:45:25 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[feat]=20#278=20-=20=ED=8B=B0=EC=BC=93=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20api=20=EB=B3=80=EA=B2=BD=20(#281)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [#278] feat(TicketApi): RequestParam 자료형 수정 * [#278] feat(TicketController): RequestParam 자료형 수정 * [#278] feat(TicketService): RequestParam 자료형 변경에 따른 코드 수정 * [#278] feat(TicketRepository): RequestParam 자료형 변경에 따른 쿼리문 수정 * [#278] rename: 변수 네이밍 변경 --- .../beat/domain/booking/api/TicketApi.java | 10 +++-- .../domain/booking/api/TicketController.java | 20 ++++----- .../booking/application/TicketService.java | 41 ++++++++++++------- .../domain/booking/dao/TicketRepository.java | 27 ++++++------ 4 files changed, 57 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/beat/domain/booking/api/TicketApi.java b/src/main/java/com/beat/domain/booking/api/TicketApi.java index 62aecf4..e3d3d58 100644 --- a/src/main/java/com/beat/domain/booking/api/TicketApi.java +++ b/src/main/java/com/beat/domain/booking/api/TicketApi.java @@ -1,5 +1,7 @@ package com.beat.domain.booking.api; +import java.util.List; + import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -52,8 +54,8 @@ public interface TicketApi { ResponseEntity> getTickets( @CurrentMember Long memberId, @PathVariable Long performanceId, - @RequestParam(required = false) ScheduleNumber scheduleNumber, - @RequestParam(required = false) BookingStatus bookingStatus + @RequestParam(required = false) List scheduleNumbers, + @RequestParam(required = false) List bookingStatuses ); @Operation(summary = "예매자 목록 검색 API", description = "메이커가 자신의 공연에 대한 예매자 목록을 검색하는 GET API입니다.") @@ -84,8 +86,8 @@ ResponseEntity> searchTickets( @CurrentMember Long memberId, @PathVariable Long performanceId, @RequestParam String searchWord, - @RequestParam(required = false) ScheduleNumber scheduleNumber, - @RequestParam(required = false) BookingStatus bookingStatus + @RequestParam(required = false) List scheduleNumbers, + @RequestParam(required = false) List bookingStatuses ); @Operation(summary = "예매자 입금여부 수정 및 웹발신 API", description = "메이커가 자신의 공연에 대한 예매자의 입금여부 정보를 수정한 뒤 예매확정 웹발신을 보내는 PUT API입니다.") diff --git a/src/main/java/com/beat/domain/booking/api/TicketController.java b/src/main/java/com/beat/domain/booking/api/TicketController.java index 87d61c5..37c59d9 100644 --- a/src/main/java/com/beat/domain/booking/api/TicketController.java +++ b/src/main/java/com/beat/domain/booking/api/TicketController.java @@ -1,5 +1,7 @@ package com.beat.domain.booking.api; +import java.util.List; + import org.springframework.http.CacheControl; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -37,14 +39,13 @@ public class TicketController implements TicketApi { public ResponseEntity> getTickets( @CurrentMember Long memberId, @PathVariable Long performanceId, - @RequestParam(required = false) ScheduleNumber scheduleNumber, - @RequestParam(required = false) BookingStatus bookingStatus) { - if (bookingStatus == BookingStatus.BOOKING_DELETED) { + @RequestParam(required = false) List scheduleNumbers, + @RequestParam(required = false) List bookingStatuses) { + if (bookingStatuses != null && bookingStatuses.contains(BookingStatus.BOOKING_DELETED)) { throw new BadRequestException(TicketErrorCode.DELETED_TICKET_RETRIEVE_NOT_ALLOWED); } TicketRetrieveResponse response = ticketService.findAllTicketsByConditions(memberId, performanceId, - scheduleNumber, - bookingStatus); + scheduleNumbers, bookingStatuses); return ResponseEntity.ok(SuccessResponse.of(TicketSuccessCode.TICKET_RETRIEVE_SUCCESS, response)); } @@ -54,18 +55,17 @@ public ResponseEntity> searchTickets( @CurrentMember Long memberId, @PathVariable Long performanceId, @RequestParam String searchWord, - @RequestParam(required = false) ScheduleNumber scheduleNumber, - @RequestParam(required = false) BookingStatus bookingStatus) { + @RequestParam(required = false) List scheduleNumbers, + @RequestParam(required = false) List bookingStatuses) { if (searchWord.length() < 2) { throw new BadRequestException(TicketErrorCode.SEARCH_WORD_TOO_SHORT); } - if (bookingStatus == BookingStatus.BOOKING_DELETED) { + if (bookingStatuses != null && bookingStatuses.contains(BookingStatus.BOOKING_DELETED)) { throw new BadRequestException(TicketErrorCode.DELETED_TICKET_RETRIEVE_NOT_ALLOWED); } TicketRetrieveResponse response = ticketService.searchAllTicketsByConditions(memberId, performanceId, - searchWord, - scheduleNumber, bookingStatus); + searchWord, scheduleNumbers, bookingStatuses); return ResponseEntity.ok() .cacheControl(CacheControl.noCache()) .body(SuccessResponse.of(TicketSuccessCode.TICKET_SEARCH_SUCCESS, response)); diff --git a/src/main/java/com/beat/domain/booking/application/TicketService.java b/src/main/java/com/beat/domain/booking/application/TicketService.java index 9d0173f..a6d180c 100644 --- a/src/main/java/com/beat/domain/booking/application/TicketService.java +++ b/src/main/java/com/beat/domain/booking/application/TicketService.java @@ -1,6 +1,7 @@ package com.beat.domain.booking.application; import java.time.LocalDateTime; +import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -56,49 +57,61 @@ public class TicketService { private final CoolSmsService coolSmsService; public TicketRetrieveResponse findAllTicketsByConditions(Long memberId, Long performanceId, - ScheduleNumber scheduleNumber, - BookingStatus bookingStatus) { + List scheduleNumbers, List bookingStatuses) { Member member = findMember(memberId); Users user = findUser(member); Performance performance = findPerformance(performanceId); performance.validatePerformanceOwnership(user.getId()); - List schedules = scheduleRepository.findAllByPerformanceId(performanceId); + List schedules = scheduleRepository.findAllByPerformanceId(performanceId); int totalPerformanceTicketCount = calculateTotalTicketCount(schedules); int totalPerformanceSoldTicketCount = calculateTotalSoldTicketCount(schedules); - List bookings = ticketRepository.findBookings(performanceId, scheduleNumber, bookingStatus); + List bookings = ticketRepository.findBookings(performanceId, scheduleNumbers, bookingStatuses); return findTicketRetrieveResponse(performance, totalPerformanceTicketCount, totalPerformanceSoldTicketCount, bookings); } public TicketRetrieveResponse searchAllTicketsByConditions(Long memberId, Long performanceId, String searchWord, - ScheduleNumber scheduleNumber, BookingStatus bookingStatus) { + List scheduleNumbers, List bookingStatuses) { Member member = findMember(memberId); Users user = findUser(member); Performance performance = findPerformance(performanceId); performance.validatePerformanceOwnership(user.getId()); - List schedules = scheduleRepository.findAllByPerformanceId(performanceId); + List schedules = scheduleRepository.findAllByPerformanceId(performanceId); int totalPerformanceTicketCount = calculateTotalTicketCount(schedules); int totalPerformanceSoldTicketCount = calculateTotalSoldTicketCount(schedules); - String scheduleNumberValue = null; - if (scheduleNumber != null) { - scheduleNumberValue = scheduleNumber.name(); + List selectedScheduleNumbers = schedules.stream() + .map(schedule -> schedule.getScheduleNumber().name()) + .toList(); + + List selectedBookingStatuses = Arrays.asList( + BookingStatus.CHECKING_PAYMENT.name(), + BookingStatus.BOOKING_CONFIRMED.name(), + BookingStatus.BOOKING_CANCELLED.name(), + BookingStatus.REFUND_REQUESTED.name() + ); + + if (scheduleNumbers != null && !scheduleNumbers.isEmpty()) { + selectedScheduleNumbers = scheduleNumbers.stream() + .map(Enum::name) + .toList(); } - String bookingStatusValue = null; - if (bookingStatus != null) { - bookingStatusValue = bookingStatus.name(); + if (bookingStatuses != null && !bookingStatuses.isEmpty()) { + selectedBookingStatuses = bookingStatuses.stream() + .map(Enum::name) + .toList(); } List bookings = ticketRepository.searchBookings( performanceId, searchWord, - scheduleNumberValue, - bookingStatusValue + selectedScheduleNumbers, + selectedBookingStatuses ); log.info("searchTickets result: {}", bookings); diff --git a/src/main/java/com/beat/domain/booking/dao/TicketRepository.java b/src/main/java/com/beat/domain/booking/dao/TicketRepository.java index c05cb86..0c0f803 100644 --- a/src/main/java/com/beat/domain/booking/dao/TicketRepository.java +++ b/src/main/java/com/beat/domain/booking/dao/TicketRepository.java @@ -15,8 +15,8 @@ public interface TicketRepository extends JpaRepository { @Query("SELECT b FROM Booking b " + "WHERE b.schedule.performance.id = :performanceId " + "AND b.bookingStatus != com.beat.domain.booking.domain.BookingStatus.BOOKING_DELETED " + - "AND (:scheduleNumber IS NULL OR b.schedule.scheduleNumber = :scheduleNumber) " + - "AND (:bookingStatus IS NULL OR b.bookingStatus = :bookingStatus) " + + "AND (:scheduleNumbers IS NULL OR b.schedule.scheduleNumber IN :scheduleNumbers) " + + "AND (:bookingStatuses IS NULL OR b.bookingStatus IN :bookingStatuses) " + "ORDER BY CASE b.bookingStatus " + " WHEN com.beat.domain.booking.domain.BookingStatus.REFUND_REQUESTED THEN 1 " + " WHEN com.beat.domain.booking.domain.BookingStatus.CHECKING_PAYMENT THEN 2 " + @@ -26,8 +26,8 @@ public interface TicketRepository extends JpaRepository { " b.createdAt DESC") List findBookings( @Param("performanceId") Long performanceId, - @Param("scheduleNumber") ScheduleNumber scheduleNumber, - @Param("bookingStatus") BookingStatus bookingStatus); + @Param("scheduleNumbers") List scheduleNumbers, + @Param("bookingStatuses") List bookingStatuses); List findByBookingStatusAndCancellationDateBefore(BookingStatus bookingStatus, LocalDateTime cancellationDate); @@ -37,23 +37,24 @@ List findByBookingStatusAndCancellationDateBefore(BookingStatus booking FROM booking b JOIN schedule s ON b.schedule_id = s.id WHERE s.performance_id = :performanceId - AND b.booking_status != 'BOOKING_DELETED' - AND (:scheduleNumber IS NULL OR s.schedule_number = :scheduleNumber) - AND(:bookingStatus IS NULL OR b.booking_status = :bookingStatus) - AND MATCH(b.booker_name) AGAINST(:searchWord IN BOOLEAN MODE) + AND b.booking_status != 'BOOKING_DELETED' + AND (s.schedule_number IN (:selectedScheduleNumbers)) + AND (b.booking_status IN (:selectedBookingStatuses)) + AND MATCH(b.booker_name) AGAINST(:searchWord IN BOOLEAN MODE) ORDER BY - CASE b.booking_status + CASE b.booking_status WHEN 'REFUND_REQUESTED' THEN 1 WHEN 'CHECKING_PAYMENT' THEN 2 WHEN 'BOOKING_CONFIRMED' THEN 3 WHEN 'BOOKING_CANCELLED' THEN 4 - END ASC, - b.created_at DESC + END ASC, + b.created_at DESC """, nativeQuery = true) List searchBookings( @Param("performanceId") Long performanceId, @Param("searchWord") String searchWord, - @Param("scheduleNumber") String scheduleNumber, - @Param("bookingStatus") String bookingStatus); + @Param("selectedScheduleNumbers") List selectedScheduleNumbers, + @Param("selectedBookingStatuses") List selectedBookingStatuses + ); } From 1bc15207767f22b87e5812b017f1c501f081faff Mon Sep 17 00:00:00 2001 From: DongHoon Lee <125895298+hoonyworld@users.noreply.github.com> Date: Tue, 3 Dec 2024 22:19:36 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[#282]=20fix:=20=EA=B7=B8=EB=A3=B9=ED=99=94?= =?UTF-8?q?=EB=A5=BC=20=EC=BD=94=EB=93=9C=20=EA=B8=B0=EB=B0=98=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20(#283)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/swagger/config/SwaggerConfig.java | 20 +++++++++++++++++++ src/main/resources/application-dev.yml | 7 +------ src/main/resources/application-prod.yml | 7 +------ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/beat/global/swagger/config/SwaggerConfig.java b/src/main/java/com/beat/global/swagger/config/SwaggerConfig.java index 0a30742..fe4e57a 100644 --- a/src/main/java/com/beat/global/swagger/config/SwaggerConfig.java +++ b/src/main/java/com/beat/global/swagger/config/SwaggerConfig.java @@ -10,6 +10,7 @@ import io.swagger.v3.oas.models.servers.Server; import org.springdoc.core.customizers.OperationCustomizer; +import org.springdoc.core.models.GroupedOpenApi; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -41,6 +42,25 @@ public OpenAPI openAPI() { .addSecurityItem(securityRequirement); } + @Bean + public GroupedOpenApi generalApi() { + return GroupedOpenApi.builder() + .group("general") + .pathsToMatch("/**") + .pathsToExclude("/api/admin/**") + .addOperationCustomizer(customize()) + .build(); + } + + @Bean + public GroupedOpenApi adminApi() { + return GroupedOpenApi.builder() + .group("admin") + .pathsToMatch("/api/admin/**") + .addOperationCustomizer(customize()) + .build(); + } + @Bean public OperationCustomizer customize() { return (operation, handlerMethod) -> { diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index bbf1bb1..5d5151a 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -86,13 +86,8 @@ springdoc: use-fqn: false default-consumes-media-type: application/json;charset=UTF-8 default-produces-media-type: application/json;charset=UTF-8 - group-configs: - - group: admin - paths-to-match: /api/admin/** - - group: general - paths-to-match: /** - paths-to-exclude: /api/admin/** swagger-ui: tags-sorter: alpha operations-sorter: alpha display-request-duration: true + urls-primary-name: general diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 0a57539..4b18549 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -86,13 +86,8 @@ springdoc: use-fqn: false default-consumes-media-type: application/json;charset=UTF-8 default-produces-media-type: application/json;charset=UTF-8 - group-configs: - - group: admin - paths-to-match: /api/admin/** - - group: general - paths-to-match: /** - paths-to-exclude: /api/admin/** swagger-ui: tags-sorter: alpha operations-sorter: alpha display-request-duration: true + urls-primary-name: general