diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index 879f7759..65f34c23 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -132,11 +132,13 @@ public void delete(MemberIdentifier identifier, Long eventId) { } @Transactional - public void decreaseLeftSeat(Long eventId, Integer count) { + public void changeLeftSeat(Long eventId, Integer count) { Event event = getByIdOrThrow(eventId); if (event.getLeftSeat() < count) { throw new NoLeftSeatException("남은 좌석이 부족합니다."); } + if (event.getLeftSeat() > event.getTotalSeat()) + throw new NoLeftSeatException("좌석 관련 알 수 없는 오류"); event.decreaseLeftSeat(count); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java index 050f852d..1d06a319 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java @@ -147,6 +147,6 @@ public void updateFrom(EventEditRequest eventEditRequest, List image } public void decreaseLeftSeat(Integer count) { - this.leftSeat -= count; + this.leftSeat += count; } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java index b3127927..557a22fd 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/application/ReservationService.java @@ -6,19 +6,14 @@ import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.event.application.EventService; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.member.application.MemberService; -import org.ktc2.cokaen.wouldyouin.payment.application.PaymentService; -import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayRequest; -import org.ktc2.cokaen.wouldyouin.payment.dto.KakaoPayResponse; -import org.ktc2.cokaen.wouldyouin.reservation.api.dto.KakaoPayReservationResponse; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationRequest; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationResponse; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationSliceResponse; import org.ktc2.cokaen.wouldyouin.reservation.exception.ReservationNotFoundForReviewException; import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; import org.ktc2.cokaen.wouldyouin.reservation.persist.ReservationRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; @@ -63,8 +58,8 @@ public ReservationResponse create( memberService.getByIdOrThrow(memberId), eventService.getByIdOrThrow(reservationRequest.getEventId())) ); - eventService.decreaseLeftSeat(reservation.getEvent().getId(), - reservationRequest.getQuantity()); + eventService.changeLeftSeat(reservation.getEvent().getId(), + reservationRequest.getQuantity() * -1); return ReservationResponse.from(reservation); } @@ -74,16 +69,16 @@ public ReservationResponse createTest( Reservation reservation = reservationRepository.save(reservationRequest.toEntity( memberService.getByIdOrThrow(identifier.id()), eventService.getByIdOrThrow(reservationRequest.getEventId()))); - eventService.decreaseLeftSeat(reservation.getEvent().getId(), - reservationRequest.getQuantity()); + eventService.changeLeftSeat(reservation.getEvent().getId(), + reservationRequest.getQuantity() * -1); return ReservationResponse.from(reservation); } @Transactional public void delete(MemberIdentifier identifier, Long reservationId) { validateMemberId(identifier.id(), getByIdOrThrow(reservationId)); - eventService.decreaseLeftSeat(-getByIdOrThrow(reservationId).getEvent().getId(), - getByIdOrThrow(reservationId).getQuantity()); + Event event = getByIdOrThrow(reservationId).getEvent(); + eventService.changeLeftSeat(event.getId(), getByIdOrThrow(reservationId).getQuantity()); reservationRepository.deleteById(reservationId); }