Skip to content

Commit 250bfa3

Browse files
committed
docs: 세모피드 메서드 주석 추가
1 parent a912a99 commit 250bfa3

4 files changed

Lines changed: 22 additions & 9 deletions

File tree

src/main/java/com/semosan/api/domain/semofeed/controller/SemoFeedController.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,38 +40,37 @@ public ResponseEntity<ApiResponse<SemoFeedResponse>> create(
4040

4141
@GetMapping
4242
@Override
43+
// 공개 세모피드 목록을 작성자 정보와 이모지 상태까지 포함해 조회합니다.
4344
public ResponseEntity<ApiResponse<PageResponse<SemoFeedResponse>>> listPublic(
4445
@AuthenticationPrincipal Long userId,
4546
@PageableDefault(size = 100) Pageable pageable
4647
) {
4748
if (pageable.getPageSize() > 100) {
4849
pageable = PageRequest.of(pageable.getPageNumber(), 100, pageable.getSort());
4950
}
50-
return ApiResponse.success(
51-
SuccessStatus.SEMOFEED_LIST_SUCCESS,
52-
PageResponse.from(semoFeedService.listPublic(pageable, userId))
53-
);
51+
PageResponse<SemoFeedResponse> response = PageResponse.from(semoFeedService.listPublic(pageable, userId));
52+
return ApiResponse.success(SuccessStatus.SEMOFEED_LIST_SUCCESS, response);
5453
}
5554

5655
@PostMapping("/{semoFeedId}/emojis")
5756
@Override
57+
// 세모피드 이모지를 타입별로 등록하거나 취소합니다.
5858
public ResponseEntity<ApiResponse<SemoFeedEmojiToggleResponse>> toggleEmoji(
5959
@AuthenticationPrincipal Long userId,
6060
@PathVariable Long semoFeedId,
6161
@Valid @RequestBody SemoFeedEmojiRequest request
6262
) {
63-
return ApiResponse.success(
64-
SuccessStatus.SEMOFEED_EMOJI_TOGGLE_SUCCESS,
65-
semoFeedEmojiService.toggleWithCount(userId, semoFeedId, request.emojiType())
66-
);
63+
SemoFeedEmojiToggleResponse response = semoFeedEmojiService.toggleWithCount(userId, semoFeedId, request.emojiType());
64+
return ApiResponse.success(SuccessStatus.SEMOFEED_EMOJI_TOGGLE_SUCCESS, response);
6765
}
6866

6967
@GetMapping("/me")
7068
@Override
7169
public ResponseEntity<ApiResponse<List<SemoFeedResponse>>> listMine(
7270
@AuthenticationPrincipal Long userId
7371
) {
74-
return ApiResponse.success(SuccessStatus.SEMOFEED_MY_LIST_SUCCESS, semoFeedService.listMine(userId));
72+
List<SemoFeedResponse> response = semoFeedService.listMine(userId);
73+
return ApiResponse.success(SuccessStatus.SEMOFEED_MY_LIST_SUCCESS, response);
7574
}
7675

7776
@PatchMapping("/{semoFeedId}/public")

src/main/java/com/semosan/api/domain/semofeed/dto/SemoFeedResponse.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public static SemoFeedResponse of(
4545
);
4646
}
4747

48+
// 새로 생성된 세모피드 응답에 기본 이모지 개수를 채웁니다.
4849
private static Map<SemoFeedEmojiType, Long> defaultEmojiCounts() {
4950
Map<SemoFeedEmojiType, Long> emojiCounts = new EnumMap<>(SemoFeedEmojiType.class);
5051
for (SemoFeedEmojiType emojiType : SemoFeedEmojiType.values()) {
@@ -53,6 +54,7 @@ private static Map<SemoFeedEmojiType, Long> defaultEmojiCounts() {
5354
return emojiCounts;
5455
}
5556

57+
// 새로 생성된 세모피드 응답에 기본 내 반응 상태를 채웁니다.
5658
private static Map<SemoFeedEmojiType, Boolean> defaultReactedByMe() {
5759
Map<SemoFeedEmojiType, Boolean> reactedByMe = new EnumMap<>(SemoFeedEmojiType.class);
5860
for (SemoFeedEmojiType emojiType : SemoFeedEmojiType.values()) {

src/main/java/com/semosan/api/domain/semofeed/service/SemoFeedEmojiService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class SemoFeedEmojiService {
2929
private final UserRepository userRepository;
3030

3131
@Transactional(noRollbackFor = DataIntegrityViolationException.class)
32+
// 이모지 반응을 토글하고 변경 후 해당 타입의 개수를 반환합니다.
3233
public SemoFeedEmojiToggleResponse toggleWithCount(
3334
Long userId,
3435
Long semoFeedId,
@@ -43,6 +44,7 @@ public SemoFeedEmojiToggleResponse toggleWithCount(
4344
return new SemoFeedEmojiToggleResponse(emojiType, reacted, count);
4445
}
4546

47+
// 기존 반응이 있으면 취소하고, 없으면 새 반응을 저장합니다.
4648
private boolean toggle(SemoFeed semoFeed, User user, SemoFeedEmojiType emojiType) {
4749
Optional<SemoFeedEmoji> existing = semoFeedEmojiRepository.findBySemoFeedAndUserAndEmojiType(
4850
semoFeed,
@@ -69,11 +71,13 @@ private boolean toggle(SemoFeed semoFeed, User user, SemoFeedEmojiType emojiType
6971
}
7072
}
7173

74+
// 세모피드가 없으면 도메인 예외를 던집니다.
7275
private SemoFeed findSemoFeedOrThrow(Long semoFeedId) {
7376
return semoFeedRepository.findById(semoFeedId)
7477
.orElseThrow(() -> new GeneralException(ErrorStatus.SEMOFEED_NOT_FOUND));
7578
}
7679

80+
// 사용자가 없으면 도메인 예외를 던집니다.
7781
private User findUserOrThrow(Long userId) {
7882
return userRepository.findById(userId)
7983
.orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND));

src/main/java/com/semosan/api/domain/semofeed/service/SemoFeedService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public List<SemoFeedResponse> listMine(Long userId) {
4646
.toList();
4747
}
4848

49+
// 공개 세모피드 목록을 N+1 없이 응답 DTO로 조립합니다.
4950
public Page<SemoFeedResponse> listPublic(Pageable pageable, Long userId) {
5051
Page<SemoFeed> semoFeeds = semoFeedRepository.findPublic(pageable);
5152
return toResponsePage(semoFeeds, userId);
@@ -73,11 +74,13 @@ private SemoFeed findOwned(Long userId, Long semoFeedId) {
7374
return semoFeed;
7475
}
7576

77+
// 페이지 메타데이터를 유지하면서 각 세모피드를 응답 DTO로 변환합니다.
7678
private Page<SemoFeedResponse> toResponsePage(Page<SemoFeed> semoFeeds, Long userId) {
7779
SemoFeedResponseAssembler assembler = createResponseAssembler(semoFeeds.getContent(), userId);
7880
return semoFeeds.map(assembler::toResponse);
7981
}
8082

83+
// 피드별 이모지 집계와 내 반응 정보를 한 번씩 조회해 조립기를 만듭니다.
8184
private SemoFeedResponseAssembler createResponseAssembler(List<SemoFeed> semoFeeds, Long userId) {
8285
List<Long> semoFeedIds = semoFeeds.stream()
8386
.map(SemoFeed::getId)
@@ -89,6 +92,7 @@ private SemoFeedResponseAssembler createResponseAssembler(List<SemoFeed> semoFee
8992
return new SemoFeedResponseAssembler(userId, emojiCounts, reactedTypes);
9093
}
9194

95+
// 피드 ID 목록 기준으로 이모지 타입별 개수를 한 번에 조회합니다.
9296
private Map<Long, Map<SemoFeedEmojiType, Long>> findEmojiCounts(List<Long> semoFeedIds) {
9397
if (semoFeedIds.isEmpty()) {
9498
return Map.of();
@@ -104,6 +108,7 @@ private Map<Long, Map<SemoFeedEmojiType, Long>> findEmojiCounts(List<Long> semoF
104108
));
105109
}
106110

111+
// 피드 ID 목록 기준으로 로그인 사용자가 누른 이모지 타입을 한 번에 조회합니다.
107112
private Map<Long, Set<SemoFeedEmojiType>> findReactedTypes(List<Long> semoFeedIds, Long userId) {
108113
if (semoFeedIds.isEmpty() || userId == null) {
109114
return Map.of();
@@ -122,6 +127,7 @@ private record SemoFeedResponseAssembler(
122127
Map<Long, Set<SemoFeedEmojiType>> reactedTypes
123128
) {
124129

130+
// 세모피드 엔티티와 집계 결과를 최종 응답 DTO로 변환합니다.
125131
private SemoFeedResponse toResponse(SemoFeed semoFeed) {
126132
return SemoFeedResponse.of(
127133
semoFeed,
@@ -131,6 +137,7 @@ private SemoFeedResponse toResponse(SemoFeed semoFeed) {
131137
);
132138
}
133139

140+
// 누락된 이모지 타입도 0으로 채워 응답 계약을 일정하게 유지합니다.
134141
private Map<SemoFeedEmojiType, Long> completeEmojiCounts(Map<SemoFeedEmojiType, Long> counts) {
135142
Map<SemoFeedEmojiType, Long> completeCounts = new EnumMap<>(SemoFeedEmojiType.class);
136143
for (SemoFeedEmojiType emojiType : SemoFeedEmojiType.values()) {
@@ -139,6 +146,7 @@ private Map<SemoFeedEmojiType, Long> completeEmojiCounts(Map<SemoFeedEmojiType,
139146
return completeCounts;
140147
}
141148

149+
// 누락된 이모지 타입도 false로 채워 응답 계약을 일정하게 유지합니다.
142150
private Map<SemoFeedEmojiType, Boolean> completeReactedByMe(Set<SemoFeedEmojiType> reactedTypes) {
143151
Map<SemoFeedEmojiType, Boolean> completeReactedTypes = new EnumMap<>(SemoFeedEmojiType.class);
144152
for (SemoFeedEmojiType emojiType : SemoFeedEmojiType.values()) {

0 commit comments

Comments
 (0)