ratempty / online-reservation

0 stars 0 forks source link

피드백 - 정현우 튜터 #1

Open Nuung opened 6 months ago

Nuung commented 6 months ago

안녕하세요 다빈님!! 매번 새로운 도전과제가 생겨서 쉽지않음에도 잘 해주시고 계셔서 좋습니다!! 🔥🔥🔥

이미지

전체 과제 체크 사항

필수 기능 구현 리스트

보너스 기능 구현 리스트


세부 피드백

user

show

https://github.com/ratempty/online-reservation/blob/2d005f5e4caf65412628f21dcb6b3855868f74ed/src/shows/shows.controller.ts#L33-L39

https://github.com/ratempty/online-reservation/blob/2d005f5e4caf65412628f21dcb6b3855868f74ed/src/shows/shows.service.ts#L25-L47

reservations


    // 좌석 조회와 예약 가능 여부 확인
    const seats = await this.seatRepository.findBy({
      showId: showId,
      seatNum: seatNum.seats,
    });

    if (seats.length !== seatNum.seats.length || seats.some(seat => !seat.canBook)) {
      throw new Error('일부 좌석이 예약 불가능합니다.');
    }

    const show = await this.showRepository.findOneBy({ id: showId });
    if (!show) {
      throw new Error('공연을 찾을 수 없습니다.');
    }

    const currentPoint = await this.pointRepository
      .createQueryBuilder('point')
      .select('SUM(point.point)', 'sum')
      .where('point.userId = :userId', { userId })
      .getRawOne();

    if (currentPoint.sum < show.price * seats.length) {
      throw new Error('보유 포인트 부족!');
    }

마무리 첨언

Nuung commented 6 months ago

[ 동시성 처리하기 ]

(1) 가장 쉽게 처리하는 방법은 query builder 를 호출하셔서 DBMS 에서 트랜잭션을 하는 것

(2) DBMS 의 Lock 을 활용하는 것