diff --git a/src/main/java/com/uniovi/dto/AnswerDto.java b/src/main/java/com/uniovi/dto/AnswerDto.java index 42275777..0e0a8504 100644 --- a/src/main/java/com/uniovi/dto/AnswerDto.java +++ b/src/main/java/com/uniovi/dto/AnswerDto.java @@ -6,7 +6,6 @@ @Getter @Setter -@AllArgsConstructor @NoArgsConstructor @ToString public class AnswerDto { diff --git a/src/main/java/com/uniovi/dto/CategoryDto.java b/src/main/java/com/uniovi/dto/CategoryDto.java index 0d8325b5..fc87530e 100644 --- a/src/main/java/com/uniovi/dto/CategoryDto.java +++ b/src/main/java/com/uniovi/dto/CategoryDto.java @@ -10,7 +10,6 @@ @Getter @Setter -@AllArgsConstructor @NoArgsConstructor public class CategoryDto { diff --git a/src/main/java/com/uniovi/dto/PlayerDto.java b/src/main/java/com/uniovi/dto/PlayerDto.java index 149cb93f..0c550485 100644 --- a/src/main/java/com/uniovi/dto/PlayerDto.java +++ b/src/main/java/com/uniovi/dto/PlayerDto.java @@ -5,7 +5,6 @@ @Getter @Setter -@AllArgsConstructor @NoArgsConstructor @ToString public class PlayerDto { diff --git a/src/main/java/com/uniovi/dto/RoleDto.java b/src/main/java/com/uniovi/dto/RoleDto.java index 4b8244cf..719dd01d 100644 --- a/src/main/java/com/uniovi/dto/RoleDto.java +++ b/src/main/java/com/uniovi/dto/RoleDto.java @@ -4,10 +4,7 @@ import lombok.*; @Getter -@Setter @AllArgsConstructor -@NoArgsConstructor -@ToString public class RoleDto { @Schema(description = "The name of the role", example = "ROLE_USER") diff --git a/src/main/java/com/uniovi/services/InsertSampleDataService.java b/src/main/java/com/uniovi/services/InsertSampleDataService.java index b9ab6163..3386e26f 100644 --- a/src/main/java/com/uniovi/services/InsertSampleDataService.java +++ b/src/main/java/com/uniovi/services/InsertSampleDataService.java @@ -67,6 +67,12 @@ public void insertSampleQuestions() throws InterruptedException { generateSampleData(); } + @Transactional + public void generateTestQuestions() { + questionRepository.deleteAll(); + questionService.testQuestions(4); + } + @Transactional public void generateSampleData() throws InterruptedException { diff --git a/src/main/java/com/uniovi/services/QuestionService.java b/src/main/java/com/uniovi/services/QuestionService.java index f1776f4d..7eb7d422 100644 --- a/src/main/java/com/uniovi/services/QuestionService.java +++ b/src/main/java/com/uniovi/services/QuestionService.java @@ -87,7 +87,7 @@ public interface QuestionService { /** * Update a question - * @param q The question to update + * @param id The id of the question to update * @param questionDto The new data of the question */ void updateQuestion(Long id, QuestionDto questionDto); @@ -97,4 +97,12 @@ public interface QuestionService { * @param id The id of the question to delete */ void deleteQuestion(Long id); + + /** + * Get some test questions + * + * @param num The number of questions to get + * @return The questions selected + */ + List testQuestions(int num); } diff --git a/src/main/java/com/uniovi/services/RoleService.java b/src/main/java/com/uniovi/services/RoleService.java index ae094f14..e620105f 100644 --- a/src/main/java/com/uniovi/services/RoleService.java +++ b/src/main/java/com/uniovi/services/RoleService.java @@ -20,10 +20,4 @@ public interface RoleService { * @return The role with the given name */ Role getRole(String name); - - /** - * Get all the roles in the database - * @return A list with all the roles - */ - List getRoles(); } diff --git a/src/main/java/com/uniovi/services/impl/QuestionServiceImpl.java b/src/main/java/com/uniovi/services/impl/QuestionServiceImpl.java index 5eea3c07..f0ec9f7e 100644 --- a/src/main/java/com/uniovi/services/impl/QuestionServiceImpl.java +++ b/src/main/java/com/uniovi/services/impl/QuestionServiceImpl.java @@ -102,7 +102,7 @@ public List getRandomQuestions(int num) { List res = new ArrayList<>(); for (int i = 0; i < num; i++) { int idx = random.nextInt(allQuestions.size()); - while (allQuestions.get(idx).hasEmptyOptions()){ + while (allQuestions.get(idx).hasEmptyOptions() || res.contains(allQuestions.get(idx))){ idx = random.nextInt(allQuestions.size()); } res.add(allQuestions.get(idx)); @@ -170,4 +170,30 @@ public void deleteQuestion(Long id) { } } + @Override + public List testQuestions(int num) { + List res = new ArrayList<>(); + Category c = new Category("Test category", "Test category"); + categoryService.addNewCategory(c); + for (int i = 0; i < num; i++) { + Question q = new Question(); + q.setStatement("Test question " + i); + q.setLanguage(LocaleContextHolder.getLocale().getLanguage()); + Associations.QuestionsCategory.addCategory(q, c); + List answers = new ArrayList<>(); + for (int j = 0; j < 4; j++) { + Answer a = new Answer(); + a.setText("Test answer " + j); + a.setCorrect(j == 0); + if(j==0) q.setCorrectAnswer(a); + answerService.addNewAnswer(a); + answers.add(a); + } + Associations.QuestionAnswers.addAnswer(q, answers); + addNewQuestion(q); + res.add(q); + } + return res; + } + } diff --git a/src/main/java/com/uniovi/services/impl/RoleServiceImpl.java b/src/main/java/com/uniovi/services/impl/RoleServiceImpl.java index 0fae17ca..b10bbcc1 100644 --- a/src/main/java/com/uniovi/services/impl/RoleServiceImpl.java +++ b/src/main/java/com/uniovi/services/impl/RoleServiceImpl.java @@ -35,11 +35,4 @@ public Role addRole(RoleDto role) { public Role getRole(String name) { return roleRepository.findById(name).orElse(null); } - - @Override - public List getRoles() { - List roles = new ArrayList<>(); - roleRepository.findAll().forEach(roles::add); - return roles; - } } diff --git a/src/main/java/com/uniovi/validators/SignUpValidator.java b/src/main/java/com/uniovi/validators/SignUpValidator.java index 07507332..24893db4 100644 --- a/src/main/java/com/uniovi/validators/SignUpValidator.java +++ b/src/main/java/com/uniovi/validators/SignUpValidator.java @@ -25,23 +25,23 @@ public void validate(Object target, Errors errors) { PlayerDto user = (PlayerDto) target; if (!EmailValidator.getInstance().isValid(user.getEmail())) { - errors.rejectValue("email", null, + errors.rejectValue("email", "signup.error.email.valid", "El email no es válido"); } if(playerService.getUserByEmail(user.getEmail()).isPresent()){ - errors.rejectValue("email", null, + errors.rejectValue("email", "signup.error.email.already", "Ya hay una cuenta registrada con este email"); } if (playerService.getUserByUsername(user.getUsername()).isPresent()) { - errors.rejectValue("username", null, + errors.rejectValue("username", "signup.error.username.already", "Ya existe una cuenta con este nombre de usuario"); } if (user.getPassword() == null || !user.getPassword().equals(user.getPasswordConfirm())) { - errors.rejectValue("passwordConfirm", null, + errors.rejectValue("passwordConfirm", "signup.error.password.match", "Las contraseñas no coinciden"); } } diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 06e28cf3..700d20df 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -68,7 +68,10 @@ signup.passwordConfirm.label=Repita la contraseña: signup.passwordConfirm.placeholder=Repita la contraseña signup.submit=Registrarse signup.title=Regístrate - +signup.error.email.valid=El correo electrónico no es válido +signup.error.email.already=El correo electrónico ya está en uso +signup.error.username.already=El nombre de usuario ya está en uso +signup.error.password.match=Las contraseñas no coinciden # -------------------Statements for the playerRanking.html and GlobalRanking.html file--------------------- ranking.title=Ranking ranking.position=Posición diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 7d663d90..5de627c5 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -68,6 +68,10 @@ signup.passwordConfirm.label=Confirm Password: signup.passwordConfirm.placeholder=Confirm your password signup.submit=Sign up signup.title=Sign up +signup.error.email.valid=Please enter a valid email address +signup.error.email.already=The email is already in use +signup.error.username.already=The username is already in use +signup.error.password.match=Passwords do not match # -------------------Statements for the playerRanking.html and GlobalRanking.html file--------------------- ranking.title=Ranking diff --git a/src/main/resources/messages_es.properties b/src/main/resources/messages_es.properties index 40491b13..cba0e125 100644 --- a/src/main/resources/messages_es.properties +++ b/src/main/resources/messages_es.properties @@ -69,6 +69,10 @@ signup.passwordConfirm.label=Repita la contraseña: signup.passwordConfirm.placeholder=Repita la contraseña signup.submit=Registrarse signup.title=Regístrate +signup.error.email.valid=El correo electrónico no es válido +signup.error.email.already=El correo electrónico ya está en uso +signup.error.username.already=El nombre de usuario ya está en uso +signup.error.password.match=Las contraseñas no coinciden # -------------------Statements for the playerRanking.html and GlobalRanking.html file--------------------- ranking.title=Ranking diff --git a/src/main/resources/templates/player/signup.html b/src/main/resources/templates/player/signup.html index 93525fdd..af9c659e 100644 --- a/src/main/resources/templates/player/signup.html +++ b/src/main/resources/templates/player/signup.html @@ -54,6 +54,6 @@

-