diff --git a/backend/src/main/java/com/festago/ticket/application/TicketService.java b/backend/src/main/java/com/festago/ticket/application/TicketService.java index 74e72d5f4..fe9424e52 100644 --- a/backend/src/main/java/com/festago/ticket/application/TicketService.java +++ b/backend/src/main/java/com/festago/ticket/application/TicketService.java @@ -46,6 +46,6 @@ private Stage findStageById(Long stageId) { @Transactional(readOnly = true) public StageTicketsResponse findStageTickets(Long stageId) { - return StageTicketsResponse.from(ticketRepository.findAllByStageId(stageId)); + return StageTicketsResponse.from(ticketRepository.findAllByStageIdWithFetch(stageId)); } } diff --git a/backend/src/main/java/com/festago/ticket/repository/TicketRepository.java b/backend/src/main/java/com/festago/ticket/repository/TicketRepository.java index 8c5ab50af..06d15247b 100644 --- a/backend/src/main/java/com/festago/ticket/repository/TicketRepository.java +++ b/backend/src/main/java/com/festago/ticket/repository/TicketRepository.java @@ -11,7 +11,12 @@ public interface TicketRepository extends JpaRepository { - List findAllByStageId(Long stageId); + @Query(""" + SELECT t from Ticket t + INNER JOIN FETCH t.ticketAmount + WHERE t.stage.id = :stageId + """) + List findAllByStageIdWithFetch(@Param("stageId") Long stageId); Optional findByTicketTypeAndStage(TicketType ticketType, Stage stage); diff --git a/backend/src/test/java/com/festago/application/TicketServiceTest.java b/backend/src/test/java/com/festago/application/TicketServiceTest.java index cca7c198a..a6a8a1a6a 100644 --- a/backend/src/test/java/com/festago/application/TicketServiceTest.java +++ b/backend/src/test/java/com/festago/application/TicketServiceTest.java @@ -41,7 +41,7 @@ class TicketServiceTest { TicketFixture.ticket().id(1L).ticketType(TicketType.STUDENT).stage(stage).build(), TicketFixture.ticket().id(2L).ticketType(TicketType.VISITOR).stage(stage).build() ); - given(ticketRepository.findAllByStageId(stageId)) + given(ticketRepository.findAllByStageIdWithFetch(stageId)) .willReturn(tickets); // when diff --git a/backend/src/test/java/com/festago/domain/TicketRepositoryTest.java b/backend/src/test/java/com/festago/domain/TicketRepositoryTest.java index 9c9361b71..22ab05712 100644 --- a/backend/src/test/java/com/festago/domain/TicketRepositoryTest.java +++ b/backend/src/test/java/com/festago/domain/TicketRepositoryTest.java @@ -52,7 +52,7 @@ class TicketRepositoryTest { ticketRepository.save(TicketFixture.ticket().stage(otherStage).build()); // when - List actual = ticketRepository.findAllByStageId(stage.getId()); + List actual = ticketRepository.findAllByStageIdWithFetch(stage.getId()); // then assertThat(actual).hasSize(2);