Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daolove0323 committed Nov 19, 2024
1 parent 4401bca commit 08560c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,6 @@ public void updateFrom(EventEditRequest eventEditRequest, List<EventImage> image
}

public void decreaseLeftSeat(Integer count) {
this.leftSeat -= count;
this.leftSeat += count;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down

0 comments on commit 08560c5

Please sign in to comment.