Skip to content

Commit

Permalink
Merge pull request #165 from beyond-sw-camp/fix/exchange/offer
Browse files Browse the repository at this point in the history
[Refactor] 교환 기능의 로직 수정 #164
  • Loading branch information
Aqulog authored Aug 11, 2024
2 parents 1a5c306 + 8dd602f commit b70ef43
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,6 @@ public BaseResponse<List<List<GetAllSeatResponse>>> getAllSeat(
}

@PostMapping("/exchange")
@Operation(summary = "교환 가능 좌석 조회", description = "특정 공연의 교환 가능 좌석을 조회하는 API 입니다.")
public BaseResponse<List<List<GetAllSeatResponse>>> getAllSeatEnableExchange(
@RequestBody GetAllSeatRequest request,
@AuthenticationPrincipal CustomUserDetails customUserDetails) throws BaseException {

List<List<GetAllSeatResponse>> AllSeatResponse;
try {
List<List<Seat>> 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<List<List<GetAvailableExchangeSeatResponse>>> getAvailableExchange(
@RequestBody GetAllSeatRequest request,
Expand All @@ -87,8 +70,6 @@ public BaseResponse<List<List<GetAvailableExchangeSeatResponse>>> getAvailableEx





@PostMapping
@Operation(summary = "예약 가능 좌석 조회", description = "특정 공연의 예약 가능 좌석을 조회하는 API 입니다.")
public BaseResponse<List<GetAvailableSeatResponse>> getAvailableSeat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,6 @@ public List<Seat> getAllSeatWithEnable(Long programId, Long sectionId, Long time
return getSeatList(allSeat);
}

@Override
public List<Seat> getAllSeatWithEnableExchange(Long programId, Long sectionId, Long timesId) throws BaseException {

List<GetAllSeatPersistentResponse> allSeat
= seatRepository.findAllSeatEnableExchange(programId, timesId, sectionId);
return getSeatList(allSeat);
}

@Override
public List<Seat> getAvailableExchang(Long programId, Long sectionId, Long timesId, Long userId) {
List<GetAvailableExchangeSeatPersistenceResponse> allSeat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,6 @@ List<GetAllSeatPersistentResponse> 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<GetAllSeatPersistentResponse> 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) " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ public interface GetSeatUseCase {

List<List<Seat>> getAllSeatWithEnable(GetAllSeatCommand command) throws BaseException;

List<List<Seat>> getAllSeatWithEnableExchange(GetAllSeatCommand command) throws BaseException;

List<List<Seat>> getAvailableExchangeSeat(GetAllSeatCommand command) throws BaseException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ public interface GetSeatPort {

List<Seat> getAllSeatWithEnable(Long programId, Long sectionId, Long timesId) throws BaseException;

List<Seat> getAllSeatWithEnableExchange(Long programId, Long sectionId, Long timesId) throws BaseException;

List<Seat> getAvailableExchang(Long programId, Long sectionId, Long timesId, Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,42 +117,6 @@ public List<List<Seat>> getAllSeatWithEnable(GetAllSeatCommand command) throws B
return ArraySeat;
}

@Override
public List<List<Seat>> getAllSeatWithEnableExchange(GetAllSeatCommand command) throws BaseException {

List<Seat> 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<List<Seat>> 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<List<Seat>> getAvailableExchangeSeat(GetAllSeatCommand command) throws BaseException {
List<Seat> allSeat = getSeatPort.getAvailableExchang(command.getProgramId(),
Expand Down Expand Up @@ -185,7 +149,6 @@ public List<List<Seat>> getAvailableExchangeSeat(GetAllSeatCommand command) thro
ArraySeat.get(rowIndex).set(colIndex, seat);
}


return ArraySeat;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ public class Reservation {
private Long timesId;
private Long sectionId;
private Long locationId;
private Long paymentId;

private String ticketNumber;
private Integer totalPrice;

@Enumerated(EnumType.STRING)
private ReservationType status;

private Boolean available;

private Integer requestLimit;
private Integer refund;


// 예매 받아올 값
private String programInfo; // 공연 정보
@Enumerated(EnumType.STRING)
Expand Down

0 comments on commit b70ef43

Please sign in to comment.