From 7f42f5fac25c75a0275d9ccf60689db0432e079d Mon Sep 17 00:00:00 2001 From: HyeonjaeKwon Date: Wed, 27 Sep 2023 16:59:59 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=94=BC=EB=93=9C=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20order=20=EC=88=9C=EC=9C=BC=EB=A1=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #670 --- .../feed/application/FeedQueryService.java | 8 +++++++- .../feed/application/FeedQueryServiceTest.java | 18 +++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/backend/emm-sale/src/main/java/com/emmsale/feed/application/FeedQueryService.java b/backend/emm-sale/src/main/java/com/emmsale/feed/application/FeedQueryService.java index f2f2772e3..2d1552eb1 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/feed/application/FeedQueryService.java +++ b/backend/emm-sale/src/main/java/com/emmsale/feed/application/FeedQueryService.java @@ -18,6 +18,7 @@ import com.emmsale.image.domain.repository.ImageRepository; import com.emmsale.member.domain.Member; import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -64,7 +65,7 @@ public FeedListResponse findAllFeeds(final Member member, final Long eventId) { } private Map> getFeedImagesMap(final List feedIds) { - return imageRepository.findAllByFeedIdIn(feedIds).stream() + final Map> feedImagesMap = imageRepository.findAllByFeedIdIn(feedIds).stream() .collect(Collectors.groupingBy( Image::getContentId, Collectors.mapping( @@ -72,6 +73,10 @@ private Map> getFeedImagesMap(final List feedIds) { Collectors.toList() ) )); + + feedImagesMap.forEach((feedId, images) -> images.sort(Comparator.comparing(Image::getOrder))); + + return feedImagesMap; } private Map getFeedIdCommentCountMap(final List feedIds) { @@ -104,6 +109,7 @@ public FeedDetailResponse findFeed(final Member member, final Long id) { final Feed feed = feedRepository.findById(id) .orElseThrow(() -> new FeedException(FeedExceptionType.NOT_FOUND_FEED)); final List images = imageRepository.findAllByFeedId(feed.getId()); + images.sort(Comparator.comparing(Image::getOrder)); validateBlockedMemberFeed(member, feed); validateDeletedFeed(feed); diff --git a/backend/emm-sale/src/test/java/com/emmsale/feed/application/FeedQueryServiceTest.java b/backend/emm-sale/src/test/java/com/emmsale/feed/application/FeedQueryServiceTest.java index 33ef6cd9f..ea72b0454 100644 --- a/backend/emm-sale/src/test/java/com/emmsale/feed/application/FeedQueryServiceTest.java +++ b/backend/emm-sale/src/test/java/com/emmsale/feed/application/FeedQueryServiceTest.java @@ -234,19 +234,23 @@ void findFeedWithDeletedFeedIdTest() { @DisplayName("피드 이미지 조회 테스트") class FeedQueryWithImage { + private Image image1; + private Image image2; + private Image image3; private List images; @BeforeEach void setUp() { - images = imageRepository.saveAll(List.of( - new Image("image-uuid", ImageType.FEED, feed1.getId(), 1, LocalDateTime.now()), - new Image("image-uuid", ImageType.FEED, feed1.getId(), 2, LocalDateTime.now()) - ) - ); + image1 = new Image("image-uuid1", ImageType.FEED, feed1.getId(), 1, LocalDateTime.now()); + image2 = new Image("image-uuid2", ImageType.FEED, feed1.getId(), 2, LocalDateTime.now()); + image3 = new Image("image-uuid3", ImageType.FEED, feed1.getId(), 3, LocalDateTime.now()); + images = List.of(image1, image2, image3); + + imageRepository.saveAll(List.of(image2, image1, image3)); } @Test - @DisplayName("피드에 이미지가 있을 경우 피드 목록에서 이미지 리스트를 함께 반환한다.") + @DisplayName("피드에 이미지가 있을 경우 피드 목록에서 이미지 리스트를 order순으로 정렬하여 함께 반환한다.") void findAllFeedsWithImages() { //given final Long eventId = event.getId(); @@ -268,7 +272,7 @@ void findAllFeedsWithImages() { } @Test - @DisplayName("피드에 이미지가 있을 경우 피드 목록에서 이미지 리스트를 함께 반환한다.") + @DisplayName("피드에 이미지가 있을 경우 피드 목록에서 이미지 리스트를 order순으로 정렬하여 함께 반환한다.") void findDetailFeedWithImages() { //given final FeedDetailResponse expect = FeedDetailResponse.from(feed1, images);