Controller question fini et testé avec postman

This commit is contained in:
trochas
2025-10-12 18:26:51 +02:00
parent 754551ef6c
commit dcd069c884
129 changed files with 114 additions and 49 deletions

Binary file not shown.

View File

@@ -1,3 +0,0 @@
/*C1*/SET SCHEMA SYSTEM_LOBS
INSERT INTO BLOCKS VALUES(0,2147483647,0)
COMMIT

View File

@@ -1,5 +1,5 @@
#HSQL Database Engine 2.7.2 #HSQL Database Engine 2.7.2
#Sat Oct 11 15:53:59 CEST 2025 #Sun Oct 12 17:07:05 CEST 2025
modified=yes modified=no
tx_timestamp=1 tx_timestamp=28
version=2.7.2 version=2.7.2

View File

@@ -29,8 +29,8 @@ SET FILES NIO TRUE
SET FILES NIO SIZE 256 SET FILES NIO SIZE 256
SET FILES LOG TRUE SET FILES LOG TRUE
SET FILES LOG SIZE 50 SET FILES LOG SIZE 50
SET FILES CHECK 1 SET FILES CHECK 28
SET DATABASE COLLATION SQL_TEXT PAD SPACE SET DATABASE COLLATION "SQL_TEXT" PAD SPACE
CREATE USER SA PASSWORD DIGEST 'd41d8cd98f00b204e9800998ecf8427e' CREATE USER SA PASSWORD DIGEST 'd41d8cd98f00b204e9800998ecf8427e'
ALTER USER SA SET LOCAL TRUE ALTER USER SA SET LOCAL TRUE
CREATE SCHEMA PUBLIC AUTHORIZATION DBA 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.SQL_IDENTIFIER TO PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.TIME_STAMP TO PUBLIC GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.TIME_STAMP TO PUBLIC
GRANT DBA TO SA GRANT DBA TO SA
SET SCHEMA SYSTEM_LOBS
INSERT INTO BLOCKS VALUES(0,2147483647,0)

View File

@@ -1,5 +1,6 @@
package sample.data.jpa.metier; package sample.data.jpa.metier;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@@ -14,7 +15,7 @@ import lombok.Setter;
@NoArgsConstructor @NoArgsConstructor
@PrimaryKeyJoinColumn(name = "Choix_Id") @PrimaryKeyJoinColumn(name = "Choix_Id")
public class Choix extends Reponse{ public class Choix extends Reponse{
List<String> choix; List<String> choix = new ArrayList<String>();;
@Override @Override
public String valHTML(){ public String valHTML(){

View File

@@ -1,6 +1,7 @@
package sample.data.jpa.metier; package sample.data.jpa.metier;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import jakarta.persistence.*; import jakarta.persistence.*;
@@ -22,7 +23,7 @@ public abstract class Reponse implements Serializable {
@OneToOne @OneToOne
private Question question; private Question question;
public List<String> reponses; public List<String> reponses = new ArrayList<String>();
public String valHTML(){ public String valHTML(){
return ""; return "";

View File

@@ -5,6 +5,8 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; 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.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping; 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.Choix;
import sample.data.jpa.metier.Question; import sample.data.jpa.metier.Question;
import sample.data.jpa.metier.Reponse;
import sample.data.jpa.metier.ReponseCourte; import sample.data.jpa.metier.ReponseCourte;
import sample.data.jpa.service.QuestionDao; import sample.data.jpa.service.QuestionDao;
@@ -67,57 +70,90 @@ public class QuestionController {
return "Question "+id+" succesfully updated! : " + q.getEnonce(); return "Question "+id+" succesfully updated! : " + q.getEnonce();
} }
@RequestMapping("/getReponse") @GetMapping("/getAll")
@ResponseBody @ResponseBody
public String getReponse(int id) { public String getAll(){
try { try {
Question question = qDao.findById(id).get(); List<Question> questions = qDao.findAll();
List<String> results = question.getReponse().getReponses();
String res = "["; String res = "[";
for(int i = 0; i < results.size(); i++){ for(int i = 0; i < questions.size(); i++){
res+=results.get(i); res+=questions.get(i).getId();
if(i<results.size()-1){ if(i<questions.size()-1){
res+=","; res+=",";
} }
else res+="]";
} }
return (results != null) res+="]";
? "Réponse de la question " + id + " : " + res return res;
: "Aucune réponse trouvée pour la question " + id; } catch (Exception ex) {
return "Erreur lors de la récupération des question : " + ex.toString();
}
}
@GetMapping("/getReponses/{id}")
@ResponseBody
public String getReponses(@PathVariable("id") int id) {
try {
Question question = qDao.findById(id).get();
Reponse rep = question.getReponse();
if(rep != null){
List<String> reponses = rep.getReponses();
String res = "[";
for(int i = 0; i < reponses.size(); i++){
res+=reponses.get(i);
if(i<reponses.size()-1){
res+=",";
}
}
res+="]";
return "Réponse de la question " + id + " : " + res;
}
else return "Réponse non initialisée pour la question : " + id;
} catch (Exception ex) { } catch (Exception ex) {
return "Erreur lors de la récupération de la réponse : " + ex.toString(); return "Erreur lors de la récupération de la réponse : " + ex.toString();
} }
} }
@RequestMapping("/addReponse") @PutMapping("/addReponse/{id}")
@ResponseBody @ResponseBody
public String addReponse(int id, String reponse) { public String addReponse(@PathVariable("id") int id, @RequestBody Map<String, String> body) {
try { try {
Question question = qDao.findById(id).get(); Question question = qDao.findById(id).get();
question.getReponse().getReponses().add(reponse); Reponse rep = question.getReponse();
qDao.save(question); if(rep != null){
return "Réponse correcte \"" + reponse + "\" ajoutée à la question " + id; 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) { } catch (Exception ex) {
return "Erreur lors de l'ajout de la réponse : " + ex.toString(); return "Erreur lors de l'ajout de la réponse : " + ex.toString();
} }
} }
@RequestMapping("/deleteReponse") @PutMapping("/deleteReponse/{id}")
@ResponseBody @ResponseBody
public String deleteReponses(int id, String reponse) { public String deleteReponses(@PathVariable("id") int id, @RequestBody Map<String, String> body) {
try { try {
Question question = qDao.findById(id).get(); Question question = qDao.findById(id).get();
question.getReponse().getReponses().remove(reponse); Reponse rep = question.getReponse();
qDao.save(question); if(rep != null){
return "Réponses supprimées de la question " + id; 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) { } catch (Exception ex) {
return "Erreur lors de la suppression des réponses : " + ex.toString(); return "Erreur lors de la suppression des réponses : " + ex.toString();
} }
} }
@RequestMapping("/setReponseChoix") @PutMapping("/setReponseChoix/{id}")
@ResponseBody @ResponseBody
public String setReponseChoix(int id) { public String setReponseChoix(@PathVariable("id") int id) {
try { try {
Question question = qDao.findById(id).get(); Question question = qDao.findById(id).get();
question.setReponse(new Choix()); question.setReponse(new Choix());
@@ -128,9 +164,9 @@ public class QuestionController {
} }
} }
@RequestMapping("/setReponseCourte") @PutMapping("/setReponseCourte/{id}")
@ResponseBody @ResponseBody
public String setReponseCourte(int id) { public String setReponseCourte(@PathVariable("id") int id) {
try { try {
Question question = qDao.findById(id).get(); Question question = qDao.findById(id).get();
question.setReponse(new ReponseCourte()); question.setReponse(new ReponseCourte());
@@ -141,27 +177,51 @@ public class QuestionController {
} }
} }
@RequestMapping("/updateChoix") @PutMapping("/addChoix/{id}")
@ResponseBody @ResponseBody
public String addChoix(int id, String choix) { public String addChoix(@PathVariable("id") int id, @RequestBody Map<String, String> body) {
try { try {
Question question = qDao.findById(id).get(); Question question = qDao.findById(id).get();
if (question.getReponse() instanceof Choix) { if (question.getReponse() instanceof Choix) {
String choix = body.get("choix");
((Choix) question.getReponse()).getChoix().add(choix); ((Choix) question.getReponse()).getChoix().add(choix);
qDao.save(question); qDao.save(question);
return "Choix \"" + choix + "\" ajouté à la question " + id;
} }
else return "Erreur : la réponse doit être a choix multiple."; else return "Erreur : la réponse doit être a choix multiple.";
return "Choix \"" + choix + "\" ajouté à la question " + id;
} catch (Exception ex) { } catch (Exception ex) {
return "Erreur lors de l'ajout du choix : " + ex.toString(); return "Erreur lors de l'ajout du choix : " + ex.toString();
} }
} }
@RequestMapping("/delete") @GetMapping("/getChoix/{id}")
@ResponseBody @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<String> choix = ((Choix) question.getReponse()).getChoix();
String res = "[";
for(int i = 0; i < choix.size(); i++){
res+=choix.get(i);
if(i<choix.size()-1){
res+=",";
}
}
res+="]";
return "Choix de la question " + id + " : " + res;
}
else return "Erreur : la question "+id+" n'est pas a choix multiple.";
} catch (Exception ex) {
return "Erreur lors de l'ajout du choix : " + ex.toString();
}
}
@DeleteMapping("/delete/{id}")
@ResponseBody
public String delete(@PathVariable("id") int id) {
try { try {
Question q = qDao.findById(id).get(); Question q = qDao.findById(id).get();

View File

@@ -3,6 +3,10 @@ package sample.data.jpa.web;
import java.util.List; import java.util.List;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
@@ -16,7 +20,7 @@ public class QuizzController {
private QuizzDao qDao; private QuizzDao qDao;
@RequestMapping("/create") @PostMapping("/create")
@ResponseBody @ResponseBody
public String create() { public String create() {
String qId = ""; String qId = "";
@@ -31,9 +35,9 @@ public class QuizzController {
return "Quizz succesfully created with id = " + qId; return "Quizz succesfully created with id = " + qId;
} }
@RequestMapping("/delete") @DeleteMapping("/delete/{id}")
@ResponseBody @ResponseBody
public String delete(int id) { public String delete(@PathVariable("id") int id) {
try { try {
Quizz q = qDao.findById(id).get(); Quizz q = qDao.findById(id).get();
qDao.delete(q); qDao.delete(q);
@@ -44,9 +48,9 @@ public class QuizzController {
return "Quizz " + id + " succesfully deleted!"; return "Quizz " + id + " succesfully deleted!";
} }
@RequestMapping("/addQuestion") @PutMapping("/addQuestion/{id}")
@ResponseBody @ResponseBody
public String delete(int id, Question question) { public String delete(@PathVariable("id") int id, Question question) {
try { try {
Quizz q = qDao.findById(id).get(); Quizz q = qDao.findById(id).get();
q.getQuestions().add(question); q.getQuestions().add(question);
@@ -58,9 +62,9 @@ public class QuizzController {
return "Question add from Quizz " + id; return "Question add from Quizz " + id;
} }
@RequestMapping("/deletQuestion") @PutMapping("/deletQuestion/{id}")
@ResponseBody @ResponseBody
public String delete(int id, int qId) { public String delete(@PathVariable("id") int id, int qId) {
try { try {
Quizz q = qDao.findById(id).get(); Quizz q = qDao.findById(id).get();
q.getQuestions().remove(qId); q.getQuestions().remove(qId);
@@ -72,7 +76,7 @@ public class QuizzController {
return "Question remove from Quizz " + id; return "Question remove from Quizz " + id;
} }
@RequestMapping("/getAll") @PutMapping("/getAll")
@ResponseBody @ResponseBody
public String getAll(){ public String getAll(){
String res = ""; String res = "";

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More