Skip to content

Commit a27625d

Browse files
authored
feat(): 커뮤니티, 프로필 조회, 알림 목록 조회 api 각각에도 썸네일 url 추가 (#215)
* feat: 커뮤니티 응답에도 썸네일 url 추가 * test: 커뮤니티 테스트 수정 * feat(user): 다른 유저의 프로필 조회 시, 컬렉션 썸네일 url 필드 포함 * feat: 알림 목록 조회 페이로드에 담긴 이미지 url도 썸네일로 변경
1 parent 313e82c commit a27625d

8 files changed

Lines changed: 25 additions & 5 deletions

File tree

src/main/java/org/devkor/apu/saerok_server/domain/collection/application/helper/CollectionImageUrlService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public Optional<String> getPrimaryImageUrlFor(UserBirdCollection collection) {
2222
.map(imageDomainService::toUploadImageUrl);
2323
}
2424

25+
public Optional<String> getPrimaryImageThumbnailUrlFor(UserBirdCollection collection) {
26+
return collectionImageSelector.selectPrimaryImageKey(collection)
27+
.map(imageDomainService::toThumbnailUrl);
28+
}
29+
2530
public Map<Long, String> getPrimaryImageUrlsFor(List<UserBirdCollection> collections) {
2631
Map<Long, String> result = new LinkedHashMap<>();
2732
Map<Long, String> objectKeyMap = collectionImageSelector.selectPrimaryImageKeyMap(collections);

src/main/java/org/devkor/apu/saerok_server/domain/community/api/dto/common/CommunityCollectionInfo.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ public record CommunityCollectionInfo(
1010
@Schema(description = "컬렉션 ID", example = "1")
1111
Long collectionId,
1212

13-
@Schema(description = "이미지 URL", example = "https://cdn.example.com/collection-images/1.jpg")
13+
@Schema(description = "이미지 URL", example = "https://cdn.example.com/collection-images/123/abc")
1414
String imageUrl,
1515

16+
@Schema(description = "썸네일 이미지 URL", example = "https://cdn.example.com/thumbnails/123/abc.webp")
17+
String thumbnailImageUrl,
18+
1619
@Schema(description = "발견 날짜", example = "2024-03-15")
1720
LocalDate discoveredDate,
1821

src/main/java/org/devkor/apu/saerok_server/domain/community/application/CommunityDataAssembler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public List<CommunityCollectionInfo> toCollectionInfos(List<UserBirdCollection>
3535
}
3636

3737
Map<Long, String> imageUrls = collectionImageUrlService.getPrimaryImageUrlsFor(collections);
38+
Map<Long, String> thumbnailImageUrls = collectionImageUrlService.getPrimaryImageThumbnailUrlsFor(collections);
3839

3940
List<Long> collectionIds = collections.stream()
4041
.map(UserBirdCollection::getId)
@@ -52,6 +53,7 @@ public List<CommunityCollectionInfo> toCollectionInfos(List<UserBirdCollection>
5253
return collections.stream()
5354
.map(collection -> {
5455
String imageUrl = imageUrls.get(collection.getId());
56+
String thumbnailImageUrl = thumbnailImageUrls.get(collection.getId());
5557
String userProfileImageUrl = userProfileImageUrlService.getProfileImageUrlFor(collection.getUser());
5658
long likeCount = collectionLikeRepository.countByCollectionId(collection.getId());
5759
long commentCount = collectionCommentRepository.countByCollectionId(collection.getId());
@@ -63,7 +65,7 @@ public List<CommunityCollectionInfo> toCollectionInfos(List<UserBirdCollection>
6365
: null;
6466

6567
return communityWebMapper.toCommunityCollectionInfo(
66-
collection, imageUrl, userProfileImageUrl, likeCount, commentCount, isLiked, isPopular, suggestionUserCount
68+
collection, imageUrl, thumbnailImageUrl, userProfileImageUrl, likeCount, commentCount, isLiked, isPopular, suggestionUserCount
6769
);
6870
})
6971
.toList();

src/main/java/org/devkor/apu/saerok_server/domain/community/mapper/CommunityWebMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public interface CommunityWebMapper {
1414

1515
@Mapping(target = "collectionId", source = "collection.id")
1616
@Mapping(target = "imageUrl", source = "imageUrl")
17+
@Mapping(target = "thumbnailImageUrl", source = "thumbnailImageUrl")
1718
@Mapping(target = "discoveredDate", source = "collection.discoveredDate")
1819
@Mapping(target = "uploadedDate", expression = "java(OffsetDateTimeLocalizer.toSeoulLocalDateTime(collection.getCreatedAt()))")
1920
@Mapping(target = "latitude", source = "collection.latitude")
@@ -31,6 +32,7 @@ public interface CommunityWebMapper {
3132
CommunityCollectionInfo toCommunityCollectionInfo(
3233
UserBirdCollection collection,
3334
String imageUrl,
35+
String thumbnailImageUrl,
3436
String userProfileImageUrl,
3537
Long likeCount,
3638
Long commentCount,

src/main/java/org/devkor/apu/saerok_server/domain/notification/application/adapter/CollectionTargetMetadataAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public Map<String, Object> enrich(Target target, Map<String, Object> baseExtras)
3333
extras.put("collectionId", target.id());
3434

3535
String imageUrl = collectionRepository.findById(target.id())
36-
.flatMap(collectionImageUrlService::getPrimaryImageUrlFor)
36+
.flatMap(collectionImageUrlService::getPrimaryImageThumbnailUrlFor)
3737
.orElse(null);
3838
extras.put("collectionImageUrl", imageUrl);
3939

src/main/java/org/devkor/apu/saerok_server/domain/profile/api/dto/response/UserProfileResponse.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public record CollectionItem(
4141
@Schema(description = "대표 이미지 URL (컬렉션의 첫 번째 이미지)", example = "https://cdn.saerok.dev/images/collection/101/main.jpg", nullable = true)
4242
String imageUrl,
4343

44+
@Schema(description = "썸네일 이미지 URL (320px 너비)", example = "https://cdn.saerok.dev/thumbnails/collection/101/main.webp", nullable = true)
45+
String thumbnailImageUrl,
46+
4447
@Schema(description = "사용자가 작성한 한줄평", example = "처음 본 새인데 정말 귀여웠다!", nullable = true)
4548
String note,
4649

src/main/java/org/devkor/apu/saerok_server/domain/profile/mapper/UserProfileMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ default List<UserProfileResponse.CollectionItem> toCollectionItems(
4040
) {
4141
Map<Long, String> imageUrlMap =
4242
collectionImageUrlService.getPrimaryImageUrlsFor(collections);
43+
Map<Long, String> thumbnailUrlMap =
44+
collectionImageUrlService.getPrimaryImageThumbnailUrlsFor(collections);
4345

4446
return collections.stream()
4547
.map(c -> new UserProfileResponse.CollectionItem(
@@ -48,6 +50,7 @@ default List<UserProfileResponse.CollectionItem> toCollectionItems(
4850
c.getBird() == null ? null : c.getBird().getName().getKoreanName(),
4951
c.getBird() == null ? null : c.getBird().getName().getScientificName(),
5052
imageUrlMap.get(c.getId()),
53+
thumbnailUrlMap.get(c.getId()),
5154
c.getNote(),
5255
c.getDiscoveredDate(),
5356
OffsetDateTimeLocalizer.toSeoulLocalDate(c.getCreatedAt())

src/test/java/org/devkor/apu/saerok_server/domain/community/application/CommunityQueryServiceTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ private static UserBirdCollection collection(Long id, User user, Bird bird, Stri
6363
private static CommunityCollectionInfo collectionInfo(
6464
Long collectionId,
6565
String imageUrl,
66+
String thumbnailImageUrl,
6667
String note,
6768
Long likeCount,
6869
Long commentCount,
@@ -74,6 +75,7 @@ private static CommunityCollectionInfo collectionInfo(
7475
return new CommunityCollectionInfo(
7576
collectionId,
7677
imageUrl,
78+
thumbnailImageUrl,
7779
LocalDate.of(2024, 3, 15),
7880
LocalDateTime.of(2024, 3, 15, 10, 30, 0),
7981
37.5665,
@@ -176,13 +178,13 @@ void getRecentCollections_withMixedCollections_correctlySetsParticipantCount() {
176178
);
177179

178180
CommunityCollectionInfo pendingInfo = collectionInfo(
179-
1L, "https://example.com/image1.jpg", "이게 무슨 새일까요?",
181+
1L, "https://example.com/image1.jpg", "https://example.com/thumbnails/1", "이게 무슨 새일까요?",
180182
10L, 5L, false, 3L, null, userInfo
181183
);
182184

183185
CommunityCollectionInfo.BirdInfo birdInfo = new CommunityCollectionInfo.BirdInfo(100L, "까치");
184186
CommunityCollectionInfo normalInfo = collectionInfo(
185-
2L, "https://example.com/image2.jpg", "까치를 발견했어요!",
187+
2L, "https://example.com/image2.jpg", "https://example.com/thumbnails/2", "까치를 발견했어요!",
186188
15L, 7L, false, null, birdInfo, userInfo
187189
);
188190

0 commit comments

Comments
 (0)