TODO controller
This commit is contained in:
@@ -1,4 +1,21 @@
|
||||
package sample.data.jpa.service;
|
||||
|
||||
public interface QuestionDao {
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import sample.data.jpa.metier.Question;
|
||||
|
||||
@Transactional
|
||||
public interface QuestionDao extends JpaRepository<Question, Integer> {
|
||||
|
||||
//public Question findById(int id);
|
||||
|
||||
public void deleteReponse(int id);
|
||||
|
||||
public void setChoix(int id);
|
||||
|
||||
public void setReponseCourte(int id);
|
||||
|
||||
public void addChoix(int id, String choix);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
package sample.data.jpa.service;
|
||||
|
||||
public interface QuizzDao {
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import sample.data.jpa.metier.Quizz;
|
||||
|
||||
@Transactional
|
||||
public interface QuizzDao extends JpaRepository<Quizz, Long> {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
package sample.data.jpa.service;
|
||||
|
||||
public interface ReponseDao {
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import sample.data.jpa.metier.Reponse;
|
||||
|
||||
public interface ReponseDao extends JpaRepository<Reponse, Long> {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
package sample.data.jpa.service;
|
||||
|
||||
public interface SessionDao {
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import sample.data.jpa.domain.User;
|
||||
import sample.data.jpa.metier.Session;
|
||||
|
||||
public interface SessionDao extends JpaRepository<Session, Long> {
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
package sample.data.jpa.service;
|
||||
|
||||
public interface UtilisateurDao {
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import sample.data.jpa.metier.Utilisateur;
|
||||
|
||||
public interface UtilisateurDao extends JpaRepository<Utilisateur, Long> {
|
||||
}
|
||||
|
||||
@@ -1,5 +1,146 @@
|
||||
package sample.data.jpa.web;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.Reponse;
|
||||
import sample.data.jpa.service.QuestionDao;
|
||||
|
||||
|
||||
|
||||
@Controller
|
||||
public class QuestionController {
|
||||
@Autowired
|
||||
private QuestionDao qDao;
|
||||
|
||||
@RequestMapping("/create")
|
||||
@ResponseBody
|
||||
public String create(String email, String name) {
|
||||
String qId = "";
|
||||
try {
|
||||
Question question = new Question();
|
||||
qDao.save(question);
|
||||
qId = String.valueOf(question.getId());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return "Error creating the question : " + ex.toString();
|
||||
}
|
||||
return "Question succesfully created with id = " + qId;
|
||||
}
|
||||
|
||||
@RequestMapping("/update")
|
||||
@ResponseBody
|
||||
public String updateUser(long id, String newQ) {
|
||||
try {
|
||||
Question q = qDao.findById(id).get();
|
||||
q.setQuestion(newQ);
|
||||
qDao.save(q);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return "Error updating the question: " + ex.toString();
|
||||
}
|
||||
return "Question succesfully updated!";
|
||||
}
|
||||
|
||||
@RequestMapping("/changeQuestion")
|
||||
@ResponseBody
|
||||
public String changeQuestion(int id, String newQuestion) {
|
||||
try {
|
||||
Question question = qDao.findById(id).get();
|
||||
question.setQuestion(newQuestion);
|
||||
qDao.save(question);
|
||||
return "Question mise à jour : " + newQuestion;
|
||||
} catch (Exception ex) {
|
||||
return "Erreur lors de la mise à jour de la question : " + ex.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/getReponse")
|
||||
@ResponseBody
|
||||
public String getReponse(int id) {
|
||||
try {
|
||||
Question question = qDao.findById(id).get();
|
||||
List<String> results = question.getReponse().getReponses();
|
||||
String res = "[";
|
||||
for(int i = 0; i < results.size(); i++){
|
||||
res+=results.get(i);
|
||||
if(i<results.size()-1){
|
||||
res+=",";
|
||||
}
|
||||
else res+="]";
|
||||
}
|
||||
return (results != null)
|
||||
? "Réponse de la question " + id + " : " + res
|
||||
: "Aucune réponse trouvée pour la question " + id;
|
||||
} catch (Exception ex) {
|
||||
return "Erreur lors de la récupération de la réponse : " + ex.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/addReponse")
|
||||
@ResponseBody
|
||||
public String addReponse(int id, String reponse) {
|
||||
try {
|
||||
Question question = qDao.findById(id).get();
|
||||
qDao.addReponse(reponse, id);
|
||||
return "Réponse correcte \"" + reponse + "\" ajoutée à la question " + id;
|
||||
} catch (Exception ex) {
|
||||
return "Erreur lors de l'ajout de la réponse : " + ex.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/deleteReponses")
|
||||
@ResponseBody
|
||||
public String deleteReponses(int id) {
|
||||
try {
|
||||
qDao.deleteReponse(id);
|
||||
return "Réponses supprimées de la question " + id;
|
||||
} catch (Exception ex) {
|
||||
return "Erreur lors de la suppression des réponses : " + ex.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/setReponseChoix")
|
||||
@ResponseBody
|
||||
public String setReponseChoix(int id) {
|
||||
try {
|
||||
qDao.setChoix(id);
|
||||
return "Réponses à choix multiple mises sur la question " + id;
|
||||
} catch (Exception ex) {
|
||||
return "Erreur lors de la mise en place du type 'choix' : " + ex.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/setReponseCourte")
|
||||
@ResponseBody
|
||||
public String setReponseCourte(int id) {
|
||||
try {
|
||||
qDao.setReponseCourte(id);
|
||||
return "Réponses courtes mises sur la question " + id;
|
||||
} catch (Exception ex) {
|
||||
return "Erreur lors de la mise en place du type 'réponse courte' : " + ex.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/addChoix")
|
||||
@ResponseBody
|
||||
public String addChoix(int id, String choix) {
|
||||
try {
|
||||
Question question = qDao.findById(id).get();
|
||||
if (question.getReponse() instanceof Choix) {
|
||||
return "Erreur : la réponse est déjà un choix multiple.";
|
||||
}
|
||||
qDao.addChoix(id, choix);
|
||||
return "Choix \"" + choix + "\" ajouté à la question " + id;
|
||||
} catch (Exception ex) {
|
||||
return "Erreur lors de l'ajout du choix : " + ex.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package sample.data.jpa.web;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@Controller
|
||||
public class QuizzController {
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package sample.data.jpa.web;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@Controller
|
||||
public class ReponseController {
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package sample.data.jpa.web;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@Controller
|
||||
public class SessionController {
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package sample.data.jpa.web;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
|
||||
@Controller
|
||||
public class UtilisateurController {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user