diff --git a/src/main/java/info/pionas/quiz/api/quiz/AnswerDto.java b/src/main/java/info/pionas/quiz/api/quiz/AnswerResponseDto.java similarity index 90% rename from src/main/java/info/pionas/quiz/api/quiz/AnswerDto.java rename to src/main/java/info/pionas/quiz/api/quiz/AnswerResponseDto.java index f2cfa82..802678d 100644 --- a/src/main/java/info/pionas/quiz/api/quiz/AnswerDto.java +++ b/src/main/java/info/pionas/quiz/api/quiz/AnswerResponseDto.java @@ -9,7 +9,7 @@ @NoArgsConstructor @Getter @Setter -class AnswerDto { +class AnswerResponseDto { private UUID id; private String content; diff --git a/src/main/java/info/pionas/quiz/api/quiz/QuestionDto.java b/src/main/java/info/pionas/quiz/api/quiz/QuestionResponseDto.java similarity index 77% rename from src/main/java/info/pionas/quiz/api/quiz/QuestionDto.java rename to src/main/java/info/pionas/quiz/api/quiz/QuestionResponseDto.java index e3fb635..2d9374d 100644 --- a/src/main/java/info/pionas/quiz/api/quiz/QuestionDto.java +++ b/src/main/java/info/pionas/quiz/api/quiz/QuestionResponseDto.java @@ -10,9 +10,9 @@ @NoArgsConstructor @Getter @Setter -class QuestionDto { +class QuestionResponseDto { private UUID id; private String content; - private List answers; + private List answers; } diff --git a/src/main/java/info/pionas/quiz/api/quiz/QuizApiMapper.java b/src/main/java/info/pionas/quiz/api/quiz/QuizApiMapper.java index cc726b7..e06da32 100644 --- a/src/main/java/info/pionas/quiz/api/quiz/QuizApiMapper.java +++ b/src/main/java/info/pionas/quiz/api/quiz/QuizApiMapper.java @@ -14,9 +14,9 @@ interface QuizApiMapper { QuizResponseDto map(Quiz quiz); - QuestionDto map(Question question); + QuestionResponseDto map(Question question); - AnswerDto map(Answer answer); + AnswerResponseDto map(Answer answer); UpdateQuestion map(UpdateQuestionDto updateQuestionDto); diff --git a/src/main/java/info/pionas/quiz/api/quiz/QuizResponseDto.java b/src/main/java/info/pionas/quiz/api/quiz/QuizResponseDto.java index 38ffbf8..fe4c76c 100644 --- a/src/main/java/info/pionas/quiz/api/quiz/QuizResponseDto.java +++ b/src/main/java/info/pionas/quiz/api/quiz/QuizResponseDto.java @@ -16,5 +16,5 @@ class QuizResponseDto { private UUID id; private String title; private String description; - private List questions = new ArrayList<>(); + private List questions = new ArrayList<>(); } diff --git a/src/main/java/info/pionas/quiz/api/quiz/QuizRestController.java b/src/main/java/info/pionas/quiz/api/quiz/QuizRestController.java index b411bd1..3f22f7f 100644 --- a/src/main/java/info/pionas/quiz/api/quiz/QuizRestController.java +++ b/src/main/java/info/pionas/quiz/api/quiz/QuizRestController.java @@ -1,6 +1,6 @@ package info.pionas.quiz.api.quiz; -import info.pionas.quiz.domain.quiz.QuizService; +import info.pionas.quiz.domain.quiz.api.QuizService; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; diff --git a/src/main/java/info/pionas/quiz/domain/quiz/QuizServiceImpl.java b/src/main/java/info/pionas/quiz/domain/quiz/QuizServiceImpl.java index 3ecdbdb..063985a 100644 --- a/src/main/java/info/pionas/quiz/domain/quiz/QuizServiceImpl.java +++ b/src/main/java/info/pionas/quiz/domain/quiz/QuizServiceImpl.java @@ -1,9 +1,6 @@ package info.pionas.quiz.domain.quiz; -import info.pionas.quiz.domain.quiz.api.NewQuestion; -import info.pionas.quiz.domain.quiz.api.NewQuiz; -import info.pionas.quiz.domain.quiz.api.Quiz; -import info.pionas.quiz.domain.quiz.api.UpdateQuestion; +import info.pionas.quiz.domain.quiz.api.*; import info.pionas.quiz.domain.shared.UuidGenerator; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/info/pionas/quiz/domain/quiz/QuizRepository.java b/src/main/java/info/pionas/quiz/domain/quiz/api/QuizRepository.java similarity index 64% rename from src/main/java/info/pionas/quiz/domain/quiz/QuizRepository.java rename to src/main/java/info/pionas/quiz/domain/quiz/api/QuizRepository.java index e5f2691..b3f16b0 100644 --- a/src/main/java/info/pionas/quiz/domain/quiz/QuizRepository.java +++ b/src/main/java/info/pionas/quiz/domain/quiz/api/QuizRepository.java @@ -1,6 +1,4 @@ -package info.pionas.quiz.domain.quiz; - -import info.pionas.quiz.domain.quiz.api.Quiz; +package info.pionas.quiz.domain.quiz.api; import java.util.Optional; import java.util.UUID; diff --git a/src/main/java/info/pionas/quiz/domain/quiz/QuizService.java b/src/main/java/info/pionas/quiz/domain/quiz/api/QuizService.java similarity index 54% rename from src/main/java/info/pionas/quiz/domain/quiz/QuizService.java rename to src/main/java/info/pionas/quiz/domain/quiz/api/QuizService.java index 9c3a2ff..a7c989e 100644 --- a/src/main/java/info/pionas/quiz/domain/quiz/QuizService.java +++ b/src/main/java/info/pionas/quiz/domain/quiz/api/QuizService.java @@ -1,9 +1,4 @@ -package info.pionas.quiz.domain.quiz; - -import info.pionas.quiz.domain.quiz.api.NewQuestion; -import info.pionas.quiz.domain.quiz.api.NewQuiz; -import info.pionas.quiz.domain.quiz.api.Quiz; -import info.pionas.quiz.domain.quiz.api.UpdateQuestion; +package info.pionas.quiz.domain.quiz.api; import java.util.UUID; diff --git a/src/main/java/info/pionas/quiz/domain/quiz/QuizJpaMapper.java b/src/main/java/info/pionas/quiz/infrastructure/database/quiz/QuizJpaMapper.java similarity index 71% rename from src/main/java/info/pionas/quiz/domain/quiz/QuizJpaMapper.java rename to src/main/java/info/pionas/quiz/infrastructure/database/quiz/QuizJpaMapper.java index 6ee06bc..edb526e 100644 --- a/src/main/java/info/pionas/quiz/domain/quiz/QuizJpaMapper.java +++ b/src/main/java/info/pionas/quiz/infrastructure/database/quiz/QuizJpaMapper.java @@ -1,11 +1,8 @@ -package info.pionas.quiz.domain.quiz; +package info.pionas.quiz.infrastructure.database.quiz; import info.pionas.quiz.domain.quiz.api.Answer; import info.pionas.quiz.domain.quiz.api.Question; import info.pionas.quiz.domain.quiz.api.Quiz; -import info.pionas.quiz.infrastructure.database.quiz.AnswerEntity; -import info.pionas.quiz.infrastructure.database.quiz.QuestionEntity; -import info.pionas.quiz.infrastructure.database.quiz.QuizEntity; import org.mapstruct.Mapper; import org.mapstruct.Mapping; diff --git a/src/main/java/info/pionas/quiz/domain/quiz/QuizJpaRepository.java b/src/main/java/info/pionas/quiz/infrastructure/database/quiz/QuizJpaRepository.java similarity index 68% rename from src/main/java/info/pionas/quiz/domain/quiz/QuizJpaRepository.java rename to src/main/java/info/pionas/quiz/infrastructure/database/quiz/QuizJpaRepository.java index b81f653..c5ce4d1 100644 --- a/src/main/java/info/pionas/quiz/domain/quiz/QuizJpaRepository.java +++ b/src/main/java/info/pionas/quiz/infrastructure/database/quiz/QuizJpaRepository.java @@ -1,6 +1,5 @@ -package info.pionas.quiz.domain.quiz; +package info.pionas.quiz.infrastructure.database.quiz; -import info.pionas.quiz.infrastructure.database.quiz.QuizEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/src/main/java/info/pionas/quiz/domain/quiz/QuizRepositoryImpl.java b/src/main/java/info/pionas/quiz/infrastructure/database/quiz/QuizRepositoryImpl.java similarity index 85% rename from src/main/java/info/pionas/quiz/domain/quiz/QuizRepositoryImpl.java rename to src/main/java/info/pionas/quiz/infrastructure/database/quiz/QuizRepositoryImpl.java index bc3e736..981a817 100644 --- a/src/main/java/info/pionas/quiz/domain/quiz/QuizRepositoryImpl.java +++ b/src/main/java/info/pionas/quiz/infrastructure/database/quiz/QuizRepositoryImpl.java @@ -1,6 +1,7 @@ -package info.pionas.quiz.domain.quiz; +package info.pionas.quiz.infrastructure.database.quiz; import info.pionas.quiz.domain.quiz.api.Quiz; +import info.pionas.quiz.domain.quiz.api.QuizRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; diff --git a/src/test/java/info/pionas/quiz/api/quiz/QuizRestControllerIT.java b/src/test/java/info/pionas/quiz/api/quiz/QuizRestControllerIT.java index d77b56e..e8d00d4 100644 --- a/src/test/java/info/pionas/quiz/api/quiz/QuizRestControllerIT.java +++ b/src/test/java/info/pionas/quiz/api/quiz/QuizRestControllerIT.java @@ -53,7 +53,7 @@ void should_create_quiz() { assertThat(quizResponseDto).isNotNull(); assertThat(quizResponseDto.getTitle()).isEqualTo(newQuizDto.getTitle()); assertThat(quizResponseDto.getDescription()).isEqualTo(newQuizDto.getDescription()); - List questions = quizResponseDto.getQuestions(); + List questions = quizResponseDto.getQuestions(); assertThat(questions).hasSize(2); final var quizEntity = dbUtil.em().find(QuizEntity.class, quizResponseDto.getId()); assertThat(quizEntity).isNotNull(); @@ -80,7 +80,7 @@ void should_throw_forbidden_when_try_to_create_quiz() throws IOException { final var errors = StreamSupport .stream(errorJson.get("errors").spliterator(), false) .toList(); - assertThat(errors.get(0).asText()).isEqualTo("Access Denied"); + assertThat(errors.getFirst().asText()).isEqualTo("Access Denied"); } @Test @@ -102,7 +102,7 @@ void should_throw_bad_request_when_try_to_create_quiz() throws IOException { final var errors = StreamSupport .stream(errorJson.get("errors").spliterator(), false) .toList(); - assertThat(errors.get(0).asText()).isEqualTo("title: must not be blank"); + assertThat(errors.getFirst().asText()).isEqualTo("title: must not be blank"); } @Test @@ -139,19 +139,19 @@ void should_add_question_to_quiz() { assertThat(quizResponseDto.getDescription()).isEqualTo("This is first question without answers"); final var questions = quizResponseDto.getQuestions(); assertThat(questions).hasSize(1); - final var questionDto = questions.get(0); + final var questionDto = questions.getFirst(); assertThat(questionDto).isNotNull(); assertThat(questionDto.getContent()).isEqualTo(newQuestionDto.getContent()); final var answers = questionDto.getAnswers(); assertThat(answers).hasSize(2); - AnswerDto answerDto1 = answers.get(0); - assertThat(answerDto1).isNotNull(); - assertThat(answerDto1.getContent()).isEqualTo(newQuestionDto.getAnswers().get(0).getContent()); - assertThat(answerDto1.getCorrect()).isEqualTo(newQuestionDto.getAnswers().get(0).getCorrect()); - AnswerDto answerDto2 = answers.get(1); - assertThat(answerDto2).isNotNull(); - assertThat(answerDto2.getContent()).isEqualTo(newQuestionDto.getAnswers().get(1).getContent()); - assertThat(answerDto2.getCorrect()).isEqualTo(newQuestionDto.getAnswers().get(1).getCorrect()); + AnswerResponseDto answerResponseDto1 = answers.getFirst(); + assertThat(answerResponseDto1).isNotNull(); + assertThat(answerResponseDto1.getContent()).isEqualTo(newQuestionDto.getAnswers().getFirst().getContent()); + assertThat(answerResponseDto1.getCorrect()).isEqualTo(newQuestionDto.getAnswers().getFirst().getCorrect()); + AnswerResponseDto answerResponseDto2 = answers.get(1); + assertThat(answerResponseDto2).isNotNull(); + assertThat(answerResponseDto2.getContent()).isEqualTo(newQuestionDto.getAnswers().get(1).getContent()); + assertThat(answerResponseDto2.getCorrect()).isEqualTo(newQuestionDto.getAnswers().get(1).getCorrect()); final var quizEntity = dbUtil.em().find(QuizEntity.class, quizResponseDto.getId()); assertThat(quizEntity).isNotNull(); assertThat(quizEntity.getTitle()).isEqualTo("First question"); @@ -178,7 +178,7 @@ void should_throw_forbidden_when_try_to_add_question_to_quiz() throws IOExceptio final var errors = StreamSupport .stream(errorJson.get("errors").spliterator(), false) .toList(); - assertThat(errors.get(0).asText()).isEqualTo("Access Denied"); + assertThat(errors.getFirst().asText()).isEqualTo("Access Denied"); } @Test @@ -200,7 +200,7 @@ void should_throw_bad_request_when_try_to_add_answer_to_quiz() throws IOExceptio final var errors = StreamSupport .stream(errorJson.get("errors").spliterator(), false) .toList(); - assertThat(errors.get(0).asText()).isEqualTo("content: must not be blank"); + assertThat(errors.getFirst().asText()).isEqualTo("content: must not be blank"); } @Test @@ -222,7 +222,7 @@ void should_throw_not_found_when_try_add_question_but_quiz_by_id_not_exist() thr final var errors = StreamSupport .stream(errorJson.get("errors").spliterator(), false) .toList(); - assertThat(errors.get(0).asText()).isEqualTo("Quiz by ID b4a63897-60f7-4e94-846e-e199d8734144 not exist"); + assertThat(errors.getFirst().asText()).isEqualTo("Quiz by ID b4a63897-60f7-4e94-846e-e199d8734144 not exist"); } @Test @@ -277,7 +277,7 @@ void should_throw_forbidden_when_try_to_delete_question_from_quiz() throws IOExc final var errors = StreamSupport .stream(errorJson.get("errors").spliterator(), false) .toList(); - assertThat(errors.get(0).asText()).isEqualTo("Access Denied"); + assertThat(errors.getFirst().asText()).isEqualTo("Access Denied"); } @Test @@ -286,7 +286,6 @@ void should_throw_not_found_when_try_delete_question_but_quiz_by_id_not_exist() final var user = new User("admin", "admin", List.of(Role.ROLE_ADMIN)); //when final var response = webTestClient.delete().uri("/api/v1/quiz/b4a63897-60f7-4e94-846e-e199d8734144/question/ce703f5b-274c-4398-b855-d461887c7ed5") - .accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .header(HttpHeaders.AUTHORIZATION, "Bearer " + generateToken(user)) .exchange() @@ -298,7 +297,7 @@ void should_throw_not_found_when_try_delete_question_but_quiz_by_id_not_exist() final var errors = StreamSupport .stream(errorJson.get("errors").spliterator(), false) .toList(); - assertThat(errors.get(0).asText()).isEqualTo("Quiz by ID b4a63897-60f7-4e94-846e-e199d8734144 not exist"); + assertThat(errors.getFirst().asText()).isEqualTo("Quiz by ID b4a63897-60f7-4e94-846e-e199d8734144 not exist"); } @Test @@ -336,19 +335,19 @@ void should_update_question_from_quiz() { assertThat(quizResponseDto.getDescription()).isEqualTo("This is first question without answers"); final var questions = quizResponseDto.getQuestions(); assertThat(questions).hasSize(1); - final var questionDto = questions.get(0); + final var questionDto = questions.getFirst(); assertThat(questionDto).isNotNull(); assertThat(questionDto.getContent()).isEqualTo(updateQuestionDto.getContent()); final var answers = questionDto.getAnswers(); assertThat(answers).hasSize(2); - AnswerDto answerDto1 = answers.get(0); - assertThat(answerDto1).isNotNull(); - assertThat(answerDto1.getContent()).isEqualTo(updateQuestionDto.getAnswers().get(0).getContent()); - assertThat(answerDto1.getCorrect()).isEqualTo(updateQuestionDto.getAnswers().get(0).getCorrect()); - AnswerDto answerDto2 = answers.get(1); - assertThat(answerDto2).isNotNull(); - assertThat(answerDto2.getContent()).isEqualTo(updateQuestionDto.getAnswers().get(1).getContent()); - assertThat(answerDto2.getCorrect()).isEqualTo(updateQuestionDto.getAnswers().get(1).getCorrect()); + AnswerResponseDto answerResponseDto1 = answers.getFirst(); + assertThat(answerResponseDto1).isNotNull(); + assertThat(answerResponseDto1.getContent()).isEqualTo(updateQuestionDto.getAnswers().getFirst().getContent()); + assertThat(answerResponseDto1.getCorrect()).isEqualTo(updateQuestionDto.getAnswers().getFirst().getCorrect()); + AnswerResponseDto answerResponseDto2 = answers.get(1); + assertThat(answerResponseDto2).isNotNull(); + assertThat(answerResponseDto2.getContent()).isEqualTo(updateQuestionDto.getAnswers().get(1).getContent()); + assertThat(answerResponseDto2.getCorrect()).isEqualTo(updateQuestionDto.getAnswers().get(1).getCorrect()); final var questionEntity = dbUtil.em().find(QuestionEntity.class, questionId); assertThat(questionEntity).isNotNull(); assertThat(questionEntity.getContent()).isEqualTo(updateQuestionDto.getContent()); @@ -375,7 +374,7 @@ void should_throw_forbidden_when_try_to_update_question_to_quiz() throws IOExcep final var errors = StreamSupport .stream(errorJson.get("errors").spliterator(), false) .toList(); - assertThat(errors.get(0).asText()).isEqualTo("Access Denied"); + assertThat(errors.getFirst().asText()).isEqualTo("Access Denied"); } @Test @@ -399,7 +398,7 @@ void should_throw_bad_request_when_try_to_update_question_to_quiz() throws IOExc final var errors = StreamSupport .stream(errorJson.get("errors").spliterator(), false) .toList(); - assertThat(errors.get(0).asText()).isEqualTo("content: must not be blank"); + assertThat(errors.getFirst().asText()).isEqualTo("content: must not be blank"); } @Test @@ -422,7 +421,7 @@ void should_throw_not_found_when_quiz_by_id_not_exist() throws IOException { final var errors = StreamSupport .stream(errorJson.get("errors").spliterator(), false) .toList(); - assertThat(errors.get(0).asText()).isEqualTo("Quiz by ID b4a63897-60f7-4e94-846e-e199d8734144 not exist"); + assertThat(errors.getFirst().asText()).isEqualTo("Quiz by ID b4a63897-60f7-4e94-846e-e199d8734144 not exist"); } private NewQuizDto getNewQuizDto() {