From 9fa1b2c3e5d47a03477da66fcea0b251dcaab772 Mon Sep 17 00:00:00 2001 From: yunseul Date: Sun, 11 Aug 2024 23:33:44 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[Refactor]=20reservationEntity=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/CreateExchangeApprovalService.java | 1 + .../application/service/CreateExchangeOfferService.java | 8 +++++--- .../adapter/out/persistence/SaveReservationAdapter.java | 6 ++++-- .../com/gamja/tiggle/reservation/domain/Reservation.java | 4 ++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gamja/tiggle/exchange/application/service/CreateExchangeApprovalService.java b/src/main/java/com/gamja/tiggle/exchange/application/service/CreateExchangeApprovalService.java index 051918b..4782cd8 100644 --- a/src/main/java/com/gamja/tiggle/exchange/application/service/CreateExchangeApprovalService.java +++ b/src/main/java/com/gamja/tiggle/exchange/application/service/CreateExchangeApprovalService.java @@ -79,6 +79,7 @@ public static Reservation updateReservation(ReservationEntity reservation) { .ticketNumber(reservation.getTicketNumber()) .totalPrice(reservation.getTotalPrice()) .status(ReservationType.EXCHANGED) + .available(reservation.isAvailable()) .requestLimit(reservation.getRequestLimit()).build(); } diff --git a/src/main/java/com/gamja/tiggle/exchange/application/service/CreateExchangeOfferService.java b/src/main/java/com/gamja/tiggle/exchange/application/service/CreateExchangeOfferService.java index 6347c9e..4bda810 100644 --- a/src/main/java/com/gamja/tiggle/exchange/application/service/CreateExchangeOfferService.java +++ b/src/main/java/com/gamja/tiggle/exchange/application/service/CreateExchangeOfferService.java @@ -40,10 +40,10 @@ public void create(CreateExchangeOfferCommand command) throws BaseException { if (exchangePort.find(command)) throw new BaseException(BaseResponseStatus.EXIST_EXCHANGE_OFFER); - if(reservation1.getRequestLimit()<1) - throw new BaseException(BaseResponseStatus.NOT_REMAIN_EXCHANGE_OFFER); + if (reservation1.getRequestLimit() < 1) + throw new BaseException(BaseResponseStatus.NOT_REMAIN_EXCHANGE_OFFER); - if(Objects.equals(reservation1.getUser().getId(), reservation2.getUser().getId())) + if (Objects.equals(reservation1.getUser().getId(), reservation2.getUser().getId())) throw new BaseException(BaseResponseStatus.WRONG_EXCHANGE_OFFER); if (!Objects.equals(reservation1.getProgramEntity().getId(), reservation2.getProgramEntity().getId()) || !Objects.equals(reservation1.getTimesEntity().getId(), reservation2.getTimesEntity().getId())) @@ -77,6 +77,8 @@ public void create(CreateExchangeOfferCommand command) throws BaseException { .ticketNumber(reservation1.getTicketNumber()) .totalPrice(reservation1.getTotalPrice()) .status(reservation1.getStatus()) + .paymentId(reservation1.getPaymentEntity().getId()) + .available(reservation1.isAvailable()) .requestLimit(reservation1.getRequestLimit() - 1).build()); } diff --git a/src/main/java/com/gamja/tiggle/reservation/adapter/out/persistence/SaveReservationAdapter.java b/src/main/java/com/gamja/tiggle/reservation/adapter/out/persistence/SaveReservationAdapter.java index ee3fcc2..9056481 100644 --- a/src/main/java/com/gamja/tiggle/reservation/adapter/out/persistence/SaveReservationAdapter.java +++ b/src/main/java/com/gamja/tiggle/reservation/adapter/out/persistence/SaveReservationAdapter.java @@ -51,14 +51,16 @@ public void update(Reservation reservation) { private static ReservationEntity updateFrom(Reservation reservation) { return ReservationEntity.builder() .id(reservation.getId()) - .user(new UserEntity(reservation.getId())) .programEntity(new ProgramEntity(reservation.getProgramId())) - .timesEntity(new TimesEntity(reservation.getTimesId())) + .user(new UserEntity(reservation.getUserId())) .seatEntity(new SeatEntity(reservation.getSeatId())) + .timesEntity(new TimesEntity(reservation.getTimesId())) .ticketNumber(reservation.getTicketNumber()) .totalPrice(reservation.getTotalPrice()) .requestLimit(reservation.getRequestLimit()) .status(reservation.getStatus()) + .available(reservation.getAvailable()) + .payType(reservation.getPayType()) .build(); } } diff --git a/src/main/java/com/gamja/tiggle/reservation/domain/Reservation.java b/src/main/java/com/gamja/tiggle/reservation/domain/Reservation.java index d5644ac..162c0d0 100644 --- a/src/main/java/com/gamja/tiggle/reservation/domain/Reservation.java +++ b/src/main/java/com/gamja/tiggle/reservation/domain/Reservation.java @@ -23,6 +23,7 @@ public class Reservation { private Long timesId; private Long sectionId; private Long locationId; + private Long paymentId; private String ticketNumber; private Integer totalPrice; @@ -30,9 +31,12 @@ public class Reservation { @Enumerated(EnumType.STRING) private ReservationType status; + private Boolean available; + private Integer requestLimit; private Integer refund; + // 예매 받아올 값 private String programInfo; // 공연 정보 @Enumerated(EnumType.STRING) From 0f12df6b6e2a5fb7c4bc68690ee6992498d07164 Mon Sep 17 00:00:00 2001 From: yunseul Date: Sun, 11 Aug 2024 23:46:58 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[Refactor]=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20api=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/in/web/GetSeatController.java | 19 ---------- .../out/persistence/getSeatAdapter.java | 8 ---- .../repositroy/SeatRepository.java | 22 ----------- .../application/port/in/GetSeatUseCase.java | 2 - .../application/port/out/GetSeatPort.java | 2 - .../application/service/GetSeatService.java | 37 ------------------- 6 files changed, 90 deletions(-) diff --git a/src/main/java/com/gamja/tiggle/reservation/adapter/in/web/GetSeatController.java b/src/main/java/com/gamja/tiggle/reservation/adapter/in/web/GetSeatController.java index c3f9275..4b2922c 100644 --- a/src/main/java/com/gamja/tiggle/reservation/adapter/in/web/GetSeatController.java +++ b/src/main/java/com/gamja/tiggle/reservation/adapter/in/web/GetSeatController.java @@ -53,23 +53,6 @@ public BaseResponse>> getAllSeat( } @PostMapping("/exchange") - @Operation(summary = "교환 가능 좌석 조회", description = "특정 공연의 교환 가능 좌석을 조회하는 API 입니다.") - public BaseResponse>> getAllSeatEnableExchange( - @RequestBody GetAllSeatRequest request, - @AuthenticationPrincipal CustomUserDetails customUserDetails) throws BaseException { - - List> AllSeatResponse; - try { - List> allSeat = getSeatUseCase.getAllSeatWithEnableExchange(toAllSeatCommand(request,customUserDetails.getUser())); - AllSeatResponse = getAllSeatResponse(allSeat); - } catch (BaseException e) { - return new BaseResponse<>(e.getStatus()); - } - return new BaseResponse<>(AllSeatResponse); - - } - - @PostMapping("/available/exchange") @Operation(summary = "교환 가능 좌석 조회", description = "교환 가능 좌석을 조회하는 API 입니다.") public BaseResponse>> getAvailableExchange( @RequestBody GetAllSeatRequest request, @@ -87,8 +70,6 @@ public BaseResponse>> getAvailableEx - - @PostMapping @Operation(summary = "예약 가능 좌석 조회", description = "특정 공연의 예약 가능 좌석을 조회하는 API 입니다.") public BaseResponse> getAvailableSeat( diff --git a/src/main/java/com/gamja/tiggle/reservation/adapter/out/persistence/getSeatAdapter.java b/src/main/java/com/gamja/tiggle/reservation/adapter/out/persistence/getSeatAdapter.java index e0f409e..ffd8710 100644 --- a/src/main/java/com/gamja/tiggle/reservation/adapter/out/persistence/getSeatAdapter.java +++ b/src/main/java/com/gamja/tiggle/reservation/adapter/out/persistence/getSeatAdapter.java @@ -127,14 +127,6 @@ public List getAllSeatWithEnable(Long programId, Long sectionId, Long time return getSeatList(allSeat); } - @Override - public List getAllSeatWithEnableExchange(Long programId, Long sectionId, Long timesId) throws BaseException { - - List allSeat - = seatRepository.findAllSeatEnableExchange(programId, timesId, sectionId); - return getSeatList(allSeat); - } - @Override public List getAvailableExchang(Long programId, Long sectionId, Long timesId, Long userId) { List allSeat diff --git a/src/main/java/com/gamja/tiggle/reservation/adapter/out/persistence/repositroy/SeatRepository.java b/src/main/java/com/gamja/tiggle/reservation/adapter/out/persistence/repositroy/SeatRepository.java index 4d264d3..d1fd5b2 100644 --- a/src/main/java/com/gamja/tiggle/reservation/adapter/out/persistence/repositroy/SeatRepository.java +++ b/src/main/java/com/gamja/tiggle/reservation/adapter/out/persistence/repositroy/SeatRepository.java @@ -43,28 +43,6 @@ List findAllSeat(@Param("programId") Long programI @Param("sectionId") Long sectionId); - @Query("SELECT NEW com.gamja.tiggle.reservation.adapter.out.persistence.Response.GetAllSeatPersistentResponse(" + - "s.id, s.row, s.seatNumber, s.active, " + - "CASE " + - "WHEN r.status = 'COMPLETED' OR r.status = 'EXCHANGED' THEN TRUE ELSE FALSE " + - "END)" + - "FROM SeatEntity s " + - "LEFT JOIN ReservationEntity r ON s.id = r.seatEntity.id " + - "AND r.programEntity.id = :programId " + - "AND r.timesEntity.id = :timesId " + - "AND COALESCE(r.modifiedAt, r.createdAt) = ( " + - " SELECT MAX(COALESCE(r2.modifiedAt, r2.createdAt)) " + - " FROM ReservationEntity r2 " + - " WHERE r2.seatEntity.id = r.seatEntity.id " + - " AND r2.programEntity.id = :programId " + - " AND r2.timesEntity.id = :timesId) " + - "WHERE s.sectionEntity.id = :sectionId " + - "ORDER BY s.row, s.seatNumber") - List findAllSeatEnableExchange(@Param("programId") Long programId, - @Param("timesId") Long timesId, - @Param("sectionId") Long sectionId); - - //예약 가능 좌석만 조회 @Query("SELECT new com.gamja.tiggle.reservation.adapter.out.persistence.Response" + ".GetAvailableSeatResponse(s.id, s.sectionEntity.id, s.seatNumber, s.row) " + diff --git a/src/main/java/com/gamja/tiggle/reservation/application/port/in/GetSeatUseCase.java b/src/main/java/com/gamja/tiggle/reservation/application/port/in/GetSeatUseCase.java index 894bd5f..2ba6327 100644 --- a/src/main/java/com/gamja/tiggle/reservation/application/port/in/GetSeatUseCase.java +++ b/src/main/java/com/gamja/tiggle/reservation/application/port/in/GetSeatUseCase.java @@ -12,7 +12,5 @@ public interface GetSeatUseCase { List> getAllSeatWithEnable(GetAllSeatCommand command) throws BaseException; - List> getAllSeatWithEnableExchange(GetAllSeatCommand command) throws BaseException; - List> getAvailableExchangeSeat(GetAllSeatCommand command) throws BaseException; } diff --git a/src/main/java/com/gamja/tiggle/reservation/application/port/out/GetSeatPort.java b/src/main/java/com/gamja/tiggle/reservation/application/port/out/GetSeatPort.java index 367549f..f59f135 100644 --- a/src/main/java/com/gamja/tiggle/reservation/application/port/out/GetSeatPort.java +++ b/src/main/java/com/gamja/tiggle/reservation/application/port/out/GetSeatPort.java @@ -14,7 +14,5 @@ public interface GetSeatPort { List getAllSeatWithEnable(Long programId, Long sectionId, Long timesId) throws BaseException; - List getAllSeatWithEnableExchange(Long programId, Long sectionId, Long timesId) throws BaseException; - List getAvailableExchang(Long programId, Long sectionId, Long timesId, Long userId); } diff --git a/src/main/java/com/gamja/tiggle/reservation/application/service/GetSeatService.java b/src/main/java/com/gamja/tiggle/reservation/application/service/GetSeatService.java index 1eb8a85..907ae60 100644 --- a/src/main/java/com/gamja/tiggle/reservation/application/service/GetSeatService.java +++ b/src/main/java/com/gamja/tiggle/reservation/application/service/GetSeatService.java @@ -117,42 +117,6 @@ public List> getAllSeatWithEnable(GetAllSeatCommand command) throws B return ArraySeat; } - @Override - public List> getAllSeatWithEnableExchange(GetAllSeatCommand command) throws BaseException { - - List allSeat = getSeatPort.getAllSeatWithEnableExchange(command.getProgramId(), - command.getSectionId(), command.getTimesId() - ); - userPersistencePort.existUser(command.getUserId()); - Long locationId = programPort.getLocationId(command.getProgramId()); - programPort.existProgram(command.getProgramId()); - timesPort.verifyTimes(command.getTimesId(), command.getProgramId()); - sectionPort.correctSection(command.getSectionId(), locationId); - - Section section = sectionPort.getRowColumn(command.getSectionId()); - int rowCount = section.getRowCount(); - int columnCount = section.getColumnCount(); - List> ArraySeat = new ArrayList<>(); - - for (int i = 0; i < rowCount; i++) { - ArraySeat.add(new ArrayList<>(Collections.nCopies(columnCount, null))); - } - - for (Seat seat : allSeat) { - int rowIndex = seat.getRow().charAt(0) - 'A'; - int colIndex = seat.getSeatNumber() - 1; - - if (colIndex >= columnCount) throw new BaseException(BaseResponseStatus.NOT_MATCH_ROW); - - if (rowIndex >= rowCount) throw new BaseException(BaseResponseStatus.NOT_MATCH_COLUMN); - - ArraySeat.get(rowIndex).set(colIndex, seat); - } - - - return ArraySeat; - } - @Override public List> getAvailableExchangeSeat(GetAllSeatCommand command) throws BaseException { List allSeat = getSeatPort.getAvailableExchang(command.getProgramId(), @@ -185,7 +149,6 @@ public List> getAvailableExchangeSeat(GetAllSeatCommand command) thro ArraySeat.get(rowIndex).set(colIndex, seat); } - return ArraySeat; }