diff --git a/data/test.lck b/data/test.lck index 72fd74d..771e2a0 100644 Binary files a/data/test.lck and b/data/test.lck differ diff --git a/data/test.log b/data/test.log index dd542e3..e69de29 100644 --- a/data/test.log +++ b/data/test.log @@ -1,3 +0,0 @@ -/*C1*/SET SCHEMA SYSTEM_LOBS -INSERT INTO BLOCKS VALUES(0,2147483647,0) -COMMIT diff --git a/data/test.properties b/data/test.properties index e00d83d..4885998 100644 --- a/data/test.properties +++ b/data/test.properties @@ -1,5 +1,5 @@ #HSQL Database Engine 2.7.2 -#Sat Oct 11 15:53:59 CEST 2025 -modified=yes -tx_timestamp=1 +#Sun Oct 12 17:07:05 CEST 2025 +modified=no +tx_timestamp=28 version=2.7.2 diff --git a/data/test.script b/data/test.script index edaf1e7..183300d 100644 --- a/data/test.script +++ b/data/test.script @@ -29,8 +29,8 @@ SET FILES NIO TRUE SET FILES NIO SIZE 256 SET FILES LOG TRUE SET FILES LOG SIZE 50 -SET FILES CHECK 1 -SET DATABASE COLLATION SQL_TEXT PAD SPACE +SET FILES CHECK 28 +SET DATABASE COLLATION "SQL_TEXT" PAD SPACE CREATE USER SA PASSWORD DIGEST 'd41d8cd98f00b204e9800998ecf8427e' ALTER USER SA SET LOCAL TRUE CREATE SCHEMA PUBLIC AUTHORIZATION DBA @@ -42,3 +42,5 @@ GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CHARACTER_DATA TO PUBLIC GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.SQL_IDENTIFIER TO PUBLIC GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.TIME_STAMP TO PUBLIC GRANT DBA TO SA +SET SCHEMA SYSTEM_LOBS +INSERT INTO BLOCKS VALUES(0,2147483647,0) diff --git a/src/main/java/sample/data/jpa/metier/Choix.java b/src/main/java/sample/data/jpa/metier/Choix.java index 23226cf..3ab5b06 100644 --- a/src/main/java/sample/data/jpa/metier/Choix.java +++ b/src/main/java/sample/data/jpa/metier/Choix.java @@ -1,5 +1,6 @@ package sample.data.jpa.metier; +import java.util.ArrayList; import java.util.List; import jakarta.persistence.Entity; @@ -14,7 +15,7 @@ import lombok.Setter; @NoArgsConstructor @PrimaryKeyJoinColumn(name = "Choix_Id") public class Choix extends Reponse{ - List choix; + List choix = new ArrayList();; @Override public String valHTML(){ diff --git a/src/main/java/sample/data/jpa/metier/Reponse.java b/src/main/java/sample/data/jpa/metier/Reponse.java index 9137376..32d5e15 100644 --- a/src/main/java/sample/data/jpa/metier/Reponse.java +++ b/src/main/java/sample/data/jpa/metier/Reponse.java @@ -1,6 +1,7 @@ package sample.data.jpa.metier; import java.io.Serializable; +import java.util.ArrayList; import java.util.List; import jakarta.persistence.*; @@ -22,7 +23,7 @@ public abstract class Reponse implements Serializable { @OneToOne private Question question; - public List reponses; + public List reponses = new ArrayList(); public String valHTML(){ return ""; diff --git a/src/main/java/sample/data/jpa/web/QuestionController.java b/src/main/java/sample/data/jpa/web/QuestionController.java index 15f1628..adbd93e 100644 --- a/src/main/java/sample/data/jpa/web/QuestionController.java +++ b/src/main/java/sample/data/jpa/web/QuestionController.java @@ -5,6 +5,8 @@ import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -14,6 +16,7 @@ import org.springframework.web.bind.annotation.ResponseBody; import sample.data.jpa.metier.Choix; import sample.data.jpa.metier.Question; +import sample.data.jpa.metier.Reponse; import sample.data.jpa.metier.ReponseCourte; import sample.data.jpa.service.QuestionDao; @@ -67,57 +70,90 @@ public class QuestionController { return "Question "+id+" succesfully updated! : " + q.getEnonce(); } - @RequestMapping("/getReponse") + @GetMapping("/getAll") @ResponseBody - public String getReponse(int id) { + public String getAll(){ try { - Question question = qDao.findById(id).get(); - List results = question.getReponse().getReponses(); + List questions = qDao.findAll(); String res = "["; - for(int i = 0; i < results.size(); i++){ - res+=results.get(i); - if(i reponses = rep.getReponses(); + String res = "["; + for(int i = 0; i < reponses.size(); i++){ + res+=reponses.get(i); + if(i body) { try { Question question = qDao.findById(id).get(); - question.getReponse().getReponses().add(reponse); - qDao.save(question); - return "Réponse correcte \"" + reponse + "\" ajoutée à la question " + id; + Reponse rep = question.getReponse(); + if(rep != null){ + String reponse = body.get("reponse"); + rep.getReponses().add(reponse); + qDao.save(question); + return "Réponse correcte \"" + reponse + "\" ajoutée à la question " + id; + } + else return "Reponse non itialisée pour la question : " + id; } catch (Exception ex) { return "Erreur lors de l'ajout de la réponse : " + ex.toString(); } } - @RequestMapping("/deleteReponse") + @PutMapping("/deleteReponse/{id}") @ResponseBody - public String deleteReponses(int id, String reponse) { + public String deleteReponses(@PathVariable("id") int id, @RequestBody Map body) { try { Question question = qDao.findById(id).get(); - question.getReponse().getReponses().remove(reponse); - qDao.save(question); - return "Réponses supprimées de la question " + id; + Reponse rep = question.getReponse(); + if(rep != null){ + String reponse = body.get("reponse"); + rep.getReponses().remove(reponse); + qDao.save(question); + return "Réponses \"" + reponse + "\" supprimées de la question " + id; + } + else return "Rien à supprimer, reponse non itialisée pour la question : " + id; } catch (Exception ex) { return "Erreur lors de la suppression des réponses : " + ex.toString(); } } - @RequestMapping("/setReponseChoix") + @PutMapping("/setReponseChoix/{id}") @ResponseBody - public String setReponseChoix(int id) { + public String setReponseChoix(@PathVariable("id") int id) { try { Question question = qDao.findById(id).get(); question.setReponse(new Choix()); @@ -128,9 +164,9 @@ public class QuestionController { } } - @RequestMapping("/setReponseCourte") + @PutMapping("/setReponseCourte/{id}") @ResponseBody - public String setReponseCourte(int id) { + public String setReponseCourte(@PathVariable("id") int id) { try { Question question = qDao.findById(id).get(); question.setReponse(new ReponseCourte()); @@ -141,27 +177,51 @@ public class QuestionController { } } - @RequestMapping("/updateChoix") + @PutMapping("/addChoix/{id}") @ResponseBody - public String addChoix(int id, String choix) { + public String addChoix(@PathVariable("id") int id, @RequestBody Map body) { try { Question question = qDao.findById(id).get(); if (question.getReponse() instanceof Choix) { + String choix = body.get("choix"); ((Choix) question.getReponse()).getChoix().add(choix); qDao.save(question); + return "Choix \"" + choix + "\" ajouté à la question " + id; } else return "Erreur : la réponse doit être a choix multiple."; - - return "Choix \"" + choix + "\" ajouté à la question " + id; } catch (Exception ex) { return "Erreur lors de l'ajout du choix : " + ex.toString(); } } - @RequestMapping("/delete") + @GetMapping("/getChoix/{id}") @ResponseBody - public String delete(int id) { + public String getChoix(@PathVariable("id") int id) { + try { + Question question = qDao.findById(id).get(); + if (question.getReponse() instanceof Choix) { + List choix = ((Choix) question.getReponse()).getChoix(); + String res = "["; + for(int i = 0; i < choix.size(); i++){ + res+=choix.get(i); + if(i