From 706481ed1af157d17fd4a738f95fbc2fee089558 Mon Sep 17 00:00:00 2001 From: LeoMoulin Date: Wed, 10 Apr 2024 23:09:38 +0200 Subject: [PATCH] Fix and simplifie the post and get for externalCurriculum --- .../Clyde/EndPoints/CurriculumController.java | 1 + .../ExternalCurriculumController.java | 44 +++++++++++++++++++ .../ExternalCurriculumRepository.java | 2 +- frontend/src/Apps/AboutRequest.vue | 6 ++- frontend/src/rest/externalCurriculum.js | 11 ++--- 5 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/EndPoints/ExternalCurriculumController.java diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CurriculumController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CurriculumController.java index 88a339b..c9e78de 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CurriculumController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CurriculumController.java @@ -118,4 +118,5 @@ public class CurriculumController { curriculumServ.delete(toDelete); return new ResponseEntity<>(HttpStatus.OK); } + } diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ExternalCurriculumController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ExternalCurriculumController.java new file mode 100644 index 0000000..03b56e4 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ExternalCurriculumController.java @@ -0,0 +1,44 @@ +package ovh.herisson.Clyde.EndPoints; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import ovh.herisson.Clyde.Repositories.ExternalCurriculumRepository; +import ovh.herisson.Clyde.Repositories.InscriptionRepository; +import ovh.herisson.Clyde.Tables.ExternalCurriculum; +import ovh.herisson.Clyde.Tables.InscriptionRequest; +import ovh.herisson.Clyde.Tables.RequestState; + +import java.util.ArrayList; +import java.util.Map; + +@RestController +@CrossOrigin(originPatterns = "*", allowCredentials = "true") +public class ExternalCurriculumController { + + public final ExternalCurriculumRepository ecr; + public final InscriptionRepository inscriptionRepository; + + public ExternalCurriculumController(ExternalCurriculumRepository ecr, InscriptionRepository inscriptionRepository) { + this.ecr = ecr; + this.inscriptionRepository = inscriptionRepository; + } + + //everyone can post some externalcurriculums (the validity of the elements is assured by the inscription service) + @PostMapping("/externalcurriculum") + public ResponseEntity postExternalCurriculum(@RequestBody Map externalCurrInfos){ + InscriptionRequest ir = inscriptionRepository.findById((Integer) externalCurrInfos.get("inscriptionRequestId")); + + ExternalCurriculum toSave = new ExternalCurriculum(ir, (String) externalCurrInfos.get("school"),(String) externalCurrInfos.get("formation"),(String) externalCurrInfos.get("completion"), (Integer)externalCurrInfos.get("startYear"), (Integer)externalCurrInfos.get("endYear"), (String)externalCurrInfos.get("justifDocUrl"), RequestState.Pending); + + return new ResponseEntity<>(ecr.save(toSave), HttpStatus.OK); + } + + @GetMapping("/externalcurriculum/{inscReqId}") + public ResponseEntity> getExternalCurrListByInscrReq(@PathVariable long inscReqId){ + InscriptionRequest ir = inscriptionRepository.findById(inscReqId); + + ArrayList toReturn = ecr.getExternalCurriculumByInscriptionRequest(ir); + return new ResponseEntity<>(toReturn, HttpStatus.OK); + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/ExternalCurriculumRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ExternalCurriculumRepository.java index 5835fab..81f9d1e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/ExternalCurriculumRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ExternalCurriculumRepository.java @@ -8,5 +8,5 @@ import ovh.herisson.Clyde.Tables.User; import java.util.ArrayList; public interface ExternalCurriculumRepository extends CrudRepository { - ArrayList getExternalCurriculumByInscriptionRequestId(Long id); + ArrayList getExternalCurriculumByInscriptionRequest(InscriptionRequest ir); } diff --git a/frontend/src/Apps/AboutRequest.vue b/frontend/src/Apps/AboutRequest.vue index 05c76c5..c363acd 100644 --- a/frontend/src/Apps/AboutRequest.vue +++ b/frontend/src/Apps/AboutRequest.vue @@ -1,14 +1,16 @@