Skip to content

Commit

Permalink
Merge pull request #137 from aelimited/feature/#131-clubFix
Browse files Browse the repository at this point in the history
[FIX] #131 - 가입한 소모임 조회 (page)
  • Loading branch information
c0smosaur authored Jun 13, 2024
2 parents 807068a + b97fcbe commit 1eb63af
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,13 @@ public BaseResponse<Page<ClubSearchResponse>> findManagingApplication(
return BaseResponse.response(responses);
}

@GetMapping("/application/search")
public BaseResponse<Page<ClubSearchApplicationResponse>> findSearchApplicationList(
@AuthenticationPrincipal MemberDetails member,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size
) {
Page<ClubSearchApplicationResponse> response = clubMemberService.findSearchClubApplicationList(member, PageRequest.of(page, size));
return BaseResponse.response(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,21 @@ public ClubQuestionResponse toQuestionResponse(List<ClubQuestion> questions, Clu
.build();
}

public ClubAnswerListResponse toAnswerResponse(List<ClubAnswer> answers, Club club) {
List<String> 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();
Expand All @@ -290,19 +305,4 @@ public ClubSearchApplicationResponse toClubSearchApplicationResponse(
.liked(isLiked)
.build();
}

public ClubAnswerListResponse toAnswerResponse(List<ClubAnswer> answers, Club club) {
List<String> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
@Repository
public interface ClubRepository extends JpaRepository<Club, Long>, ClubCustomRepository {
Page<Club> findByMemberId(Long memberId, Pageable pageable);
List<Club> findByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.core.linkup.club.club.repository.ClubRepository;
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;
Expand Down Expand Up @@ -156,4 +157,44 @@ public Page<ClubSearchResponse> findManagingApplication(MemberDetails memberDeta
});
}

public Page<ClubSearchApplicationResponse> findSearchClubApplicationList(MemberDetails member, Pageable pageable) {
Long memberId = member.getId();

List<Club> hostedClubs = clubRepository.findByMemberId(memberId);
List<Long> hostedClubIds = hostedClubs.stream().map(Club::getId).collect(Collectors.toList());

List<ClubMember> clubMembers = clubMemberRepository.findByMemberId(memberId);

List<Long> memberLikes = likeRepository.findAllByMemberId(memberId).stream()
.map(ClubLike::getClubId)
.collect(Collectors.toList());

List<ClubSearchApplicationResponse> 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<ClubSearchApplicationResponse> page = new PageImpl<>(responses.subList(start, end), pageable, responses.size());

return page;
}
}

0 comments on commit 1eb63af

Please sign in to comment.