Skip to content

Commit

Permalink
Merge pull request #134 from aelimited/feature/#131-clubFix
Browse files Browse the repository at this point in the history
Feature/#131 club fix
  • Loading branch information
aelimited authored Jun 12, 2024
2 parents e8426e9 + 5cd93ef commit db1261f
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
@@ -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;
Expand Down Expand Up @@ -112,6 +110,16 @@ public BaseResponse<ClubQuestionResponse> findQuestion(
return BaseResponse.response(response);
}

@GetMapping("/{club_id}/answer")
public BaseResponse<ClubAnswerListResponse> 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<Void> likeClub(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,19 @@ 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 @@ -10,4 +10,6 @@ public interface ClubAnswerRepository extends JpaRepository<ClubAnswer, Long> {
List<ClubAnswer> findByMemberId(Long memberId);

List<ClubAnswer> findByMemberIdAndClubId(Long memberId, Long clubId);

List<ClubAnswer> findAllByClubId(Long clubId);
}
Original file line number Diff line number Diff line change
@@ -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<String> answer,
Integer qorders
) {
}
18 changes: 18 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,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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -202,4 +205,19 @@ public ClubQuestionResponse findQuestion(MemberDetails memberDetails, Long clubI
}

}

public ClubAnswerListResponse findAnswer(MemberDetails memberDetails, Long clubId) {
Long memberId = memberDetails.getId();

List<ClubAnswer> answers = clubAnswerRepository.findAllByClubId(clubId);
Optional<Club> clubOptional = clubRepository.findById(clubId);

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

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

0 comments on commit db1261f

Please sign in to comment.