Skip to content

Commit

Permalink
[DDING-000] Feed thumbnail 조회 버그 수정 (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
KoSeonJe authored Jan 12, 2025
1 parent 329b585 commit 8f75593
Showing 1 changed file with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ClubFeedPageQuery getFeedPageByClub(Long clubId, int size, Long currentCu
Slice<Feed> feedPage = feedService.getFeedPageByClubId(clubId, size, currentCursorId);
List<Feed> feeds = feedPage.getContent();

List<FeedListQuery> feedListQueries = buildFeedListQuery(feeds);
List<FeedListQuery> feedListQueries = feeds.stream().map(this::extractFeedThumbnailInfo).toList();
PagingQuery pagingQuery = PagingQuery.of(currentCursorId, feeds.get(feeds.size() -1).getId(), feedPage.hasNext());

return ClubFeedPageQuery.of(feedListQueries, pagingQuery);
Expand All @@ -45,7 +45,7 @@ public NewestFeedPerClubPageQuery getNewestFeedPerClubPage(int size, Long curren
Slice<Feed> feedPage = feedService.getNewestFeedPerClubPage(size, currentCursorId);
List<Feed> feeds = feedPage.getContent();

List<FeedListQuery> feedListQueries = buildFeedListQuery(feeds);
List<FeedListQuery> feedListQueries = feeds.stream().map(this::extractFeedThumbnailInfo).toList();
PagingQuery pagingQuery = PagingQuery.of(currentCursorId, feeds.get(feeds.size() -1).getId(), feedPage.hasNext());

return NewestFeedPerClubPageQuery.of(feedListQueries, pagingQuery);
Expand All @@ -58,6 +58,21 @@ public FeedQuery getById(Long feedId) {
return FeedQuery.of(feed, clubProfileQuery, feedFileUrlQuery);
}

private FeedListQuery extractFeedThumbnailInfo(Feed feed) {
FileMetaData fileMetaData = getFileMetaData(feed.getFeedType().getDomainType(), feed.getId());
if (feed.isImage()) {
UploadedFileUrlQuery urlQuery = s3FileService.getUploadedFileUrl(fileMetaData.getFileKey());
return new FeedListQuery(feed.getId(), urlQuery.cdnUrl(), urlQuery.originUrl(), feed.getFeedType().name());
}

if (feed.isVideo()) {
UploadedVideoUrlQuery urlQuery = s3FileService.getUploadedVideoUrl(fileMetaData.getFileKey());
return new FeedListQuery(feed.getId(), urlQuery.thumbnailCdnUrl(), urlQuery.thumbnailOriginUrl(), feed.getFeedType().name());
}

throw new IllegalArgumentException("FeedType은 Image 혹은 Video여야 합니다.");
}

private FeedFileUrlQuery extractFeedFileInfo(Feed feed) {
FileMetaData fileMetaData = getFileMetaData(feed.getFeedType().getDomainType(), feed.getId());
if (feed.isImage()) {
Expand Down Expand Up @@ -86,14 +101,4 @@ private FileMetaData getFileMetaData(DomainType domainType, Long id) {
.findFirst()
.orElseThrow(() -> new ResourceNotFound("해당 FileMetaData(feedId: " + id + ")를 찾을 수 없습니다.)"));
}

private List<FeedListQuery> buildFeedListQuery(List<Feed> feeds) {
return feeds.stream()
.map(feed -> {
FileMetaData fileMetaData = getFileMetaData(feed.getFeedType().getDomainType(), feed.getId());
UploadedVideoUrlQuery urlQuery = s3FileService.getUploadedVideoUrl(fileMetaData.getFileKey());
return FeedListQuery.of(feed, urlQuery);
}).toList();
}

}

0 comments on commit 8f75593

Please sign in to comment.