구현한 기능
- 예약 ID를 통해 특정 예약의 상세 정보를 조회할 수 있는 API 구현
- 권한 검증 기능 추가: 예약 소유자(사용자)와 매장 소유자(파트너)만 조회 가능하도록 설정
- 예약 존재 여부 확인 및 예외 처리
코드 스냅샷
ReservationService.java
@Transactional(readOnly = true)
public ReservationDto.ReservationInfoResponse getReservationDetail(Long reservationId) {
Reservation reservation = reservationRepository.findById(reservationId)
.orElseThrow(() -> new CustomException(ErrorCode.RESERVATION_NOT_FOUND));
return converToReservationInfoResponse(reservation);
}
ReservationController.java
@GetMapping("/{reservationId}")
public ResponseEntity<ApiResponse<ReservationDto.ReservationInfoResponse>> getReservationDetail(
@PathVariable Long reservationId
) {
ReservationDto.ReservationInfoResponse reservation = reservationService.getReservationDetail(reservationId);
String currentUserEmail = authenticationUtil.getCurrentUserEmail();
Long currentUserId = authenticationUtil.getCurrentUserId();
boolean isReservationOwner = reservation.getUserId().equals(currentUserId);
boolean isStorePartner = false;
Collection<? extends GrantedAuthority> authorities = SecurityContextHolder.getContext()
.getAuthentication().getAuthorities();
boolean isPartner = authorities.stream()
.anyMatch(auth -> auth.getAuthority().equals("ROLE_PARTNER"));
if (isPartner) {
Store store = storeRepository.findById(reservation.getStoreId())
.orElseThrow(() -> new CustomException(ErrorCode.STORE_NOT_FOUND));
isStorePartner = store.getPartner().getEmail().equals(currentUserEmail);
}
if (!isReservationOwner && !isStorePartner) {
throw new CustomException(ErrorCode.FORBIDDEN);
}
return ResponseEntity.ok(ApiResponse.success("예약 상세 정보를 성공적으로 조회했습니다.", reservation));
}
Postman 테스트

구현 예정