diff --git a/src/main/java/org/depromeet/sambad/moring/meeting/answer/application/MeetingAnswerService.java b/src/main/java/org/depromeet/sambad/moring/meeting/answer/application/MeetingAnswerService.java index c0db23b5..3c93d31c 100644 --- a/src/main/java/org/depromeet/sambad/moring/meeting/answer/application/MeetingAnswerService.java +++ b/src/main/java/org/depromeet/sambad/moring/meeting/answer/application/MeetingAnswerService.java @@ -41,21 +41,36 @@ public class MeetingAnswerService { public void save(Long userId, Long meetingId, Long meetingQuestionId, MeetingAnswerRequest request) { MeetingMember loginMember = meetingMemberService.getByUserIdAndMeetingId(userId, meetingId); MeetingQuestion meetingQuestion = meetingQuestionService.getById(meetingId, meetingQuestionId); - Long questionId = meetingQuestion.getQuestion().getId(); meetingQuestion.validateNotFinished(LocalDateTime.now(clock)); validateNonDuplicateMeetingAnswer(meetingQuestion.getId(), loginMember.getId()); meetingQuestion.validateMeetingAnswerCount(request.answerIds().size()); - List answerIds = request.answerIds(); + saveMeetingAnswers(meetingQuestion, loginMember, request.answerIds()); + + eventService.inactivateLastEventByType(userId, meetingId, QUESTION_REGISTERED); + advanceToNextQuestionIfAllAnswered(meetingId, meetingQuestion); + } + + public MyMeetingAnswerListResponse getMyList(Long userId, Long meetingId) { + MeetingMember loginMember = meetingMemberService.getByUserIdAndMeetingId(userId, meetingId); + return meetingAnswerRepository.findAllByMeetingMemberId(loginMember.getId()); + } + + private void saveMeetingAnswers(MeetingQuestion meetingQuestion, MeetingMember loginMember, List answerIds) { + Long questionId = meetingQuestion.getQuestion().getId(); List meetingAnswers = answerIds.stream() .map(answerId -> answerService.getById(questionId, answerId)) .map(answer -> new MeetingAnswer(meetingQuestion, answer, loginMember)) .toList(); meetingAnswers.forEach(meetingAnswerRepository::save); + } - eventService.inactivateLastEventByType(userId, meetingId, QUESTION_REGISTERED); - advanceToNextQuestionIfAllAnswered(meetingId, meetingQuestion); + private void validateNonDuplicateMeetingAnswer(Long meetingQuestionId, Long meetingMemberId) { + boolean exists = meetingAnswerRepository.existsByMeetingMember(meetingQuestionId, meetingMemberId); + if (exists) { + throw new DuplicateMeetingAnswerException(); + } } private void advanceToNextQuestionIfAllAnswered(Long meetingId, MeetingQuestion currentQuestion) { @@ -72,16 +87,4 @@ private void advanceToNextQuestionIfAllAnswered(Long meetingId, MeetingQuestion }); } } - - public MyMeetingAnswerListResponse getMyList(Long userId, Long meetingId) { - MeetingMember loginMember = meetingMemberService.getByUserIdAndMeetingId(userId, meetingId); - return meetingAnswerRepository.findAllByMeetingMemberId(loginMember.getId()); - } - - private void validateNonDuplicateMeetingAnswer(Long meetingQuestionId, Long meetingMemberId) { - boolean exists = meetingAnswerRepository.existsByMeetingMember(meetingQuestionId, meetingMemberId); - if (exists) { - throw new DuplicateMeetingAnswerException(); - } - } } \ No newline at end of file