diff --git a/src/main/java/com/core/linkup/club/club/controller/ClubMemberController.java b/src/main/java/com/core/linkup/club/club/controller/ClubMemberController.java index 06dae81..2651f42 100644 --- a/src/main/java/com/core/linkup/club/club/controller/ClubMemberController.java +++ b/src/main/java/com/core/linkup/club/club/controller/ClubMemberController.java @@ -88,4 +88,13 @@ public BaseResponse> findManagingApplication( return BaseResponse.response(responses); } + @GetMapping("/application/search") + public BaseResponse> findSearchApplicationList( + @AuthenticationPrincipal MemberDetails member, + @RequestParam(defaultValue = "0") int page, + @RequestParam(defaultValue = "10") int size + ) { + Page response = clubMemberService.findSearchClubApplicationList(member, PageRequest.of(page, size)); + return BaseResponse.response(response); + } } \ No newline at end of file diff --git a/src/main/java/com/core/linkup/club/club/converter/ClubConverter.java b/src/main/java/com/core/linkup/club/club/converter/ClubConverter.java index 898748b..db87a36 100644 --- a/src/main/java/com/core/linkup/club/club/converter/ClubConverter.java +++ b/src/main/java/com/core/linkup/club/club/converter/ClubConverter.java @@ -267,6 +267,21 @@ public ClubQuestionResponse toQuestionResponse(List questions, Clu .build(); } + public ClubAnswerListResponse toAnswerResponse(List answers, Club club) { + List answerList = answers.stream() + .map(ClubAnswer::getAnswer) + .toList(); + + return ClubAnswerListResponse.builder() + .clubId(club.getId()) + .clubTitle(club.getTitle()) + .clubIntroduction(club.getIntroduction()) + .clubDetailIntroduction(club.getDetailedIntroduction()) + .answer(answerList) + .qorders(answers.size()) + .build(); + } + public ClubSearchApplicationResponse toClubSearchApplicationResponse( ClubMember clubMember,Member member, Club club, boolean isLiked) { ClubType clubType = club.getCategory(); @@ -287,19 +302,4 @@ public ClubSearchApplicationResponse toClubSearchApplicationResponse( .liked(isLiked) .build(); } - - public ClubAnswerListResponse toAnswerResponse(List answers, Club club) { - List answerList = answers.stream() - .map(ClubAnswer::getAnswer) - .toList(); - - return ClubAnswerListResponse.builder() - .clubId(club.getId()) - .clubTitle(club.getTitle()) - .clubIntroduction(club.getIntroduction()) - .clubDetailIntroduction(club.getDetailedIntroduction()) - .answer(answerList) - .qorders(answers.size()) - .build(); - } } diff --git a/src/main/java/com/core/linkup/club/club/repository/ClubRepository.java b/src/main/java/com/core/linkup/club/club/repository/ClubRepository.java index ca8666d..0e101c2 100644 --- a/src/main/java/com/core/linkup/club/club/repository/ClubRepository.java +++ b/src/main/java/com/core/linkup/club/club/repository/ClubRepository.java @@ -11,4 +11,5 @@ @Repository public interface ClubRepository extends JpaRepository, ClubCustomRepository { Page findByMemberId(Long memberId, Pageable pageable); + List findByMemberId(Long memberId); } diff --git a/src/main/java/com/core/linkup/club/club/service/ClubMemberService.java b/src/main/java/com/core/linkup/club/club/service/ClubMemberService.java index 1556d62..247755f 100644 --- a/src/main/java/com/core/linkup/club/club/service/ClubMemberService.java +++ b/src/main/java/com/core/linkup/club/club/service/ClubMemberService.java @@ -5,6 +5,7 @@ import com.core.linkup.club.club.repository.*; import com.core.linkup.club.club.request.ClubApplicationRequest; import com.core.linkup.club.club.request.ClubMemberApprovalRequest; +import com.core.linkup.club.club.response.ClubAnswerListResponse; import com.core.linkup.club.club.response.ClubApplicationResponse; import com.core.linkup.club.club.response.ClubSearchApplicationResponse; import com.core.linkup.club.club.response.ClubSearchResponse; @@ -149,4 +150,44 @@ public Page findManagingApplication(MemberDetails memberDeta }); } + public Page findSearchClubApplicationList(MemberDetails member, Pageable pageable) { + Long memberId = member.getId(); + + List hostedClubs = clubRepository.findByMemberId(memberId); + List hostedClubIds = hostedClubs.stream().map(Club::getId).collect(Collectors.toList()); + + List clubMembers = clubMemberRepository.findByMemberId(memberId); + + List memberLikes = likeRepository.findAllByMemberId(memberId).stream() + .map(ClubLike::getClubId) + .collect(Collectors.toList()); + + List responses = new ArrayList<>(); + + responses.addAll(clubMembers.stream() + .map(clubMember -> { + Club club = validateClub(clubMember.getClubId()); + boolean isLiked = memberLikes.contains(club.getId()); + Member memberInfo = memberRepository.findById(clubMember.getMemberId()) + .orElseThrow(() -> new BaseException(BaseResponseStatus.INVALID_CLUB_MEMBER)); + return clubConverter.toClubSearchApplicationResponse(clubMember, memberInfo, club, isLiked); + }) + .collect(Collectors.toList())); + + responses.addAll(hostedClubs.stream() + .map(club -> { + ClubMember clubMember = new ClubMember(); // 새로운 ClubMember 객체 생성 또는 적절한 방법으로 변환 + clubMember.setClubId(club.getId()); + clubMember.setMemberId(club.getMemberId()); + boolean isLiked = memberLikes.contains(club.getId()); + return clubConverter.toClubSearchApplicationResponse(clubMember, member.getMember(), club, isLiked); + }) + .collect(Collectors.toList())); + + int start = (int) pageable.getOffset(); + int end = Math.min((start + pageable.getPageSize()), responses.size()); + Page page = new PageImpl<>(responses.subList(start, end), pageable, responses.size()); + + return page; + } }