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
21 changes: 12 additions & 9 deletions src/main/java/eatda/controller/cheer/CheerPreviewResponse.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package eatda.controller.cheer;

import eatda.domain.cheer.Cheer;
import eatda.domain.store.Store;

public record CheerPreviewResponse(
long storeId,
Expand All @@ -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()
);
}
}
3 changes: 3 additions & 0 deletions src/main/java/eatda/repository/cheer/CheerRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cheer, Long> {

@EntityGraph(attributePaths = {"store", "member"})
List<Cheer> findAllByOrderByCreatedAtDesc(Pageable pageable);

@EntityGraph(attributePaths = {"member"})
List<Cheer> findAllByStoreOrderByCreatedAtDesc(Store store, Pageable pageable);

@Query("""
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/eatda/service/cheer/CheerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public CheersResponse getCheers(int page, int size) {

private CheersResponse toCheersResponse(List<Cheer> 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());
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions src/test/java/eatda/document/store/CheerDocumentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down