diff --git a/src/main/java/eatda/controller/cheer/CheerPreviewResponse.java b/src/main/java/eatda/controller/cheer/CheerPreviewResponse.java index fd3c3794..35c37a9c 100644 --- a/src/main/java/eatda/controller/cheer/CheerPreviewResponse.java +++ b/src/main/java/eatda/controller/cheer/CheerPreviewResponse.java @@ -1,7 +1,6 @@ package eatda.controller.cheer; import eatda.domain.cheer.Cheer; -import eatda.domain.store.Store; public record CheerPreviewResponse( long storeId, @@ -11,19 +10,23 @@ public record CheerPreviewResponse( String storeNeighborhood, String storeCategory, long cheerId, - String cheerDescription + String cheerDescription, + long memberId, + String memberNickname ) { - public CheerPreviewResponse(Cheer cheer, Store store, String imageUrl) { + public CheerPreviewResponse(Cheer cheer, String imageUrl) { this( - store.getId(), + cheer.getStore().getId(), imageUrl, - store.getName(), - store.getAddressDistrict(), - store.getAddressNeighborhood(), - store.getCategory().getCategoryName(), + cheer.getStore().getName(), + cheer.getStore().getAddressDistrict(), + cheer.getStore().getAddressNeighborhood(), + cheer.getStore().getCategory().getCategoryName(), cheer.getId(), - cheer.getDescription() + cheer.getDescription(), + cheer.getMember().getId(), + cheer.getMember().getNickname() ); } } diff --git a/src/main/java/eatda/repository/cheer/CheerRepository.java b/src/main/java/eatda/repository/cheer/CheerRepository.java index 8a54de54..ca05a557 100644 --- a/src/main/java/eatda/repository/cheer/CheerRepository.java +++ b/src/main/java/eatda/repository/cheer/CheerRepository.java @@ -7,13 +7,16 @@ import java.util.List; import java.util.Optional; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; public interface CheerRepository extends JpaRepository { + @EntityGraph(attributePaths = {"store", "member"}) List findAllByOrderByCreatedAtDesc(Pageable pageable); + @EntityGraph(attributePaths = {"member"}) List findAllByStoreOrderByCreatedAtDesc(Store store, Pageable pageable); @Query(""" diff --git a/src/main/java/eatda/service/cheer/CheerService.java b/src/main/java/eatda/service/cheer/CheerService.java index 89c06e3e..1ed6d398 100644 --- a/src/main/java/eatda/service/cheer/CheerService.java +++ b/src/main/java/eatda/service/cheer/CheerService.java @@ -71,8 +71,7 @@ public CheersResponse getCheers(int page, int size) { private CheersResponse toCheersResponse(List cheers) { return new CheersResponse(cheers.stream() - .map(cheer -> new CheerPreviewResponse(cheer, cheer.getStore(), - imageStorage.getPreSignedUrl(cheer.getImageKey()))) + .map(cheer -> new CheerPreviewResponse(cheer, imageStorage.getPreSignedUrl(cheer.getImageKey()))) .toList()); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 1f48211b..1aa73914 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -6,6 +6,10 @@ spring: properties: hibernate: format_sql: true + jdbc: + batch_size: 100 + order_inserts: true + order_updates: true defer-datasource-initialization: false open-in-view: false diff --git a/src/test/java/eatda/document/store/CheerDocumentTest.java b/src/test/java/eatda/document/store/CheerDocumentTest.java index 56ec5e99..843751fc 100644 --- a/src/test/java/eatda/document/store/CheerDocumentTest.java +++ b/src/test/java/eatda/document/store/CheerDocumentTest.java @@ -156,7 +156,9 @@ class GetCheers { fieldWithPath("cheers[].storeNeighborhood").type(STRING).description("가게 주소 (동)"), fieldWithPath("cheers[].storeCategory").type(STRING).description("가게 카테고리"), fieldWithPath("cheers[].cheerId").type(NUMBER).description("응원 ID"), - fieldWithPath("cheers[].cheerDescription").type(STRING).description("응원 내용") + fieldWithPath("cheers[].cheerDescription").type(STRING).description("응원 내용"), + fieldWithPath("cheers[].memberId").type(NUMBER).description("응원 작성자 회원 ID"), + fieldWithPath("cheers[].memberNickname").type(STRING).description("응원 작성자 닉네임") ); @Test @@ -165,9 +167,9 @@ class GetCheers { int size = 2; CheersResponse responses = new CheersResponse(List.of( new CheerPreviewResponse(2L, "https://example.image", "농민백암순대 본점", "강남구", "선릉구", "한식", 2L, - "너무 맛있어요!"), + "너무 맛있어요!", 5L, "커찬"), new CheerPreviewResponse(1L, null, "석관동떡볶이", "성북구", "석관동", "기타", 1L, - "너무 매워요! 하지만 맛있어요!") + "너무 매워요! 하지만 맛있어요!", 8L, "찬커") )); doReturn(responses).when(cheerService).getCheers(page, size); diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 322f3ce8..906aa712 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -29,6 +29,10 @@ spring: properties: hibernate: format_sql: true + jdbc: + batch_size: 100 + order_inserts: true + order_updates: true hibernate: ddl-auto: create-drop open-in-view: false