Skip to content

Commit

Permalink
Merge pull request #121 from aelimited/feature/#112-clubNoticeAndBoard
Browse files Browse the repository at this point in the history
[FEAT] #112 - 소모임 질문조회
  • Loading branch information
aelimited authored Jun 11, 2024
2 parents f482a0f + 9bd9ded commit 6aaa682
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,8 +42,8 @@ public BaseResponse<Page<ClubSearchResponse>> findClubs(
@RequestParam(name = "category", required = false) String category
) {

// 비로그인
if (category!=null) {
// 비로그인
if (category != null) {
Page<ClubSearchResponse> searchResponse =
clubService.findClubs(pageable, category);
return BaseResponse.response(searchResponse);
Expand All @@ -60,7 +61,7 @@ public BaseResponse<Page<ClubSearchResponse>> findClubsAuthenticated(
@PageableDefault(sort = "id", direction = Sort.Direction.ASC) Pageable pageable,
@RequestParam(name = "category", required = false) String category) {
// 로그인
if (category!=null) {
if (category != null) {
Page<ClubSearchResponse> searchResponse =
clubService.findClubs(member.getMember(), pageable, category);
return BaseResponse.response(searchResponse);
Expand Down Expand Up @@ -102,6 +103,15 @@ public BaseResponse<String> delete(
return BaseResponse.response(BaseResponseStatus.DELETE_SUCCESS);
}

@GetMapping("/{club_id}/question")
public BaseResponse<ClubQuestionResponse> 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<Void> likeClub(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,18 @@ public ClubSearchResponse toManagingApplication(Club club, Member member) {
.clubThumbnail(club.getClubThumbnail())
.build();
}

public ClubQuestionResponse toQuestionResponse(List<ClubQuestion> questions, Club club) {
List<String> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClubQuestion, Long> {
List<ClubQuestion> findAllByClubId(Long clubId);
}
Original file line number Diff line number Diff line change
@@ -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<String> question
) {
}
17 changes: 17 additions & 0 deletions src/main/java/com/core/linkup/club/club/service/ClubService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -185,4 +186,20 @@ public Page<ClubSearchResponse> findLikeClub(MemberDetails member, Pageable page
});
}

//소모임 질문 조회
public ClubQuestionResponse findQuestion(MemberDetails memberDetails, Long clubId) {
Long memberId = memberDetails.getId();

List<ClubQuestion> questions = clubQuestionRepository.findAllByClubId(clubId);
Optional<Club> clubOptional = clubRepository.findById(clubId);

if (clubOptional.isPresent()) {
Club club = clubOptional.get();

return clubConverter.toQuestionResponse(questions, club);
} else {
throw new BaseException(BaseResponseStatus.INVALID_CLUB_ID);
}

}
}

0 comments on commit 6aaa682

Please sign in to comment.