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 db9c9be..33830c1 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 @@ -2,6 +2,7 @@ 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.service.ClubService; import com.core.linkup.common.response.BaseResponse; @@ -41,8 +42,8 @@ public BaseResponse> findClubs( @RequestParam(name = "category", required = false) String category ) { - // 비로그인 - if (category!=null) { + // 비로그인 + if (category != null) { Page searchResponse = clubService.findClubs(pageable, category); return BaseResponse.response(searchResponse); @@ -60,7 +61,7 @@ public BaseResponse> findClubsAuthenticated( @PageableDefault(sort = "id", direction = Sort.Direction.ASC) Pageable pageable, @RequestParam(name = "category", required = false) String category) { // 로그인 - if (category!=null) { + if (category != null) { Page searchResponse = clubService.findClubs(member.getMember(), pageable, category); return BaseResponse.response(searchResponse); @@ -102,6 +103,15 @@ public BaseResponse delete( return BaseResponse.response(BaseResponseStatus.DELETE_SUCCESS); } + @GetMapping("/{club_id}/question") + public BaseResponse findQuestion( + @AuthenticationPrincipal MemberDetails memberDetails, + @PathVariable("club_id") Long clubId + ) { + ClubQuestionResponse response = clubService.findQuestion(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 04530f1..be97276 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 @@ -249,4 +249,18 @@ public ClubSearchResponse toManagingApplication(Club club, Member member) { .clubThumbnail(club.getClubThumbnail()) .build(); } + + public ClubQuestionResponse toQuestionResponse(List questions, Club club) { + List questionList = questions.stream() + .map(ClubQuestion::getQuestion) + .toList(); + + return ClubQuestionResponse.builder() + .clubId(club.getId()) + .clubTitle(club.getTitle()) + .clubIntroduction(club.getIntroduction()) + .clubDetailIntroduction(club.getDetailedIntroduction()) + .question(questionList) + .build(); + } } diff --git a/src/main/java/com/core/linkup/club/club/repository/ClubQuestionRepository.java b/src/main/java/com/core/linkup/club/club/repository/ClubQuestionRepository.java index ed852b4..aca9c31 100644 --- a/src/main/java/com/core/linkup/club/club/repository/ClubQuestionRepository.java +++ b/src/main/java/com/core/linkup/club/club/repository/ClubQuestionRepository.java @@ -3,5 +3,8 @@ import com.core.linkup.club.club.entity.ClubQuestion; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ClubQuestionRepository extends JpaRepository { + List findAllByClubId(Long clubId); } diff --git a/src/main/java/com/core/linkup/club/club/response/ClubQuestionResponse.java b/src/main/java/com/core/linkup/club/club/response/ClubQuestionResponse.java new file mode 100644 index 0000000..15ea595 --- /dev/null +++ b/src/main/java/com/core/linkup/club/club/response/ClubQuestionResponse.java @@ -0,0 +1,15 @@ +package com.core.linkup.club.club.response; + +import lombok.Builder; + +import java.util.List; + +@Builder +public record ClubQuestionResponse( + Long clubId, + String clubTitle, + String clubIntroduction, + String clubDetailIntroduction, + List question +) { +} 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 dcec710..97a47ea 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,7 @@ 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.ClubQuestionResponse; import com.core.linkup.club.club.response.ClubSearchResponse; import com.core.linkup.club.clubmeeting.entity.ClubMeeting; import com.core.linkup.club.clubmeeting.repository.ClubMeetingRepository; @@ -185,4 +186,20 @@ public Page findLikeClub(MemberDetails member, Pageable page }); } + //소모임 질문 조회 + public ClubQuestionResponse findQuestion(MemberDetails memberDetails, Long clubId) { + Long memberId = memberDetails.getId(); + + List questions = clubQuestionRepository.findAllByClubId(clubId); + Optional clubOptional = clubRepository.findById(clubId); + + if (clubOptional.isPresent()) { + Club club = clubOptional.get(); + + return clubConverter.toQuestionResponse(questions, club); + } else { + throw new BaseException(BaseResponseStatus.INVALID_CLUB_ID); + } + + } }