diff --git a/back/src/main/java/com/back/domain/mentoring/reservation/service/ReservationService.java b/back/src/main/java/com/back/domain/mentoring/reservation/service/ReservationService.java index 659db6e0..1a2772b9 100644 --- a/back/src/main/java/com/back/domain/mentoring/reservation/service/ReservationService.java +++ b/back/src/main/java/com/back/domain/mentoring/reservation/service/ReservationService.java @@ -56,9 +56,11 @@ public ReservationResponse getReservation(Member member, Long reservationId) { Reservation reservation = reservationRepository.findByIdAndMember(reservationId, member.getId()) .orElseThrow(() -> new ServiceException(ReservationErrorCode.RESERVATION_NOT_ACCESSIBLE)); - MentoringSession mentoringSession = mentoringSessionService.getMentoringSessionByReservation(reservation); + Optional mentoringSession = mentoringSessionService.findMentoringSessionByReservation(reservation); - return ReservationResponse.from(reservation, mentoringSession); + return mentoringSession + .map(session -> ReservationResponse.from(reservation, session)) + .orElseGet(() -> ReservationResponse.from(reservation)); } @Transactional diff --git a/back/src/main/java/com/back/domain/mentoring/session/service/MentoringSessionService.java b/back/src/main/java/com/back/domain/mentoring/session/service/MentoringSessionService.java index 3d457e2e..e91bd799 100644 --- a/back/src/main/java/com/back/domain/mentoring/session/service/MentoringSessionService.java +++ b/back/src/main/java/com/back/domain/mentoring/session/service/MentoringSessionService.java @@ -8,6 +8,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.Optional; + @Service @RequiredArgsConstructor public class MentoringSessionService { @@ -28,6 +30,10 @@ public MentoringSession getMentoringSessionByReservation(Reservation reservation .orElseThrow(() -> new ServiceException("404", "해당 예약의 세션이 없습니다.")); } + public Optional findMentoringSessionByReservation(Reservation reservation) { + return mentoringSessionRepository.findByReservation((reservation)); + } + public MentoringSession getMentoringSessionByMentoring(Mentoring mentoring) { return mentoringSessionRepository.findByMentoring(mentoring) .orElseThrow(() -> new ServiceException("404", "해당 멘토링의 세션이 없습니다.")); diff --git a/back/src/test/java/com/back/domain/mentoring/reservation/service/ReservationServiceTest.java b/back/src/test/java/com/back/domain/mentoring/reservation/service/ReservationServiceTest.java index 891ac7d2..bfa2820e 100644 --- a/back/src/test/java/com/back/domain/mentoring/reservation/service/ReservationServiceTest.java +++ b/back/src/test/java/com/back/domain/mentoring/reservation/service/ReservationServiceTest.java @@ -135,7 +135,7 @@ void getReservation() { when(reservationRepository.findByIdAndMember(reservationId, mentor.getMember().getId())) .thenReturn(Optional.of(reservation)); MentoringSession session = MentoringSessionFixture.create(reservation); - when(mentoringSessionService.getMentoringSessionByReservation(reservation)).thenReturn(session); + when(mentoringSessionService.findMentoringSessionByReservation(reservation)).thenReturn(Optional.ofNullable(session)); // when ReservationResponse response = reservationService.getReservation(