Skip to content

Commit cd7030e

Browse files
authored
Merge pull request #173 from checkmo2025/refactor/172/modify-swagger-schema
[REFACTOR] swagger schema 수정
2 parents bcada83 + ec18831 commit cd7030e

17 files changed

Lines changed: 111 additions & 31 deletions

File tree

src/main/java/checkmo/clubManagement/internal/service/ClubManagementQueryFacade.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import java.util.EnumSet;
2929
import java.util.List;
3030
import java.util.Map;
31+
import java.util.Objects;
3132
import java.util.Optional;
33+
import java.util.stream.Collectors;
3234
import java.util.stream.IntStream;
3335
import lombok.RequiredArgsConstructor;
3436
import org.springframework.stereotype.Service;
@@ -197,13 +199,26 @@ public ClubRecommendationList recommend(String memberId) {
197199
List<ClubRecommendation> result
198200
= clubManagementQueryService.recommend(interestCategories, lastActivityAt, memberId);
199201

202+
// 추천 결과 기반으로 클럽 정보 배치 조회
203+
List<Long> clubIds = ExtractHelper.extractDistinctList(result, ClubRecommendation::getClubId);
204+
List<Club> clubs = clubManagementQueryService.retrieveClubs(clubIds);
205+
Map<Long, Club> clubMap = clubs.stream().collect(Collectors.toMap(Club::getId, c -> c));
206+
200207
List<ClubResponseDTO.ClubRecommendation> recommendations = IntStream.range(0, result.size())
201208
.mapToObj(i -> {
202209
ClubRecommendation rec = result.get(i);
210+
Club club = clubMap.get(rec.getClubId());
211+
if (club == null) {
212+
// 추천 결과에 클럽 정보가 없는 경우는 무시 (정상적으로는 발생하지 않아야 함)
213+
return null;
214+
}
215+
ClubDetailWithMyStatus clubDTO = ClubResponseDTO.ClubDetailWithMyStatus.builder()
216+
.club(ClubManagementConverter.toClubDetailDTO(club, false))
217+
.myStatus(MyClubMemberStatus.NONE)
218+
.build();
203219
return ClubResponseDTO.ClubRecommendation.builder()
204220
.rank(i + 1)
205-
.clubId(rec.getClubId())
206-
.clubName(rec.getClubName())
221+
.clubInfo(clubDTO)
207222
.overlapCount(rec.getOverlapCount())
208223
.activeMemberCount(rec.getActiveMemberCount())
209224
.lastActivityAt(rec.getLastActivityAt())
@@ -212,7 +227,7 @@ public ClubRecommendationList recommend(String memberId) {
212227
.toList();
213228

214229
return ClubResponseDTO.ClubRecommendationList.builder()
215-
.recommendations(recommendations)
230+
.recommendations(recommendations.stream().filter(Objects::nonNull).toList())
216231
.build();
217232
}
218233

src/main/java/checkmo/clubManagement/internal/service/query/ClubManagementQueryService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ public List<Club> retrieveClubs(ClubRequestDTO.ClubSearchFilter filter, Long cur
2828
return clubRepository.searchClubs(filter, cursorId, pageSize);
2929
}
3030

31+
public List<Club> retrieveClubs(List<Long> clubIds) {
32+
if (clubIds == null || clubIds.isEmpty()) {
33+
return List.of();
34+
}
35+
return clubRepository.findAllById(clubIds);
36+
}
37+
3138
public boolean isDuplicateClubName(String clubName) {
3239
return clubRepository.existsByName(clubName.trim());
3340
}

src/main/java/checkmo/clubManagement/web/dto/ClubResponseDTO.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ public static ClubContactItem from(ClubContact clubContact) {
8080
public static class ClubDetail {
8181
private Long clubId;
8282
private String name;
83-
@JsonInclude(JsonInclude.Include.NON_NULL) // 독서모임 검색
83+
@JsonInclude(JsonInclude.Include.NON_NULL) // 독서모임 검색, 추천
8484
private String description;
8585
private String profileImageUrl;
8686
private boolean isOpen;
8787
private String region;
8888
private List<ClubCategoryItem> category;
8989
private List<ClubParticipantTypeItem> participantTypes;
90-
@JsonInclude(JsonInclude.Include.NON_NULL) // 독서모임 검색
90+
@JsonInclude(JsonInclude.Include.NON_NULL) // 독서모임 검색, 추천
9191
private List<ClubContactItem> links;
9292
}
9393

@@ -176,10 +176,8 @@ public static class ClubRecommendationList {
176176
public static class ClubRecommendation {
177177
@Schema(description = "정렬 순서", example = "1")
178178
private int rank;
179-
@Schema(description = "추천하는 모임 ID", example = "12345")
180-
private Long clubId;
181-
@Schema(description = "추천하는 모임 이름", example = "책읽는 사람들")
182-
private String clubName;
179+
@Schema(description = "추천 모임의 상세 정보")
180+
private ClubDetailWithMyStatus clubInfo;
183181
@Schema(description = "멤버의 선호 카테고리와 모임의 카테고리 간의 겹치는 항목 수(모임 추천 기능 확인을 위해 넣은 필드로, 안정됐다고 판단되면 사라질 수 있습니다) ", example = "3")
184182
private Long overlapCount;
185183
@Schema(description = "모임의 활성화 상태인 클럽 멤버 수(모임 추천 기능 확인을 위해 넣은 필드로, 안정됐다고 판단되면 사라질 수 있습니다)", example = "150")

src/main/java/checkmo/clubMeeting/internal/service/ClubMeetingQueryFacade.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public BookShelfResponseDTO.BookShelfList retrieveBookShelfList(
5757
String memberId,
5858
Long cursorId
5959
) {
60-
validateClubAndClubMembership(clubId, memberId);
60+
MembershipInfo clubMembership = validateClubAndClubMembership(clubId, memberId);
6161

6262
CursorResult<Meeting> meetingCursorResult = CursorPagingHelper.getPage(
6363
pageSize -> clubMeetingQueryService.retrieveMeetings(clubId, cursorId, pageSize),
@@ -73,6 +73,7 @@ public BookShelfResponseDTO.BookShelfList retrieveBookShelfList(
7373
.bookShelfInfoList(mapMeetingsToBookshelfInfo(meetings, bookInfoMap))
7474
.hasNext(meetingCursorResult.hasNext())
7575
.nextCursor(meetingCursorResult.nextCursor())
76+
.staff(clubMembership.isStaff())
7677
.build();
7778
}
7879

src/main/java/checkmo/clubMeeting/web/dto/bookshelf/BookShelfResponseDTO.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ public static class BookShelfList {
2020
private List<BookShelfInfo> bookShelfInfoList;
2121
private boolean hasNext;
2222
private Long nextCursor;
23+
24+
@Getter(AccessLevel.NONE)
25+
private boolean staff;
26+
27+
@JsonProperty("isStaff")
28+
public boolean isStaff() {
29+
return staff;
30+
}
2331
}
2432

2533
@Getter

src/main/java/checkmo/clubNotice/internal/converter/ClubNoticeConverter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static Notice toNotice(ClubNoticeRequestDTO.CreateClubNotice request, Not
2424
return Notice.builder()
2525
.title(request.getTitle())
2626
.content(request.getContent())
27-
.important(request.isImportant())
27+
.pinned(request.isPinned())
2828
.tag(tag)
2929
.meetingId(request.getMeetingId())
3030
.clubId(clubId)
@@ -64,7 +64,7 @@ public static ClubNoticeResponseDTO.ClubNoticePreview toClubNoticePreview(Notice
6464
return ClubNoticePreview.builder()
6565
.id(notice.getId())
6666
.title(notice.getTitle())
67-
.important(notice.isImportant())
67+
.pinned(notice.isPinned())
6868
.tagItem(ClubNoticeTagItem.from(notice.getTag()))
6969
.createdAt(notice.getCreatedAt())
7070
.build();
@@ -79,7 +79,7 @@ public static ClubNoticeResponseDTO.ClubNoticeDetail toClubNoticeDetail(
7979
.id(notice.getId())
8080
.title(notice.getTitle())
8181
.content(notice.getContent())
82-
.important(notice.isImportant())
82+
.pinned(notice.isPinned())
8383
.tag(ClubNoticeTagItem.from(notice.getTag()))
8484
.imageUrls(notice.getImageUrls())
8585
.createdAt(notice.getCreatedAt())

src/main/java/checkmo/clubNotice/internal/entity/Notice.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public class Notice extends BaseEntity {
4343
@Column(length = 1000)
4444
private String content;
4545

46-
private boolean important;
46+
@Column(name = "is_pinned")
47+
private boolean pinned;
4748

4849
@Enumerated(EnumType.STRING)
4950
@Column(nullable = false)
@@ -72,12 +73,12 @@ public class Notice extends BaseEntity {
7273
public void update(
7374
String title,
7475
String content,
75-
boolean important,
76+
boolean pinned,
7677
Long meetingId
7778
) {
7879
this.title = title;
7980
this.content = content;
80-
this.important = important;
81+
this.pinned = pinned;
8182
this.meetingId = meetingId;
8283
this.tag = NoticeTag.decideTag(this.vote != null, meetingId != null);
8384
}
@@ -126,7 +127,7 @@ public List<String> replaceImages(List<String> images) {
126127
if (images == null) {
127128
return List.of(); // null이면 변경 없음
128129
}
129-
130+
130131
if (images.size() > MAX_IMAGE_COUNT) {
131132
throw new ClubNoticeException(ClubNoticeErrorStatus.NOTICE_IMAGE_LIMIT_EXCEEDED);
132133
}

src/main/java/checkmo/clubNotice/internal/exception/ClubNoticeErrorStatus.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public enum ClubNoticeErrorStatus implements BaseErrorCode {
1212
// 공지사항
1313
NOTICE_NOT_FOUND(HttpStatus.NOT_FOUND, "NOTICE_400", "공지사항을 찾을 수 없습니다."),
1414
MEETING_NOT_IN_CLUB(HttpStatus.BAD_REQUEST, "NOTICE_401", "공지사항의 모임이 해당 동아리에 속해있지 않습니다."),
15+
PINNED_NOTICE_LIMIT_EXCEEDED(HttpStatus.BAD_REQUEST, "NOTICE_402", "고정 공지사항은 최대 5개까지 설정할 수 있습니다."),
1516

1617
// 투표
1718
INSUFFICIENT_VOTE_ITEMS(HttpStatus.BAD_REQUEST, "VOTE_400", "투표 항목이 2개 미만입니다."),

src/main/java/checkmo/clubNotice/internal/repository/NoticeRepository.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public interface NoticeRepository extends JpaRepository<Notice, Long> {
1818

1919
@Query("SELECT n FROM Notice n "
2020
+ "WHERE n.clubId = :clubId "
21-
+ "AND n.important = :important "
21+
+ "AND n.pinned = :pinned "
2222
+ "ORDER BY n.createdAt DESC, n.id DESC ")
23-
Page<Notice> findAllByClubIdAndImportant(Long clubId, boolean important, Pageable pageable);
23+
Page<Notice> findAllByClubIdAndPinned(Long clubId, boolean pinned, Pageable pageable);
24+
25+
long countByClubIdAndPinnedTrue(Long clubId);
2426
}

src/main/java/checkmo/clubNotice/internal/service/ClubNoticeQueryFacade.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ public ClubNoticePreviewList retrieveClubNoticeList(
5555
Long clubId,
5656
String memberId,
5757
int page,
58-
boolean important
58+
boolean pinned
5959
) {
6060
clubManagementAPI.validateClub(clubId);
6161
clubManagementAPI.fetchMembershipInfo(clubId, memberId);
6262

6363
PageResult<Notice> noticePageResult = PagePagingHelper.getPage(
64-
pageable -> clubNoticeQueryService.retrieveNotices(clubId, important, pageable),
64+
pageable -> clubNoticeQueryService.retrieveNotices(clubId, pinned, pageable),
6565
page,
6666
DEFAULT_PAGE_SIZE
6767
);

0 commit comments

Comments
 (0)