Skip to content

Commit 842391e

Browse files
authored
Refactor: 예약 상세 조회 시 리뷰 id, 리뷰 작성/수정 가능 여부 포함 (#371)
1 parent da25a8f commit 842391e

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

back/src/main/java/com/back/domain/mentoring/mentoring/repository/ReviewRepository.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.springframework.data.jpa.repository.Query;
88
import org.springframework.data.repository.query.Param;
99

10+
import java.util.Optional;
11+
1012
public interface ReviewRepository extends JpaRepository<Review, Long> {
1113
boolean existsByReservationId(Long reservationId);
1214

@@ -39,4 +41,13 @@ Page<Review> findAllByMentoringId(
3941
@Param("mentoringId") Long mentoringId,
4042
Pageable pageable
4143
);
44+
45+
@Query("""
46+
SELECT r.id
47+
FROM Review r
48+
WHERE r.reservation.id = :reservationId
49+
""")
50+
Optional<Long> findReviewIdByReservationId(
51+
@Param("reservationId") Long reservationId
52+
);
4253
}

back/src/main/java/com/back/domain/mentoring/mentoring/service/MentoringStorage.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.back.domain.mentoring.mentoring.entity.Mentoring;
44
import com.back.domain.mentoring.mentoring.error.MentoringErrorCode;
55
import com.back.domain.mentoring.mentoring.repository.MentoringRepository;
6+
import com.back.domain.mentoring.mentoring.repository.ReviewRepository;
67
import com.back.domain.mentoring.reservation.entity.Reservation;
78
import com.back.domain.mentoring.reservation.error.ReservationErrorCode;
89
import com.back.domain.mentoring.reservation.repository.ReservationRepository;
@@ -30,6 +31,7 @@ public class MentoringStorage {
3031
private final MentorSlotRepository mentorSlotRepository;
3132
private final ReservationRepository reservationRepository;
3233
private final MentoringSessionRepository mentoringSessionRepository;
34+
private final ReviewRepository reviewRepository;
3335

3436
// ===== find 메서드 =====
3537

@@ -56,6 +58,11 @@ public Reservation findReservation(Long reservationId) {
5658
.orElseThrow(() -> new ServiceException(ReservationErrorCode.NOT_FOUND_RESERVATION));
5759
}
5860

61+
public Long findReviewIdByReservationId(Long reservationId) {
62+
return reviewRepository.findReviewIdByReservationId(reservationId)
63+
.orElse(null);
64+
}
65+
5966

6067
// ==== exists 메서드 =====
6168

back/src/main/java/com/back/domain/mentoring/reservation/dto/ReservationDetailDto.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ public record ReservationDetailDto(
2626
LocalDateTime createDate,
2727
@Schema(description = "수정일")
2828
LocalDateTime modifyDate,
29+
2930
@Schema(description = "멘토링 세션 ID")
30-
Long mentoringSessionId
31+
Long mentoringSessionId,
32+
@Schema(description = "리뷰 ID")
33+
Long reviewId,
34+
@Schema(description = "리뷰 가능 여부")
35+
boolean canReview
3136
) {
3237
public static ReservationDetailDto from(Reservation reservation) {
3338
return new ReservationDetailDto(
@@ -39,11 +44,13 @@ public static ReservationDetailDto from(Reservation reservation) {
3944
reservation.getMentorSlot().getEndDateTime(),
4045
reservation.getCreateDate(),
4146
reservation.getModifyDate(),
42-
null
47+
null,
48+
null,
49+
false
4350
);
4451
}
4552

46-
public static ReservationDetailDto from(Reservation reservation, MentoringSession mentoringSession) {
53+
public static ReservationDetailDto from(Reservation reservation, MentoringSession mentoringSession, Long reviewId) {
4754
return new ReservationDetailDto(
4855
reservation.getId(),
4956
reservation.getStatus(),
@@ -53,7 +60,9 @@ public static ReservationDetailDto from(Reservation reservation, MentoringSessio
5360
reservation.getMentorSlot().getEndDateTime(),
5461
reservation.getCreateDate(),
5562
reservation.getModifyDate(),
56-
mentoringSession.getId()
63+
mentoringSession.getId(),
64+
reviewId,
65+
reservation.getStatus().canReview()
5766
);
5867
}
5968
}

back/src/main/java/com/back/domain/mentoring/reservation/dto/response/ReservationResponse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public static ReservationResponse from(Reservation reservation) {
2121
MenteeDto.from(reservation.getMentee())
2222
);
2323
}
24-
public static ReservationResponse from(Reservation reservation, MentoringSession mentoringSession) {
24+
public static ReservationResponse from(Reservation reservation, MentoringSession mentoringSession, Long reviewId) {
2525
return new ReservationResponse(
26-
ReservationDetailDto.from(reservation, mentoringSession),
26+
ReservationDetailDto.from(reservation, mentoringSession, reviewId),
2727
MentoringDto.from(reservation.getMentoring()),
2828
MentorDto.from(reservation.getMentor()),
2929
MenteeDto.from(reservation.getMentee())

back/src/main/java/com/back/domain/mentoring/reservation/service/ReservationService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ public ReservationResponse getReservation(Member member, Long reservationId) {
6262
.orElseThrow(() -> new ServiceException(ReservationErrorCode.RESERVATION_NOT_ACCESSIBLE));
6363

6464
Optional<MentoringSession> mentoringSession = mentoringSessionService.findMentoringSessionByReservation(reservation);
65+
Long reviewId = mentoringStorage.findReviewIdByReservationId(reservationId);
6566

6667
return mentoringSession
67-
.map(session -> ReservationResponse.from(reservation, session))
68+
.map(session -> ReservationResponse.from(reservation, session, reviewId))
6869
.orElseGet(() -> ReservationResponse.from(reservation));
6970
}
7071

@@ -100,7 +101,7 @@ public ReservationResponse approveReservation(Mentor mentor, Long reservationId)
100101

101102
MentoringSession mentoringSession = mentoringSessionService.create(reservation);
102103

103-
return ReservationResponse.from(reservation, mentoringSession);
104+
return ReservationResponse.from(reservation, mentoringSession, null);
104105
} catch (OptimisticLockException e) {
105106
throw new ServiceException(ReservationErrorCode.CONCURRENT_APPROVAL_CONFLICT);
106107
}

0 commit comments

Comments
 (0)