Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat#11] 공연 좌석 정보 조회, 공연 좌석 예약 (동시성 해결 X) #15

Merged
merged 10 commits into from
Oct 2, 2021
Prev Previous commit
[fix:#11] 피드백 반영
- 피드백을 반영하여 getIsBooking()메소드에서 seat 정보를 2번 read 하는 작업을 -> 1개로 수정하였습니다. 
- history에 저장되는 메소드 이름을 saveBookingXXXlog(fail,success)통일 시켰습니다.
- insert, update 등이 수행되는 부분에는 @Transcational을 추가하고, 조회하는 경우에는 readOnly를 추가하였습니다.
hyejungg committed Oct 2, 2021
commit 5085387d52f5d9287e58846dc2f09043273ca6b3
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ public Booking saveBookging(final BookingDto reqBooking){
updateSeat(seat, performance, reqBooking);

//seat의 값이 있다면, booking 가능
addBookingHistory(user, performance, seat);
saveBookingSucessLog(user, performance, seat);

//booking 여부 insert
Booking booking = reqBooking.toEntity(user, performance, seat);
@@ -58,7 +58,7 @@ private void updateSeat(final Seat seat, final Performance performance, final Bo
seatService.updateSeat(seatDto);
}

private void addBookingHistory(final User user, final Performance performance, final Seat seat) {
private void saveBookingSucessLog(final User user, final Performance performance, final Seat seat) {
//booking의 성공 여부 history 저장
BookingHistoryDto bookingHistoryDto = BookingHistoryDto.builder()
.user(user)
Original file line number Diff line number Diff line change
@@ -8,8 +8,10 @@
import comento.backend.ticket.dto.*;
import comento.backend.ticket.repository.SeatRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

@@ -23,6 +25,7 @@ public SeatService(SeatRepository seatRepository, BookingHistoryService bookingH
this.bookingHistoryService = bookingHistoryService;
}

@Transactional(readOnly = true)
public List<SeatResponse> getListPerformanceSeat(final PerformanceResponse performanceData) {
Performance performance = new Performance();
performance.setId(performanceData.getId());
@@ -39,26 +42,26 @@ public Seat updateSeat(final SeatDto seatDto) {
}

// @TODO : insert 쿼리도 출력되고, 예외도 발생하지만 BookingHisotry 테이블에 새 데이터 insert가 안된다 ..
@Transactional
public Seat getIsBooking(final User user, final Performance performance, final SeatType seatType, final Integer seatNumber, final boolean isBooking) {
Optional<Seat> seatIsBooking = seatRepository.findByPerformanceAndSeatTypeAndSeatNumberAndIsBooking(performance, seatType, seatNumber, isBooking);
final Seat seat = getSeat(performance, seatType, seatNumber); //seat 번호를 위해서 필요
return seatIsBooking.orElseGet(() -> {
//실패 여부 BookingHistory에 저장
BookingHistoryDto bookingHistoryDto = BookingHistoryDto.builder()
.id(null)
.user(user)
.performance(performance)
.seat(seat)
.isSuccess(false)
.build();
bookingHistoryService.saveBookingHistory(bookingHistoryDto);
//예외 전달
Seat seatIsBooking = seatRepository.findByPerformanceAndSeatTypeAndSeatNumberAndIsBooking(performance, seatType, seatNumber, isBooking)
.orElseGet(()-> null);
if(Objects.isNull(seatIsBooking)){
saveBookingFailLog(user, performance, null);
throw new DuplicatedException("SeatService");
});
}
return seatIsBooking;
}

public Seat getSeat(Performance performance, SeatType seatType, Integer seatNumber) {
Optional<Seat> seat = seatRepository.findByPerformanceAndSeatTypeAndSeatNumber(performance, seatType, seatNumber);
return seat.orElse(seat.get());
private void saveBookingFailLog(final User user, final Performance performance, final Seat seat) {
//실패 여부 BookingHistory에 저장
BookingHistoryDto bookingHistoryDto = BookingHistoryDto.builder()
.id(null)
.user(user)
.performance(performance)
.seat(seat)
.isSuccess(false)
.build();
bookingHistoryService.saveBookingHistory(bookingHistoryDto);
}
}