Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/parkez/payment/service/PaymentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import com.parkez.user.domain.entity.User;
import com.parkez.user.service.UserReader;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class PaymentService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,13 @@ List<Reservation> findExpiredReservations(
);

Optional<Reservation> findByParkingZone_IdAndStartDateTimeAndEndDateTime(Long parkingZoneId, LocalDateTime startDateTime, LocalDateTime endDateTime);
}

@Query("""
SELECT r
FROM Reservation r
JOIN FETCH r.user
JOIN FETCH r.parkingZone
WHERE r.id = :id
""")
Optional<Reservation> findByIdWithUserAndParkingZone(@Param("id") Long reservationId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Page<ReservationWithReviewDto> findMyReservations(Long userId, PageReques

public Reservation findMyReservation(Long userId, Long reservationId) {

Reservation reservation = reservationRepository.findById(reservationId).orElseThrow(
Reservation reservation = reservationRepository.findByIdWithUserAndParkingZone(reservationId).orElseThrow(
() -> new ParkingEasyException(ReservationErrorCode.NOT_FOUND_RESERVATION)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class GetReservationByUserId {

Reservation reservation = createReservation(reservationId, user);

given(reservationRepository.findById(anyLong())).willReturn(Optional.of(reservation));
given(reservationRepository.findByIdWithUserAndParkingZone(anyLong())).willReturn(Optional.of(reservation));

// when
Reservation result = reservationReader.findMyReservation(userId, reservationId);
Expand All @@ -136,8 +136,6 @@ class GetReservationByUserId {
Long userId = 1L;
Long reservationId = -1L;

given(reservationRepository.findById(anyLong())).willReturn(Optional.empty());

// when & then
ParkingEasyException exception = assertThrows(ParkingEasyException.class,
() -> reservationReader.findMyReservation(userId, reservationId));
Expand All @@ -155,7 +153,7 @@ class GetReservationByUserId {

Reservation reservation = createReservation(reservationId, differentUser);

given(reservationRepository.findById(anyLong())).willReturn(Optional.of(reservation));
given(reservationRepository.findByIdWithUserAndParkingZone(anyLong())).willReturn(Optional.of(reservation));

// when & then
ParkingEasyException exception = assertThrows(ParkingEasyException.class,
Expand Down