From 8cd8734f64714d8d9dbbfc0775c77e408c56a061 Mon Sep 17 00:00:00 2001 From: aelimited Date: Thu, 13 Jun 2024 05:38:03 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[FEAT]=20#131=20-=20=EC=86=8C=EB=AA=A8?= =?UTF-8?q?=EC=9E=84=20=EC=A7=88=EB=AC=B8=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=EB=8C=80=EB=8B=B5=20=EC=A1=B0=ED=9A=8C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../club/club/controller/ClubController.java | 14 +++++++++++--- .../club/club/converter/ClubConverter.java | 14 ++++++++++++++ .../club/repository/ClubAnswerRepository.java | 2 ++ .../club/response/ClubAnswerListResponse.java | 16 ++++++++++++++++ .../linkup/club/club/service/ClubService.java | 18 ++++++++++++++++++ 5 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/core/linkup/club/club/response/ClubAnswerListResponse.java 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 128fe26..9147ed2 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 @@ -287,4 +287,18 @@ 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) + .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 97a47ea..09eaea9 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); + } + } } From 5cd93ef757571dc6895482644c94a3ea8e985d0a Mon Sep 17 00:00:00 2001 From: aelimited Date: Thu, 13 Jun 2024 05:49:52 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[FIX]=20#313=20-=20qoders=20size=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/core/linkup/club/club/converter/ClubConverter.java | 1 + 1 file changed, 1 insertion(+) 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 9147ed2..898748b 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 @@ -299,6 +299,7 @@ public ClubAnswerListResponse toAnswerResponse(List answers, Club cl .clubIntroduction(club.getIntroduction()) .clubDetailIntroduction(club.getDetailedIntroduction()) .answer(answerList) + .qorders(answers.size()) .build(); } }