From bef096e152690169fef4cab47614f0c9e548d4d4 Mon Sep 17 00:00:00 2001 From: Choi Min Young Date: Mon, 11 Nov 2024 22:35:26 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix=20#61=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Carrot/domain/post/repository/PostImageRepository.java | 3 ++- .../land/leets/Carrot/domain/post/service/PostService.java | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/land/leets/Carrot/domain/post/repository/PostImageRepository.java b/src/main/java/land/leets/Carrot/domain/post/repository/PostImageRepository.java index c46e6d0..30734d0 100644 --- a/src/main/java/land/leets/Carrot/domain/post/repository/PostImageRepository.java +++ b/src/main/java/land/leets/Carrot/domain/post/repository/PostImageRepository.java @@ -1,6 +1,7 @@ package land.leets.Carrot.domain.post.repository; import java.util.List; +import java.util.Optional; import land.leets.Carrot.domain.post.entity.PostImage; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -8,5 +9,5 @@ public interface PostImageRepository extends JpaRepository { @Query("SELECT p FROM PostImage p WHERE p.postSnapshot.id = :postsnapshotId") - List findByPostSnapshotId(@Param("postsnapshotId") Long postsnapshotId); + Optional> findByPostSnapshotId(@Param("postsnapshotId") Long postsnapshotId); } diff --git a/src/main/java/land/leets/Carrot/domain/post/service/PostService.java b/src/main/java/land/leets/Carrot/domain/post/service/PostService.java index 32f8468..3b98ff0 100644 --- a/src/main/java/land/leets/Carrot/domain/post/service/PostService.java +++ b/src/main/java/land/leets/Carrot/domain/post/service/PostService.java @@ -253,7 +253,7 @@ public ResponseDto getAppliedList(Long userId) { .filter(postSnapshot -> postSnapshot.getPost().getPostId() == apply.getPost().getPostId()) .map(postSnapshot -> new AppliedPost(apply.getPost().getPostId(), postSnapshot.getTitle(), postSnapshot.getPost().getStoreName(), - postImageRepository.findByPostSnapshotId(postSnapshot.getId()).get(0).getImageUrl(), + getFirstImageUrl(postSnapshot.getId()), apply.isRecruited(), postSnapshot.getPost().getStatus().equals("done")))) .collect(Collectors.toList()); @@ -265,7 +265,10 @@ public ResponseDto getAppliedList(Long userId) { private String getFirstImageUrl(Long postSnapshotId) { - return postImageRepository.findByPostSnapshotId(postSnapshotId).get(0).getImageUrl(); + return postImageRepository.findByPostSnapshotId(postSnapshotId) + .filter(list -> !list.isEmpty()) + .map(list -> list.get(0).getImageUrl()) + .orElse(null); } From ebb5a8eee9023559aaf928d1adb3bd3e9c633fc5 Mon Sep 17 00:00:00 2001 From: Choi Min Young Date: Mon, 11 Nov 2024 22:36:08 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix=20#61=20=EC=97=B0=EA=B3=84=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../land/leets/Carrot/domain/post/service/PostService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/land/leets/Carrot/domain/post/service/PostService.java b/src/main/java/land/leets/Carrot/domain/post/service/PostService.java index 3b98ff0..49505f3 100644 --- a/src/main/java/land/leets/Carrot/domain/post/service/PostService.java +++ b/src/main/java/land/leets/Carrot/domain/post/service/PostService.java @@ -155,8 +155,11 @@ public ResponseDto getDetailPost(Long postId) { .orElseThrow(() -> new PostException(LATEST_SNAPSHOT_NOT_FOUND)); List imageList = postImageRepository.findByPostSnapshotId(postSnapshot.getId()) - .stream() - .map(image -> image.getImageUrl()).collect(Collectors.toList()); + .filter(list -> !list.isEmpty()) + .map(list -> list.stream() + .map(imageRow -> imageRow.getImageUrl()) + .collect(Collectors.toList())) + .orElse(null); String workType = getWorkTypeName(postSnapshot.getWorkTypeId()); PostResponse postResponse = new PostResponse(postId, post.getCeo().getId(), post.getStoreName(),