From 159233c71a988951ba35999e8d2f52e2d5551022 Mon Sep 17 00:00:00 2001 From: nahyeon99 Date: Wed, 7 Aug 2024 16:51:43 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=AA=A8=EC=9E=84=EC=9B=90=20?= =?UTF-8?q?=EB=8B=B5=EB=B3=80=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=B6=84=EB=A6=AC=20?= =?UTF-8?q?(=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/MeetingAnswerService.java | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) 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