Controller question fini et testé avec postman
This commit is contained in:
@@ -3,6 +3,10 @@ package sample.data.jpa.web;
|
||||
import java.util.List;
|
||||
|
||||
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.ResponseBody;
|
||||
|
||||
@@ -16,7 +20,7 @@ public class QuizzController {
|
||||
private QuizzDao qDao;
|
||||
|
||||
|
||||
@RequestMapping("/create")
|
||||
@PostMapping("/create")
|
||||
@ResponseBody
|
||||
public String create() {
|
||||
String qId = "";
|
||||
@@ -31,9 +35,9 @@ public class QuizzController {
|
||||
return "Quizz succesfully created with id = " + qId;
|
||||
}
|
||||
|
||||
@RequestMapping("/delete")
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@ResponseBody
|
||||
public String delete(int id) {
|
||||
public String delete(@PathVariable("id") int id) {
|
||||
try {
|
||||
Quizz q = qDao.findById(id).get();
|
||||
qDao.delete(q);
|
||||
@@ -44,9 +48,9 @@ public class QuizzController {
|
||||
return "Quizz " + id + " succesfully deleted!";
|
||||
}
|
||||
|
||||
@RequestMapping("/addQuestion")
|
||||
@PutMapping("/addQuestion/{id}")
|
||||
@ResponseBody
|
||||
public String delete(int id, Question question) {
|
||||
public String delete(@PathVariable("id") int id, Question question) {
|
||||
try {
|
||||
Quizz q = qDao.findById(id).get();
|
||||
q.getQuestions().add(question);
|
||||
@@ -58,9 +62,9 @@ public class QuizzController {
|
||||
return "Question add from Quizz " + id;
|
||||
}
|
||||
|
||||
@RequestMapping("/deletQuestion")
|
||||
@PutMapping("/deletQuestion/{id}")
|
||||
@ResponseBody
|
||||
public String delete(int id, int qId) {
|
||||
public String delete(@PathVariable("id") int id, int qId) {
|
||||
try {
|
||||
Quizz q = qDao.findById(id).get();
|
||||
q.getQuestions().remove(qId);
|
||||
@@ -72,7 +76,7 @@ public class QuizzController {
|
||||
return "Question remove from Quizz " + id;
|
||||
}
|
||||
|
||||
@RequestMapping("/getAll")
|
||||
@PutMapping("/getAll")
|
||||
@ResponseBody
|
||||
public String getAll(){
|
||||
String res = "";
|
||||
|
||||
Reference in New Issue
Block a user