Skip to content

Commit

Permalink
[Feat] ReservationRepository에서 사용자 정보를 통한 예매내역을 count하는 adpater 구현 #142
Browse files Browse the repository at this point in the history
  • Loading branch information
ashd89 committed Aug 8, 2024
1 parent 20b6be8 commit 45840b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
@RequiredArgsConstructor
public class ReadReservationPersistenceAdapter implements ReadReservationPort {

private final ReservationRepository repository;
private final ReservationRepository reservationRepository;

@Override
public ReservationEntity read(Long reservationId) throws BaseException {
return repository.findById(reservationId).orElseThrow(() -> new BaseException(BaseResponseStatus.NOT_FOUND_RESERVATION));
return reservationRepository.findById(reservationId).orElseThrow(() -> new BaseException(BaseResponseStatus.NOT_FOUND_RESERVATION));
}

@Override
public Reservation readReservation(Reservation reservation) throws BaseException {
ReservationEntity result = repository.findReservationWithDetails(reservation.getId());
ReservationEntity result = reservationRepository.findReservationWithDetails(reservation.getId());
List<String> imageFiles = result.getProgramEntity().getProgramImageEntities().stream()
.map(programImageEntity -> programImageEntity.getImgUrl())
.collect(Collectors.toList());
Expand Down Expand Up @@ -63,7 +63,7 @@ public List<Reservation> myRead(ReadReservationCommand command) throws BaseExcep
int page = command.getPage();
int size = command.getSize();
Pageable pageable = PageRequest.of(page, size);
Page<ReservationEntity> result = repository.findReservationsByUserId(command.getUser().getId(), pageable);
Page<ReservationEntity> result = reservationRepository.findReservationsByUserId(command.getUser().getId(), pageable);

List<Reservation> reservations = result.stream()
.filter(r -> ReservationType.COMPLETED.equals(r.getStatus()))
Expand Down Expand Up @@ -95,4 +95,9 @@ public List<Reservation> myRead(ReadReservationCommand command) throws BaseExcep

return reservations;
}

@Override
public Long getReservationCnt(Long userid) throws BaseException {
return reservationRepository.countReservationsByUserId(userid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ public interface ReservationRepository extends JpaRepository<ReservationEntity,
"JOIN FETCH r.user u " +
"WHERE u.id = :userId")
Page<ReservationEntity> findReservationsByUserId(@Param("userId") Long userId, Pageable pageable);


@Query("SELECT COUNT(r) FROM ReservationEntity r " +
"JOIN r.user u " +
"WHERE u.id = :userId")
Long countReservationsByUserId(@Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public interface ReadReservationPort {
ReservationEntity read(Long reservationId) throws BaseException;
Reservation readReservation(Reservation reservation) throws BaseException;
List<Reservation> myRead(ReadReservationCommand command) throws BaseException;
Long getReservationCnt(Long userid) throws BaseException;
}

0 comments on commit 45840b2

Please sign in to comment.