Controller reponse et session
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user