diff --git a/src/main/java/com/core/linkup/club/club/controller/ClubController.java b/src/main/java/com/core/linkup/club/club/controller/ClubController.java index 33830c1..940b548 100644 --- a/src/main/java/com/core/linkup/club/club/controller/ClubController.java +++ b/src/main/java/com/core/linkup/club/club/controller/ClubController.java @@ -1,9 +1,7 @@ package com.core.linkup.club.club.controller; import com.core.linkup.club.club.request.*; -import com.core.linkup.club.club.response.ClubLikeResponse; -import com.core.linkup.club.club.response.ClubQuestionResponse; -import com.core.linkup.club.club.response.ClubSearchResponse; +import com.core.linkup.club.club.response.*; import com.core.linkup.club.club.service.ClubService; import com.core.linkup.common.response.BaseResponse; import com.core.linkup.common.response.BaseResponseStatus; @@ -112,6 +110,16 @@ public BaseResponse findQuestion( return BaseResponse.response(response); } + @GetMapping("/{club_id}/answer") + public BaseResponse findAnswer( + @AuthenticationPrincipal MemberDetails memberDetails, + @PathVariable("club_id") Long clubId + ) { + ClubAnswerListResponse response = clubService.findAnswer(memberDetails, clubId); + return BaseResponse.response(response); + } + + //소모임 좋아요 @PostMapping("/{club_id}/like") public BaseResponse likeClub( 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 79356b6..0a45c05 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 @@ -290,4 +290,19 @@ 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/ClubAnswerRepository.java b/src/main/java/com/core/linkup/club/club/repository/ClubAnswerRepository.java index 6d732e4..cf14670 100644 --- a/src/main/java/com/core/linkup/club/club/repository/ClubAnswerRepository.java +++ b/src/main/java/com/core/linkup/club/club/repository/ClubAnswerRepository.java @@ -10,4 +10,6 @@ public interface ClubAnswerRepository extends JpaRepository { List findByMemberId(Long memberId); List findByMemberIdAndClubId(Long memberId, Long clubId); + + List findAllByClubId(Long clubId); } diff --git a/src/main/java/com/core/linkup/club/club/response/ClubAnswerListResponse.java b/src/main/java/com/core/linkup/club/club/response/ClubAnswerListResponse.java new file mode 100644 index 0000000..3a6e30a --- /dev/null +++ b/src/main/java/com/core/linkup/club/club/response/ClubAnswerListResponse.java @@ -0,0 +1,16 @@ +package com.core.linkup.club.club.response; + +import lombok.Builder; + +import java.util.List; + +@Builder +public record ClubAnswerListResponse( + Long clubId, + String clubTitle, + String clubIntroduction, + String clubDetailIntroduction, + List answer, + Integer qorders +) { +} diff --git a/src/main/java/com/core/linkup/club/club/service/ClubService.java b/src/main/java/com/core/linkup/club/club/service/ClubService.java index 8ab7e50..396599e 100644 --- a/src/main/java/com/core/linkup/club/club/service/ClubService.java +++ b/src/main/java/com/core/linkup/club/club/service/ClubService.java @@ -4,6 +4,8 @@ import com.core.linkup.club.club.entity.*; import com.core.linkup.club.club.repository.*; import com.core.linkup.club.club.request.*; +import com.core.linkup.club.club.response.ClubAnswerListResponse; +import com.core.linkup.club.club.response.ClubAnswerResponse; import com.core.linkup.club.club.response.ClubQuestionResponse; import com.core.linkup.club.club.response.ClubSearchResponse; import com.core.linkup.club.clubmeeting.entity.ClubMeeting; @@ -35,6 +37,7 @@ public class ClubService { private final ClubConverter clubConverter; private final ClubMeetingRepository clubMeetingRepository; private final ClubLikeRepository clubLikeRepository; + private final ClubAnswerRepository clubAnswerRepository; //소모임 개별 조회 public ClubSearchResponse findClub(Long clubId, Member member) { @@ -202,4 +205,19 @@ public ClubQuestionResponse findQuestion(MemberDetails memberDetails, Long clubI } } + + public ClubAnswerListResponse findAnswer(MemberDetails memberDetails, Long clubId) { + Long memberId = memberDetails.getId(); + + List answers = clubAnswerRepository.findAllByClubId(clubId); + Optional clubOptional = clubRepository.findById(clubId); + + if (clubOptional.isPresent()) { + Club club = clubOptional.get(); + + return clubConverter.toAnswerResponse(answers, club); + } else { + throw new BaseException(BaseResponseStatus.INVALID_CLUB_ID); + } + } }