Controller reponse et session
This commit is contained in:
@@ -6,6 +6,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import sample.data.jpa.metier.Quizz;
|
||||
|
||||
@Transactional
|
||||
public interface QuizzDao extends JpaRepository<Quizz, Long> {
|
||||
public interface QuizzDao extends JpaRepository<Quizz, Integer> {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import sample.data.jpa.metier.Reponse;
|
||||
|
||||
public interface ReponseDao extends JpaRepository<Reponse, Long> {
|
||||
public interface ReponseDao extends JpaRepository<Reponse, Integer> {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,72 @@
|
||||
package sample.data.jpa.web;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import sample.data.jpa.metier.Question;
|
||||
import sample.data.jpa.metier.Quizz;
|
||||
import sample.data.jpa.service.QuizzDao;
|
||||
|
||||
@Controller
|
||||
public class QuizzController {
|
||||
private QuizzDao qDao;
|
||||
|
||||
|
||||
@RequestMapping("/create")
|
||||
@ResponseBody
|
||||
public String create() {
|
||||
String qId = "";
|
||||
try {
|
||||
Quizz q = new Quizz();
|
||||
qDao.save(q);
|
||||
qId = String.valueOf(q.getId());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return "Error creating the Quizz : " + ex.toString();
|
||||
}
|
||||
return "Quizz succesfully created with id = " + qId;
|
||||
}
|
||||
|
||||
@RequestMapping("/delete")
|
||||
@ResponseBody
|
||||
public String delete(int id) {
|
||||
try {
|
||||
Quizz q = qDao.findById(id).get();
|
||||
qDao.delete(q);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return "Error deleting the quizz " + id + " :" + ex.toString();
|
||||
}
|
||||
return "Quizz " + id + " succesfully deleted!";
|
||||
}
|
||||
|
||||
@RequestMapping("/addQuestion")
|
||||
@ResponseBody
|
||||
public String delete(int id, Question question) {
|
||||
try {
|
||||
Quizz q = qDao.findById(id).get();
|
||||
q.getQuestions().add(question);
|
||||
qDao.save(q);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return "Error Question adding from quizz " + id + " :" + ex.toString();
|
||||
}
|
||||
return "Question add from Quizz " + id;
|
||||
}
|
||||
|
||||
@RequestMapping("/deletQuestion")
|
||||
@ResponseBody
|
||||
public String delete(int id, int qId) {
|
||||
try {
|
||||
Quizz q = qDao.findById(id).get();
|
||||
q.getQuestions().remove(qId);
|
||||
qDao.save(q);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return "Error removing question from the quizz " + id + " :" + ex.toString();
|
||||
}
|
||||
return "Question remove from Quizz " + id;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,62 @@
|
||||
package sample.data.jpa.web;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import sample.data.jpa.metier.Choix;
|
||||
import sample.data.jpa.metier.Question;
|
||||
import sample.data.jpa.metier.Quizz;
|
||||
import sample.data.jpa.metier.Reponse;
|
||||
import sample.data.jpa.metier.ReponseCourte;
|
||||
import sample.data.jpa.service.ReponseDao;
|
||||
|
||||
@Controller
|
||||
public class ReponseController {
|
||||
private ReponseDao rDao;
|
||||
|
||||
|
||||
@RequestMapping("/createCourte")
|
||||
@ResponseBody
|
||||
public String createCourte() {
|
||||
String rId = "";
|
||||
try {
|
||||
Reponse r = new ReponseCourte();
|
||||
rDao.save(r);
|
||||
rId = String.valueOf(r.getId());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return "Error creating the Quizz : " + ex.toString();
|
||||
}
|
||||
return "Quizz succesfully created with id = " + rId;
|
||||
}
|
||||
|
||||
@RequestMapping("/createChoix")
|
||||
@ResponseBody
|
||||
public String createChoix() {
|
||||
String rId = "";
|
||||
try {
|
||||
Reponse r = new Choix();
|
||||
rDao.save(r);
|
||||
rId = String.valueOf(r.getId());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return "Error creating the Quizz : " + ex.toString();
|
||||
}
|
||||
return "Quizz succesfully created with id = " + rId;
|
||||
}
|
||||
|
||||
@RequestMapping("/addReponse")
|
||||
@ResponseBody
|
||||
public String addReponse(int id, String reponse) {
|
||||
try {
|
||||
Reponse r = rDao.findById(id).get();
|
||||
r.getReponses().add(reponse);
|
||||
rDao.save(r);
|
||||
return "Réponse correcte \"" + reponse + "\" ajoutée " + id;
|
||||
} catch (Exception ex) {
|
||||
return "Erreur lors de l'ajout de la réponse : " + ex.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user