|
|
@@ -20,10 +20,15 @@ import fr.jaquin.bdlg.planner.persistence.EvenementData;
|
|
|
import fr.jaquin.bdlg.planner.persistence.EvenementLob;
|
|
|
import fr.jaquin.bdlg.planner.persistence.EvenementNotFoundException;
|
|
|
import fr.jaquin.bdlg.planner.persistence.MyUser;
|
|
|
+import fr.jaquin.bdlg.planner.persistence.Questionnaire;
|
|
|
+import fr.jaquin.bdlg.planner.persistence.QuestionnaireQuestion;
|
|
|
+import fr.jaquin.bdlg.planner.persistence.QuestionnaireQuestionCompetence;
|
|
|
import fr.jaquin.bdlg.planner.persistence.Volunteer;
|
|
|
import fr.jaquin.bdlg.planner.persistence.repositories.EvenementLobRepository;
|
|
|
import fr.jaquin.bdlg.planner.persistence.repositories.EvenementRepository;
|
|
|
import fr.jaquin.bdlg.planner.persistence.repositories.MyUserRepository;
|
|
|
+import fr.jaquin.bdlg.planner.persistence.repositories.QuestionnaireQuestionRepo;
|
|
|
+import fr.jaquin.bdlg.planner.persistence.repositories.QuestionnaireRepo;
|
|
|
import fr.jaquin.bdlg.planner.persistence.repositories.RegistrationRepository;
|
|
|
|
|
|
@RestController
|
|
|
@@ -38,12 +43,19 @@ public class ApiController {
|
|
|
|
|
|
private final RegistrationRepository repositoryVolunteer;
|
|
|
|
|
|
+ private final QuestionnaireRepo repositoryQuestionnaire;
|
|
|
+ private final QuestionnaireQuestionRepo repositoryQuestionnaireQuestion;
|
|
|
+
|
|
|
public ApiController(EvenementRepository repository, EvenementLobRepository repositoryLob,
|
|
|
- MyUserRepository repositoryUser, RegistrationRepository repositoryVolunteer) {
|
|
|
+ MyUserRepository repositoryUser, RegistrationRepository repositoryVolunteer,
|
|
|
+ QuestionnaireRepo repositoryQuestionnaire,
|
|
|
+ QuestionnaireQuestionRepo repositoryQuestionnaireQuestion) {
|
|
|
this.repository = repository;
|
|
|
this.repositoryLob = repositoryLob;
|
|
|
this.repositoryUser = repositoryUser;
|
|
|
this.repositoryVolunteer = repositoryVolunteer;
|
|
|
+ this.repositoryQuestionnaire = repositoryQuestionnaire;
|
|
|
+ this.repositoryQuestionnaireQuestion = repositoryQuestionnaireQuestion;
|
|
|
}
|
|
|
|
|
|
@GetMapping("/evenements")
|
|
|
@@ -172,4 +184,87 @@ public class ApiController {
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping("/questionnaire/{uuid}")
|
|
|
+ Questionnaire getQuestionnaire(@PathVariable String uuid) {
|
|
|
+ Optional<Questionnaire> existing = repositoryQuestionnaire.findByUuid(uuid);
|
|
|
+ if (existing.isPresent()) {
|
|
|
+ return existing.get();
|
|
|
+ } else {
|
|
|
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, "",
|
|
|
+ new EvenementNotFoundException(uuid));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/questionnaire/{uuid}")
|
|
|
+ void postQuestionnaire(@PathVariable String uuid, @RequestBody Questionnaire q) {
|
|
|
+ if (repository.findByUuid(uuid).size() > 0) {
|
|
|
+ Optional<Questionnaire> existing = repositoryQuestionnaire.findByUuid(uuid);
|
|
|
+ if (existing.isPresent()) {
|
|
|
+ existing.get().setIntroduction(q.getIntroduction());
|
|
|
+ repositoryQuestionnaire.save(existing.get());
|
|
|
+ } else {
|
|
|
+ repositoryQuestionnaire.save(q);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Evenement does not exist");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/questionnaire/{uuid}/questions")
|
|
|
+ List<QuestionnaireQuestion> getQuestionnaireQuestions(@PathVariable String uuid) {
|
|
|
+ return repositoryQuestionnaireQuestion.findByEvtUuid(uuid);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/questionnaire/{evtUuid}/questions/{uuid}")
|
|
|
+ void putQuestionnaireQuestion(@PathVariable String evtUuid, @PathVariable String uuid,
|
|
|
+ @RequestBody QuestionnaireQuestion q) {
|
|
|
+ if (repository.findByUuid(evtUuid).size() > 0) {
|
|
|
+ Optional<QuestionnaireQuestion> existing = repositoryQuestionnaireQuestion.findByUuid(uuid);
|
|
|
+ if (existing.isPresent()) {
|
|
|
+ throw new ResponseStatusException(HttpStatus.CONFLICT, "UUID already existing");
|
|
|
+ }
|
|
|
+ repositoryQuestionnaireQuestion.save(q);
|
|
|
+ } else {
|
|
|
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Evenement does not exist");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/questionnaire/{evtUuid}/questions/{uuid}")
|
|
|
+ void postQuestionnaireQuestion(@PathVariable String evtUuid, @PathVariable String uuid,
|
|
|
+ @RequestBody QuestionnaireQuestion q) {
|
|
|
+ if (repository.findByUuid(evtUuid).size() > 0) {
|
|
|
+ Optional<QuestionnaireQuestion> existing = repositoryQuestionnaireQuestion.findByUuid(uuid);
|
|
|
+ if (existing.isPresent()) {
|
|
|
+ QuestionnaireQuestion current = existing.get();
|
|
|
+ q.setUid(current.getUid());
|
|
|
+ q.getCompetenceList().forEach(c -> {
|
|
|
+ for (QuestionnaireQuestionCompetence oldCompetence : current.getCompetenceList()) {
|
|
|
+ if (oldCompetence.getId() == c.getId()) {
|
|
|
+ c.setUid(oldCompetence.getUid());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ c.setQuestion(q);
|
|
|
+ });
|
|
|
+ repositoryQuestionnaireQuestion.save(q);
|
|
|
+ } else {
|
|
|
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Question does not exist");
|
|
|
+ }
|
|
|
+ } else
|
|
|
+
|
|
|
+ {
|
|
|
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Evenement does not exist");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @DeleteMapping("/questionnaire/{evtUuid}/questions/{uuid}")
|
|
|
+ boolean deleteQuestionnaireQuestion(@PathVariable String evtUuid, @PathVariable String uuid) {
|
|
|
+ Optional<QuestionnaireQuestion> v = repositoryQuestionnaireQuestion.findByUuid(uuid);
|
|
|
+ if (v.isPresent()) {
|
|
|
+ repositoryQuestionnaireQuestion.delete(v.get());
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Question not found");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|