Skip to content

Commit af48b63

Browse files
authored
feat(community): 동정의견 참여자 수 모든 커뮤니티 조회에서 추가 (#187)
* feat: 커뮤니티 메인에서 동정 참여자 수 확인을 위한 dto 수정 * feat: 서비스 로직도 변경 * test: 커뮤니티 테스트 추가
1 parent df48a81 commit af48b63

9 files changed

Lines changed: 144 additions & 166 deletions

File tree

src/main/java/org/devkor/apu/saerok_server/domain/community/api/CommunityController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import lombok.RequiredArgsConstructor;
1111
import org.devkor.apu.saerok_server.domain.community.api.dto.response.GetCommunityCollectionsResponse;
1212
import org.devkor.apu.saerok_server.domain.community.api.dto.response.GetCommunityMainResponse;
13-
import org.devkor.apu.saerok_server.domain.community.api.dto.response.GetCommunityPendingCollectionsResponse;
1413
import org.devkor.apu.saerok_server.domain.community.api.dto.response.GetCommunitySearchResponse;
1514
import org.devkor.apu.saerok_server.domain.community.api.dto.response.GetCommunitySearchUsersResponse;
1615
import org.devkor.apu.saerok_server.domain.community.application.CommunityQueryService;
@@ -136,10 +135,10 @@ public GetCommunityCollectionsResponse getPopularCollections(
136135
""",
137136
responses = {
138137
@ApiResponse(responseCode = "200", description = "조회 성공",
139-
content = @Content(schema = @Schema(implementation = GetCommunityPendingCollectionsResponse.class)))
138+
content = @Content(schema = @Schema(implementation = GetCommunityCollectionsResponse.class)))
140139
}
141140
)
142-
public GetCommunityPendingCollectionsResponse getPendingCollections(
141+
public GetCommunityCollectionsResponse getPendingCollections(
143142
@AuthenticationPrincipal UserPrincipal userPrincipal,
144143
@Parameter(description = "페이지 번호 (1부터 시작)", example = "1") @RequestParam(required = false) Integer page,
145144
@Parameter(description = "페이지 크기", example = "20") @RequestParam(required = false) Integer size

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public record CommunityCollectionInfo(
3939
@Schema(description = "내가 좋아요 눌렀는지 여부", example = "true")
4040
Boolean isLiked,
4141

42+
@Schema(description = "동정 돕기에 참여한 유저 수 (동정 요청 컬렉션인 경우에만)", example = "5", nullable = true)
43+
Long suggestionUserCount,
44+
4245
@Schema(description = "새 정보")
4346
BirdInfo bird,
4447

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

Lines changed: 0 additions & 72 deletions
This file was deleted.

src/main/java/org/devkor/apu/saerok_server/domain/community/api/dto/response/GetCommunityMainResponse.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import io.swagger.v3.oas.annotations.media.Schema;
44
import org.devkor.apu.saerok_server.domain.community.api.dto.common.CommunityCollectionInfo;
5-
import org.devkor.apu.saerok_server.domain.community.api.dto.common.CommunityPendingCollectionInfo;
65

76
import java.util.List;
87

@@ -15,5 +14,5 @@ public record GetCommunityMainResponse(
1514
List<CommunityCollectionInfo> popularCollections,
1615

1716
@Schema(description = "동정 요청 새록 목록 (최대 3개)")
18-
List<CommunityPendingCollectionInfo> pendingCollections
17+
List<CommunityCollectionInfo> pendingCollections
1918
) {}

src/main/java/org/devkor/apu/saerok_server/domain/community/api/dto/response/GetCommunityPendingCollectionsResponse.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

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

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.devkor.apu.saerok_server.domain.collection.core.repository.CollectionLikeRepository;
88
import org.devkor.apu.saerok_server.domain.collection.core.repository.BirdIdSuggestionRepository;
99
import org.devkor.apu.saerok_server.domain.community.api.dto.common.CommunityCollectionInfo;
10-
import org.devkor.apu.saerok_server.domain.community.api.dto.common.CommunityPendingCollectionInfo;
1110
import org.devkor.apu.saerok_server.domain.community.api.dto.common.CommunityUserInfo;
1211
import org.devkor.apu.saerok_server.domain.community.mapper.CommunityWebMapper;
1312
import org.devkor.apu.saerok_server.domain.user.core.entity.User;
@@ -35,16 +34,28 @@ public List<CommunityCollectionInfo> toCollectionInfos(List<UserBirdCollection>
3534

3635
Map<Long, String> imageUrls = collectionImageUrlService.getPrimaryImageUrlsFor(collections);
3736

37+
List<Long> pendingCollectionIds = collections.stream()
38+
.filter(c -> c.getBird() == null)
39+
.map(UserBirdCollection::getId)
40+
.toList();
41+
Map<Long, Long> suggestionUserCounts = pendingCollectionIds.isEmpty()
42+
? Map.of()
43+
: birdIdSuggestionRepository.countDistinctUsersByCollectionIds(pendingCollectionIds);
44+
3845
return collections.stream()
3946
.map(collection -> {
4047
String imageUrl = imageUrls.get(collection.getId());
4148
String userProfileImageUrl = userProfileImageUrlService.getProfileImageUrlFor(collection.getUser());
4249
long likeCount = collectionLikeRepository.countByCollectionId(collection.getId());
4350
long commentCount = collectionCommentRepository.countByCollectionId(collection.getId());
4451
boolean isLiked = userId != null && collectionLikeRepository.existsByUserIdAndCollectionId(userId, collection.getId());
52+
53+
Long suggestionUserCount = collection.getBird() == null
54+
? suggestionUserCounts.getOrDefault(collection.getId(), 0L)
55+
: null;
4556

4657
return communityWebMapper.toCommunityCollectionInfo(
47-
collection, imageUrl, userProfileImageUrl, likeCount, commentCount, isLiked
58+
collection, imageUrl, userProfileImageUrl, likeCount, commentCount, isLiked, suggestionUserCount
4859
);
4960
})
5061
.toList();
@@ -58,29 +69,4 @@ public List<CommunityUserInfo> toUserInfos(List<User> users) {
5869
})
5970
.toList();
6071
}
61-
62-
public List<CommunityPendingCollectionInfo> toPendingCollectionInfos(List<UserBirdCollection> collections, Long userId) {
63-
if (collections.isEmpty()) {
64-
return List.of();
65-
}
66-
67-
Map<Long, String> imageUrls = collectionImageUrlService.getPrimaryImageUrlsFor(collections);
68-
List<Long> collectionIds = collections.stream().map(UserBirdCollection::getId).toList();
69-
Map<Long, Long> suggestionUserCounts = birdIdSuggestionRepository.countDistinctUsersByCollectionIds(collectionIds);
70-
71-
return collections.stream()
72-
.map(collection -> {
73-
String imageUrl = imageUrls.get(collection.getId());
74-
String userProfileImageUrl = userProfileImageUrlService.getProfileImageUrlFor(collection.getUser());
75-
long likeCount = collectionLikeRepository.countByCollectionId(collection.getId());
76-
long commentCount = collectionCommentRepository.countByCollectionId(collection.getId());
77-
boolean isLiked = userId != null && collectionLikeRepository.existsByUserIdAndCollectionId(userId, collection.getId());
78-
long suggestionUserCount = suggestionUserCounts.getOrDefault(collection.getId(), 0L);
79-
80-
return communityWebMapper.toCommunityPendingCollectionInfo(
81-
collection, imageUrl, userProfileImageUrl, likeCount, commentCount, isLiked, suggestionUserCount
82-
);
83-
})
84-
.toList();
85-
}
8672
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import org.devkor.apu.saerok_server.domain.collection.core.entity.UserBirdCollection;
55
import org.devkor.apu.saerok_server.domain.community.api.dto.response.GetCommunityCollectionsResponse;
66
import org.devkor.apu.saerok_server.domain.community.api.dto.response.GetCommunityMainResponse;
7-
import org.devkor.apu.saerok_server.domain.community.api.dto.response.GetCommunityPendingCollectionsResponse;
87
import org.devkor.apu.saerok_server.domain.community.api.dto.response.GetCommunitySearchResponse;
98
import org.devkor.apu.saerok_server.domain.community.api.dto.response.GetCommunitySearchUsersResponse;
109
import org.devkor.apu.saerok_server.domain.community.application.dto.CommunityQueryCommand;
@@ -20,7 +19,7 @@
2019
@RequiredArgsConstructor
2120
public class CommunityQueryService {
2221

23-
private static final int POPULAR_MIN_LIKES = 10;
22+
private static final int POPULAR_MIN_LIKES = 3;
2423

2524
private final CommunityRepository communityRepository;
2625
private final CommunityDataAssembler dataAssembler;
@@ -36,7 +35,7 @@ public GetCommunityMainResponse getCommunityMain(Long userId) {
3635
return new GetCommunityMainResponse(
3736
dataAssembler.toCollectionInfos(recentCollections, userId),
3837
dataAssembler.toCollectionInfos(popularCollections, userId),
39-
dataAssembler.toPendingCollectionInfos(pendingCollections, userId)
38+
dataAssembler.toCollectionInfos(pendingCollections, userId)
4039
);
4140
}
4241

@@ -50,9 +49,9 @@ public GetCommunityCollectionsResponse getPopularCollections(Long userId, Commun
5049
return new GetCommunityCollectionsResponse(dataAssembler.toCollectionInfos(collections, userId));
5150
}
5251

53-
public GetCommunityPendingCollectionsResponse getPendingBirdIdCollections(Long userId, CommunityQueryCommand command) {
52+
public GetCommunityCollectionsResponse getPendingBirdIdCollections(Long userId, CommunityQueryCommand command) {
5453
List<UserBirdCollection> collections = communityRepository.findPendingBirdIdCollections(command);
55-
return new GetCommunityPendingCollectionsResponse(dataAssembler.toPendingCollectionInfos(collections, userId));
54+
return new GetCommunityCollectionsResponse(dataAssembler.toCollectionInfos(collections, userId));
5655
}
5756

5857
public GetCommunitySearchResponse searchAll(String query, Long userId) {

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

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.devkor.apu.saerok_server.domain.collection.core.entity.UserBirdCollection;
44
import org.devkor.apu.saerok_server.domain.community.api.dto.common.CommunityCollectionInfo;
5-
import org.devkor.apu.saerok_server.domain.community.api.dto.common.CommunityPendingCollectionInfo;
65
import org.devkor.apu.saerok_server.domain.community.api.dto.common.CommunityUserInfo;
76
import org.devkor.apu.saerok_server.domain.user.core.entity.User;
87
import org.mapstruct.Mapper;
@@ -23,32 +22,10 @@ public interface CommunityWebMapper {
2322
@Mapping(target = "likeCount", source = "likeCount")
2423
@Mapping(target = "commentCount", source = "commentCount")
2524
@Mapping(target = "isLiked", source = "isLiked")
25+
@Mapping(target = "suggestionUserCount", source = "suggestionUserCount")
2626
@Mapping(target = "bird", expression = "java(mapBirdInfo(collection))")
2727
@Mapping(target = "user", expression = "java(mapUserInfo(collection, userProfileImageUrl))")
2828
CommunityCollectionInfo toCommunityCollectionInfo(
29-
UserBirdCollection collection,
30-
String imageUrl,
31-
String userProfileImageUrl,
32-
Long likeCount,
33-
Long commentCount,
34-
Boolean isLiked
35-
);
36-
37-
@Mapping(target = "collectionId", source = "collection.id")
38-
@Mapping(target = "imageUrl", source = "imageUrl")
39-
@Mapping(target = "discoveredDate", source = "collection.discoveredDate")
40-
@Mapping(target = "latitude", source = "collection.latitude")
41-
@Mapping(target = "longitude", source = "collection.longitude")
42-
@Mapping(target = "locationAlias", source = "collection.locationAlias")
43-
@Mapping(target = "address", source = "collection.address")
44-
@Mapping(target = "note", source = "collection.note")
45-
@Mapping(target = "likeCount", source = "likeCount")
46-
@Mapping(target = "commentCount", source = "commentCount")
47-
@Mapping(target = "isLiked", source = "isLiked")
48-
@Mapping(target = "suggestionUserCount", source = "suggestionUserCount")
49-
@Mapping(target = "bird", expression = "java(mapPendingBirdInfo(collection))")
50-
@Mapping(target = "user", expression = "java(mapPendingUserInfo(collection, userProfileImageUrl))")
51-
CommunityPendingCollectionInfo toCommunityPendingCollectionInfo(
5229
UserBirdCollection collection,
5330
String imageUrl,
5431
String userProfileImageUrl,
@@ -83,25 +60,4 @@ default CommunityCollectionInfo.UserInfo mapUserInfo(UserBirdCollection collecti
8360
profileImageUrl
8461
);
8562
}
86-
87-
default CommunityPendingCollectionInfo.BirdInfo mapPendingBirdInfo(UserBirdCollection collection) {
88-
if (collection.getBird() == null) {
89-
return null;
90-
}
91-
return new CommunityPendingCollectionInfo.BirdInfo(
92-
collection.getBird().getId(),
93-
collection.getBird().getName() != null ? collection.getBird().getName().getKoreanName() : null
94-
);
95-
}
96-
97-
default CommunityPendingCollectionInfo.UserInfo mapPendingUserInfo(UserBirdCollection collection, String profileImageUrl) {
98-
if (collection.getUser() == null) {
99-
return null;
100-
}
101-
return new CommunityPendingCollectionInfo.UserInfo(
102-
collection.getUser().getId(),
103-
collection.getUser().getNickname(),
104-
profileImageUrl
105-
);
106-
}
10763
}

0 commit comments

Comments
 (0)