diff --git a/src/main/java/info/pionas/quiz/domain/exam/ExamServiceImpl.java b/src/main/java/info/pionas/quiz/domain/exam/ExamServiceImpl.java index aaa8558..2ddacc0 100644 --- a/src/main/java/info/pionas/quiz/domain/exam/ExamServiceImpl.java +++ b/src/main/java/info/pionas/quiz/domain/exam/ExamServiceImpl.java @@ -61,11 +61,9 @@ private List getExamAnswers(UUID resultId, List a } private NewExamAnswer prepareNewExamAnswer(UUID resultId, PassExamAnswer answer, LocalDateTime dateTime) { - if (quizAnswerRepository.isCorrectAnswer(answer.getQuestionId(), answer.getAnswerId())) { - return NewExamAnswer.correct(resultId, dateTime, answer.getQuestionId(), answer.getAnswerId()); - } else { - return NewExamAnswer.wrong(resultId, dateTime, answer.getQuestionId(), answer.getAnswerId()); - } + final var correctAnswer = quizAnswerRepository.isCorrectAnswer(answer.getQuestionId(), answer.getAnswerId()); + return new NewExamAnswer(resultId, answer.getQuestionId(), answer.getAnswerId(), correctAnswer, dateTime); + } } diff --git a/src/main/java/info/pionas/quiz/domain/exam/api/NewExamAnswer.java b/src/main/java/info/pionas/quiz/domain/exam/api/NewExamAnswer.java index 901e595..3684389 100644 --- a/src/main/java/info/pionas/quiz/domain/exam/api/NewExamAnswer.java +++ b/src/main/java/info/pionas/quiz/domain/exam/api/NewExamAnswer.java @@ -1,13 +1,13 @@ package info.pionas.quiz.domain.exam.api; -import lombok.Builder; +import lombok.AllArgsConstructor; import lombok.Getter; import java.time.LocalDateTime; import java.util.UUID; -@Builder @Getter +@AllArgsConstructor public class NewExamAnswer { private UUID resultId; @@ -15,24 +15,4 @@ public class NewExamAnswer { private UUID answerId; private Boolean correct; private LocalDateTime created; - - public static NewExamAnswer correct(UUID resultId, LocalDateTime dateTime, UUID questionId, UUID answerId) { - return NewExamAnswer.builder() - .resultId(resultId) - .questionId(questionId) - .answerId(answerId) - .correct(true) - .created(dateTime) - .build(); - } - - public static NewExamAnswer wrong(UUID resultId, LocalDateTime dateTime, UUID questionId, UUID answerId) { - return NewExamAnswer.builder() - .resultId(resultId) - .questionId(questionId) - .answerId(answerId) - .correct(false) - .created(dateTime) - .build(); - } }