Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pionas committed Dec 18, 2023
1 parent ff736fc commit 7f9d761
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ private List<NewExamAnswer> getExamAnswers(UUID resultId, List<PassExamAnswer> 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);

}

}
24 changes: 2 additions & 22 deletions src/main/java/info/pionas/quiz/domain/exam/api/NewExamAnswer.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,18 @@
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;
private UUID questionId;
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();
}
}

0 comments on commit 7f9d761

Please sign in to comment.