diff --git a/api/src/main/java/lab/en2b/quizapi/commons/utils/GameModeUtils.java b/api/src/main/java/lab/en2b/quizapi/commons/utils/GameModeUtils.java index 4e6c2886..eaf16af9 100644 --- a/api/src/main/java/lab/en2b/quizapi/commons/utils/GameModeUtils.java +++ b/api/src/main/java/lab/en2b/quizapi/commons/utils/GameModeUtils.java @@ -3,6 +3,7 @@ import lab.en2b.quizapi.game.Game; import lab.en2b.quizapi.game.GameMode; import lab.en2b.quizapi.questions.question.QuestionCategory; +import lab.en2b.quizapi.questions.question.dtos.QuestionCategoryDto; import java.util.List; @@ -54,4 +55,71 @@ public static void setGamemodeParams(Game game){ game.setRoundDuration(30); } } + + public static List getQuestionCategories(String lang) { + if(lang == null) + lang = "en"; + if(lang.equals("en")) + return getQuestionCategoriesEn(); + return getQuestionCategoriesEs(); + } + private static List getQuestionCategoriesEn(){ + return List.of( + QuestionCategoryDto.builder() + .name("Art") + .description("Are you an art expert? Prove it!") + .internalRepresentation(QuestionCategory.ART) + .build(), + QuestionCategoryDto.builder() + .name("Music") + .description("Are you a music lover? Prove it!") + .internalRepresentation(QuestionCategory.MUSIC) + .build(), + QuestionCategoryDto.builder() + .name("Geography") + .description("Are you a geography expert? Prove it!") + .internalRepresentation(QuestionCategory.GEOGRAPHY) + .build(), + QuestionCategoryDto.builder() + .name("Sports") + .description("Are you a sports fanatic? Prove it!") + .internalRepresentation(QuestionCategory.SPORTS) + .build(), + QuestionCategoryDto.builder() + .name("Video Games") + .description("Are you a gamer? Prove it!") + .internalRepresentation(QuestionCategory.VIDEOGAMES) + .build() + ); + } + + private static List getQuestionCategoriesEs(){ + return List.of( + QuestionCategoryDto.builder() + .name("Arte") + .description("¿Eres un experto en arte? ¡Demuéstralo!") + .internalRepresentation(QuestionCategory.ART) + .build(), + QuestionCategoryDto.builder() + .name("Música") + .description("¿Eres un melómano? ¡Demuéstralo!") + .internalRepresentation(QuestionCategory.MUSIC) + .build(), + QuestionCategoryDto.builder() + .name("Geografía") + .description("¿Eres un experto en geografía? ¡Demuéstralo!") + .internalRepresentation(QuestionCategory.GEOGRAPHY) + .build(), + QuestionCategoryDto.builder() + .name("Deportes") + .description("¿Eres un fanático de los deportes? ¡Demuéstralo!") + .internalRepresentation(QuestionCategory.SPORTS) + .build(), + QuestionCategoryDto.builder() + .name("Videojuegos") + .description("¿Eres un gamer? ¡Demuéstralo!") + .internalRepresentation(QuestionCategory.VIDEOGAMES) + .build() + ); + } } diff --git a/api/src/main/java/lab/en2b/quizapi/game/GameController.java b/api/src/main/java/lab/en2b/quizapi/game/GameController.java index 3192b857..99c1d872 100644 --- a/api/src/main/java/lab/en2b/quizapi/game/GameController.java +++ b/api/src/main/java/lab/en2b/quizapi/game/GameController.java @@ -8,6 +8,7 @@ import jakarta.validation.Valid; import lab.en2b.quizapi.game.dtos.*; import lab.en2b.quizapi.questions.question.QuestionCategory; +import lab.en2b.quizapi.questions.question.dtos.QuestionCategoryDto; import lab.en2b.quizapi.questions.question.dtos.QuestionResponseDto; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -133,8 +134,8 @@ public ResponseEntity> getQuestionGameModes(){ @ApiResponse(responseCode = "403", description = "You are not logged in", content = @io.swagger.v3.oas.annotations.media.Content) }) @GetMapping("/question-categories") - public ResponseEntity> getQuestionCategories(){ - return ResponseEntity.ok(gameService.getQuestionCategories()); + public ResponseEntity> getQuestionCategories(@RequestParam(required = false) String lang){ + return ResponseEntity.ok(gameService.getQuestionCategories(lang)); } } diff --git a/api/src/main/java/lab/en2b/quizapi/game/GameService.java b/api/src/main/java/lab/en2b/quizapi/game/GameService.java index 54eb2a9e..36b9d8a1 100644 --- a/api/src/main/java/lab/en2b/quizapi/game/GameService.java +++ b/api/src/main/java/lab/en2b/quizapi/game/GameService.java @@ -1,10 +1,12 @@ package lab.en2b.quizapi.game; import lab.en2b.quizapi.commons.user.UserService; +import lab.en2b.quizapi.commons.utils.GameModeUtils; import lab.en2b.quizapi.game.dtos.*; import lab.en2b.quizapi.game.mappers.GameResponseDtoMapper; import lab.en2b.quizapi.questions.question.QuestionCategory; import lab.en2b.quizapi.questions.question.QuestionService; +import lab.en2b.quizapi.questions.question.dtos.QuestionCategoryDto; import lab.en2b.quizapi.questions.question.dtos.QuestionResponseDto; import lab.en2b.quizapi.questions.question.mappers.QuestionResponseDtoMapper; import lab.en2b.quizapi.statistics.Statistics; @@ -151,8 +153,8 @@ public GameResponseDto getGameDetails(Long id, Authentication authentication) { return gameResponseDtoMapper.apply(game); } - public List getQuestionCategories() { - return Arrays.asList(QuestionCategory.values()); + public List getQuestionCategories(String lang) { + return GameModeUtils.getQuestionCategories(lang); } private boolean wasGameMeantToBeOver(Game game) { diff --git a/api/src/main/java/lab/en2b/quizapi/questions/question/dtos/QuestionCategoryDto.java b/api/src/main/java/lab/en2b/quizapi/questions/question/dtos/QuestionCategoryDto.java new file mode 100644 index 00000000..3d9180b4 --- /dev/null +++ b/api/src/main/java/lab/en2b/quizapi/questions/question/dtos/QuestionCategoryDto.java @@ -0,0 +1,21 @@ +package lab.en2b.quizapi.questions.question.dtos; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lab.en2b.quizapi.questions.question.QuestionCategory; +import lombok.*; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +@Builder +@Setter +public class QuestionCategoryDto { + @Schema(description = "Beautified name of the question category",example = "Sports") + private String name; + @Schema(description = "Description of the question category",example = "Test description of the question category") + private String description; + @JsonProperty("internal_representation") + @Schema(description = "Internal code used for describing the question category",example = "SPORTS") + private QuestionCategory internalRepresentation; +} diff --git a/api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java b/api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java index 5063486b..ef3d483a 100644 --- a/api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java +++ b/api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java @@ -468,7 +468,7 @@ public void getGameDetailsInvalidId(){ @Test public void testGetQuestionCategories(){ - assertEquals(Arrays.asList(QuestionCategory.values()), gameService.getQuestionCategories()); + assertEquals(QuestionCategory.values().length, gameService.getQuestionCategories(null).size()); } @Test