@@ -71,24 +71,28 @@ public ReservationResponse getReservation(Member member, Long reservationId) {
7171
7272 @ Transactional
7373 public ReservationResponse createReservation (Mentee mentee , ReservationRequest reqDto ) {
74- Mentoring mentoring = mentoringStorage .findMentoring (reqDto .mentoringId ());
75- MentorSlot mentorSlot = mentoringStorage .findMentorSlot (reqDto .mentorSlotId ());
74+ try {
75+ Mentoring mentoring = mentoringStorage .findMentoring (reqDto .mentoringId ());
76+ MentorSlot mentorSlot = mentoringStorage .findMentorSlot (reqDto .mentorSlotId ());
7677
77- DateTimeValidator .validateStartTimeNotInPast (mentorSlot .getStartDateTime ());
78- validateMentorSlotStatus (mentorSlot , mentee );
79- validateOverlappingTimeForMentee (mentee , mentorSlot );
78+ DateTimeValidator .validateStartTimeNotInPast (mentorSlot .getStartDateTime ());
79+ validateMentorSlotStatus (mentorSlot , mentee );
80+ validateOverlappingTimeForMentee (mentee , mentorSlot );
8081
81- Reservation reservation = Reservation .builder ()
82- .mentoring (mentoring )
83- .mentee (mentee )
84- .mentorSlot (mentorSlot )
85- .preQuestion (reqDto .preQuestion ())
86- .build ();
87- reservationRepository .save (reservation );
82+ Reservation reservation = Reservation .builder ()
83+ .mentoring (mentoring )
84+ .mentee (mentee )
85+ .mentorSlot (mentorSlot )
86+ .preQuestion (reqDto .preQuestion ())
87+ .build ();
88+ reservationRepository .save (reservation );
8889
89- mentorSlot .updateStatus (MentorSlotStatus .PENDING );
90+ mentorSlot .updateStatus (MentorSlotStatus .PENDING );
9091
91- return ReservationResponse .from (reservation );
92+ return ReservationResponse .from (reservation );
93+ } catch (OptimisticLockException e ) {
94+ throw new ServiceException (ReservationErrorCode .CONCURRENT_RESERVATION_CONFLICT );
95+ }
9296 }
9397
9498 @ Transactional
0 commit comments