Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SAMBAD-246] 모임원의 답변 목록 조회 기능 구현 #97

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.List;

import org.depromeet.sambad.moring.meeting.answer.domain.MeetingAnswer;
import org.depromeet.sambad.moring.meeting.answer.presentation.response.MyMeetingAnswerListResponse;
import org.depromeet.sambad.moring.meeting.answer.presentation.response.MeetingAnswerListResponse;
import org.depromeet.sambad.moring.meeting.member.domain.MeetingMember;

public interface MeetingAnswerRepository {
Expand All @@ -20,5 +20,5 @@ public interface MeetingAnswerRepository {

List<MeetingMember> findMeetingMembersSelectWith(Long meetingQuestionId, List<Long> answerIds);

MyMeetingAnswerListResponse findAllByMeetingMemberId(Long meetingMemberId);
MeetingAnswerListResponse findAllByMeetingMemberId(Long meetingMemberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import org.depromeet.sambad.moring.meeting.answer.domain.MeetingAnswer;
import org.depromeet.sambad.moring.meeting.answer.presentation.exception.DuplicateMeetingAnswerException;
import org.depromeet.sambad.moring.meeting.answer.presentation.request.MeetingAnswerRequest;
import org.depromeet.sambad.moring.meeting.answer.presentation.response.MyMeetingAnswerListResponse;
import org.depromeet.sambad.moring.meeting.answer.presentation.response.MeetingAnswerListResponse;
import org.depromeet.sambad.moring.meeting.member.application.MeetingMemberService;
import org.depromeet.sambad.moring.meeting.member.domain.MeetingMember;
import org.depromeet.sambad.moring.meeting.member.domain.MeetingMemberValidator;
import org.depromeet.sambad.moring.meeting.question.application.MeetingQuestionRepository;
import org.depromeet.sambad.moring.meeting.question.application.MeetingQuestionService;
import org.depromeet.sambad.moring.meeting.question.domain.MeetingQuestion;
Expand All @@ -35,6 +36,8 @@ public class MeetingAnswerService {
private final AnswerService answerService;
private final EventService eventService;

private final MeetingMemberValidator meetingMemberValidator;

private final Clock clock;

@Transactional
Expand All @@ -52,11 +55,17 @@ public void save(Long userId, Long meetingId, Long meetingQuestionId, MeetingAns
advanceToNextQuestionIfAllAnswered(meetingId, meetingQuestion);
}

public MyMeetingAnswerListResponse getMyList(Long userId, Long meetingId) {
public MeetingAnswerListResponse getListByMe(Long userId, Long meetingId) {
MeetingMember loginMember = meetingMemberService.getByUserIdAndMeetingId(userId, meetingId);
return meetingAnswerRepository.findAllByMeetingMemberId(loginMember.getId());
}

public MeetingAnswerListResponse getListByMember(Long userId, Long meetingId, Long targetMemberId) {
meetingMemberValidator.validateUserIsMemberOfMeeting(userId, meetingId);
meetingMemberValidator.validateMemberIsMemberOfMeeting(targetMemberId, meetingId);
return meetingAnswerRepository.findAllByMeetingMemberId(targetMemberId);
}

private void saveMeetingAnswers(MeetingQuestion meetingQuestion, MeetingMember loginMember, List<Long> answerIds) {
Long questionId = meetingQuestion.getQuestion().getId();
List<MeetingAnswer> meetingAnswers = answerIds.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.depromeet.sambad.moring.answer.domain.Answer;
import org.depromeet.sambad.moring.meeting.answer.domain.MeetingAnswer;
import org.depromeet.sambad.moring.meeting.answer.infrastructure.dto.MyMeetingAnswerResponseCustom;
import org.depromeet.sambad.moring.meeting.answer.presentation.response.MyMeetingAnswerListResponse;
import org.depromeet.sambad.moring.meeting.answer.presentation.response.MeetingAnswerListResponse;
import org.depromeet.sambad.moring.meeting.member.domain.MeetingMember;
import org.depromeet.sambad.moring.meeting.question.domain.MeetingQuestion;
import org.springframework.stereotype.Repository;
Expand Down Expand Up @@ -88,7 +88,7 @@ public List<MeetingMember> findMeetingMembersSelectWith(Long meetingQuestionId,
.toList();
}

public MyMeetingAnswerListResponse findAllByMeetingMemberId(Long meetingMemberId) {
public MeetingAnswerListResponse findAllByMeetingMemberId(Long meetingMemberId) {
List<MeetingQuestion> meetingQuestions = queryFactory.select(meetingQuestion)
.from(meetingQuestion)
.join(meetingAnswer).on(meetingQuestion.eq(meetingAnswer.meetingQuestion)).fetchJoin()
Expand All @@ -103,7 +103,7 @@ public MyMeetingAnswerListResponse findAllByMeetingMemberId(Long meetingMemberId
getMyComment(meetingMemberId, question)))
.toList();

return MyMeetingAnswerListResponse.from(responseCustoms);
return MeetingAnswerListResponse.from(responseCustoms);
}

private List<Answer> getMyAnswers(Long memberId, MeetingQuestion meetingQuestion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.depromeet.sambad.moring.meeting.answer.application.MeetingAnswerRepository;
import org.depromeet.sambad.moring.meeting.answer.domain.MeetingAnswer;
import org.depromeet.sambad.moring.meeting.answer.presentation.response.MyMeetingAnswerListResponse;
import org.depromeet.sambad.moring.meeting.answer.presentation.response.MeetingAnswerListResponse;
import org.depromeet.sambad.moring.meeting.member.domain.MeetingMember;
import org.springframework.stereotype.Repository;

Expand Down Expand Up @@ -49,7 +49,7 @@ public List<MeetingMember> findMeetingMembersSelectWith(Long meetingQuestionId,
}

@Override
public MyMeetingAnswerListResponse findAllByMeetingMemberId(Long meetingMemberId) {
public MeetingAnswerListResponse findAllByMeetingMemberId(Long meetingMemberId) {
return meetingAnswerQueryRepository.findAllByMeetingMemberId(meetingMemberId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.depromeet.sambad.moring.meeting.answer.application.MeetingAnswerResultService;
import org.depromeet.sambad.moring.meeting.answer.application.MeetingAnswerService;
import org.depromeet.sambad.moring.meeting.answer.presentation.request.MeetingAnswerRequest;
import org.depromeet.sambad.moring.meeting.answer.presentation.response.MyMeetingAnswerListResponse;
import org.depromeet.sambad.moring.meeting.answer.presentation.response.MeetingAnswerListResponse;
import org.depromeet.sambad.moring.meeting.answer.presentation.response.SelectedAnswerResponse;
import org.depromeet.sambad.moring.user.presentation.resolver.UserId;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -61,11 +61,30 @@ public ResponseEntity<Object> save(
@ApiResponse(responseCode = "403", description = "USER_NOT_MEMBER_OF_MEETING")
})
@GetMapping("/meetings/{meetingId}/questions/answers/me")
public ResponseEntity<MyMeetingAnswerListResponse> findMyList(
public ResponseEntity<MeetingAnswerListResponse> findMyList(
@UserId Long userId,
@Parameter(description = "모임 ID", example = "1", required = true) @PathVariable("meetingId") Long meetingId
) {
MyMeetingAnswerListResponse response = meetingAnswerService.getMyList(userId, meetingId);
MeetingAnswerListResponse response = meetingAnswerService.getListByMe(userId, meetingId);
return ResponseEntity.ok(response);
}

@Operation(summary = "모임원이 작성한 모든 질문의 답변 리스트 조회", description =
"- 프로필 페이지 내 릴레이 질문 영역 조회 시 사용합니다.\n"
+ "- 생성 순으로 오름차순 정렬하여 반환합니다.\n"
+ "- 답변이 없다면, content는 빈 배열 [] 을 반환합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "403", description = "USER_NOT_MEMBER_OF_MEETING"),
@ApiResponse(responseCode = "404", description = "MEETING_MEMBER_NOT_FOUND")
})
@GetMapping("/meetings/{meetingId}/members/{memberId}/questions/answers")
public ResponseEntity<MeetingAnswerListResponse> findMemberList(
@UserId Long userId,
@Parameter(description = "모임 ID", example = "1", required = true) @PathVariable("meetingId") Long meetingId,
@Parameter(description = "타겟 모임원 ID", example = "1", required = true) @PathVariable("memberId") Long memberId
) {
MeetingAnswerListResponse response = meetingAnswerService.getListByMember(userId, meetingId, memberId);
return ResponseEntity.ok(response);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.depromeet.sambad.moring.meeting.answer.presentation.response;

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.*;

import java.util.List;

import org.depromeet.sambad.moring.meeting.answer.infrastructure.dto.MyMeetingAnswerResponseCustom;

import io.swagger.v3.oas.annotations.media.Schema;

public record MeetingAnswerListResponse(
@Schema(description = "작성한 답변 목록", requiredMode = REQUIRED)
List<MeetingAnswerListResponseDetail> contents
) {

public static MeetingAnswerListResponse from(List<MyMeetingAnswerResponseCustom> content) {
return new MeetingAnswerListResponse(MeetingAnswerListResponseDetail.from(content));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import io.swagger.v3.oas.annotations.media.Schema;

public record MyMeetingAnswerListResponseDetail(
public record MeetingAnswerListResponseDetail(
@Schema(title = "질문 인덱스", example = "1", requiredMode = REQUIRED)
int idx,

Expand All @@ -24,11 +24,11 @@ public record MyMeetingAnswerListResponseDetail(
String commentContent
) {

public static List<MyMeetingAnswerListResponseDetail> from(List<MyMeetingAnswerResponseCustom> responseCustoms) {
public static List<MeetingAnswerListResponseDetail> from(List<MyMeetingAnswerResponseCustom> responseCustoms) {
return IntStream.range(0, responseCustoms.size())
.mapToObj(i -> {
MyMeetingAnswerResponseCustom response = responseCustoms.get(i);
return new MyMeetingAnswerListResponseDetail(
return new MeetingAnswerListResponseDetail(
i + 1,
response.meetingQuestionTitle(),
response.getMeetingAnswers(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.depromeet.sambad.moring.meeting.member.application;

import static org.depromeet.sambad.moring.event.domain.EventType.*;

import java.time.LocalDateTime;
import java.util.List;

Expand Down Expand Up @@ -28,9 +30,6 @@

import lombok.RequiredArgsConstructor;

import static org.depromeet.sambad.moring.event.domain.EventType.QUESTION_REGISTERED;
import static org.depromeet.sambad.moring.event.domain.EventType.TARGET_MEMBER;

@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.depromeet.sambad.moring.meeting.member.presentation.exception.ExceedMaxMemberCountException;
import org.depromeet.sambad.moring.meeting.member.presentation.exception.ExceedMaxOwnerCountException;
import org.depromeet.sambad.moring.meeting.member.presentation.exception.MeetingMemberAlreadyExistsException;
import org.depromeet.sambad.moring.meeting.member.presentation.exception.MeetingMemberNotFoundException;
import org.depromeet.sambad.moring.meeting.member.presentation.exception.UserNotMemberOfMeetingException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -56,4 +57,10 @@ public void validateUserIsMemberOfMeeting(Long userId, Long meetingId) {
throw new UserNotMemberOfMeetingException();
}
}

public void validateMemberIsMemberOfMeeting(Long memberId, Long meetingId) {
if (!meetingMemberRepository.isUserMemberOfMeeting(memberId, meetingId)) {
throw new MeetingMemberNotFoundException();
}
}
}
Loading