From 8a5a26e2abc239e302bcad2ff6503a6c6c3e64df Mon Sep 17 00:00:00 2001 From: LeoMoulin Date: Thu, 18 Apr 2024 14:09:06 +0200 Subject: [PATCH] Add the management of changeCurriculum requests --- .../Inscription/RequestsController.java | 55 +++++++++ .../ChangeCurriculumRequestRepository.java | 2 + .../UserCurriculumRepository.java | 1 + .../Inscription/AboutChangeCurriculum.vue | 115 ++++++++++++++++++ .../src/Apps/Inscription/ManageRequests.vue | 24 +++- frontend/src/rest/requests.js | 12 ++ 6 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 frontend/src/Apps/Inscription/AboutChangeCurriculum.vue diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java index 83292ec..f423984 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java @@ -20,6 +20,7 @@ import ovh.herisson.Clyde.Tables.Inscription.ScholarshipRequest; import ovh.herisson.Clyde.Tables.Inscription.UnregisterRequest; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import java.util.Map; @@ -196,4 +197,58 @@ public class RequestsController { return new ResponseEntity<>(HttpStatus.OK); } + + @GetMapping("/changecurriculumreq") + public ResponseEntity> getAllChangeCurrReq(@RequestHeader("Authorization") String token){ + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token)) + return new UnauthorizedResponse<>(null); + + ArrayList toReturn = new ArrayList<>(); + + changeCurriculumRequestRepository.findAll().forEach(toReturn::add); + + return new ResponseEntity<>(toReturn, HttpStatus.OK); + } + + @GetMapping("/changecurriculumreq/{id}") + public ResponseEntity getCCrbyId(@RequestHeader("Authorization") String token, @PathVariable long id){ + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token)) + return new UnauthorizedResponse<>(null); + + ChangeCurriculumRequest toReturn = changeCurriculumRequestRepository.findById(id); + return new ResponseEntity<>(toReturn, HttpStatus.OK); + } + + @PatchMapping("/changecurriculumreq/{id}/{newState}") + public ResponseEntity editCCReq(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newState){ + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token)) + return new UnauthorizedResponse<>(null); + + ChangeCurriculumRequest toEdit = changeCurriculumRequestRepository.findById(id); + + toEdit.setState(newState); + + if (newState == RequestState.Accepted){ + //If actual curriculum is not null then we need to set that the user doesn't follow it anymore + User u = toEdit.getUser(); + if (toEdit.getActualCurriculum() != null){ + ArrayList listcurr = userCurriculumRepository.findByUserOrderByCurriculum(u); + + for (int i = 0; i < listcurr.size(); i++){ + if (listcurr.get(i).getCurriculum() == toEdit.getActualCurriculum()){ + listcurr.get(i).setActual(false); + } + } + + userCurriculumRepository.saveAll(listcurr); + } + + Calendar c = Calendar.getInstance(); + UserCurriculum userCurriculum = new UserCurriculum(u, toEdit.getDestinationCurriculum(), c.get(Calendar.YEAR), true); + userCurriculumRepository.save(userCurriculum); + } + + changeCurriculumRequestRepository.save(toEdit); + return new ResponseEntity<>(HttpStatus.OK); + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ChangeCurriculumRequestRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ChangeCurriculumRequestRepository.java index 414f119..0248e43 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ChangeCurriculumRequestRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ChangeCurriculumRequestRepository.java @@ -4,4 +4,6 @@ import org.springframework.data.repository.CrudRepository; import ovh.herisson.Clyde.Tables.ChangeCurriculumRequest; public interface ChangeCurriculumRequestRepository extends CrudRepository { + ChangeCurriculumRequest findById(long id); } + diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserCurriculumRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserCurriculumRepository.java index dbf203e..75922fa 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserCurriculumRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserCurriculumRepository.java @@ -15,4 +15,5 @@ public interface UserCurriculumRepository extends CrudRepository findByUserOrderByCurriculum(User student); UserCurriculum findByUserAndCurriculumAndActual(User user, Curriculum curriculum, boolean actual); + } diff --git a/frontend/src/Apps/Inscription/AboutChangeCurriculum.vue b/frontend/src/Apps/Inscription/AboutChangeCurriculum.vue new file mode 100644 index 0000000..1427446 --- /dev/null +++ b/frontend/src/Apps/Inscription/AboutChangeCurriculum.vue @@ -0,0 +1,115 @@ + + + + + + \ No newline at end of file diff --git a/frontend/src/Apps/Inscription/ManageRequests.vue b/frontend/src/Apps/Inscription/ManageRequests.vue index 7869557..cb8345e 100644 --- a/frontend/src/Apps/Inscription/ManageRequests.vue +++ b/frontend/src/Apps/Inscription/ManageRequests.vue @@ -3,9 +3,15 @@ import {ref} from 'vue' import {validateRegister, getAllRegisters } from '@/rest/ServiceInscription.js' import AboutRequest from "@/Apps/Inscription/AboutRequest.vue"; - import {getAllExemptionsRequest, getAllScholarShipsRequest, getAllUnregisters} from "@/rest/requests.js"; + import { + getAllChangeCurrReq, + getAllExemptionsRequest, + getAllScholarShipsRequest, + getAllUnregisters + } from "@/rest/requests.js"; import AboutScholarship from "@/Apps/Inscription/AboutScholarship.vue"; import AboutUnregister from "@/Apps/Inscription/AboutUnregister.vue"; + import AboutChangeCurriculum from "@/Apps/Inscription/AboutChangeCurriculum.vue"; const requests = ref(await getAllRegisters()); let targetId = ""; @@ -13,7 +19,7 @@ const requestType = ref("inscription"); const filterType = ref("None"); - //0 = liste, 1 = détails, 2 = sure?, 3 = manage scholarship, 4 manage unregister + //0 = liste, 1 = détails, 2 = sure?, 3 = manage scholarship, 4 manage unregister, 5 = manage curriculum change let windowsState = ref(0); async function upPage(id,review){ @@ -35,6 +41,9 @@ break; case "unregister": requests.value = await getAllUnregisters(); + break; + case "curriculum change": + requests.value = await getAllChangeCurrReq(); } } @@ -53,6 +62,7 @@ + Filter : @@ -104,6 +114,13 @@
{{item.state}}
+
+
{{item.date.slice(0,10)}}
+
{{item.user.firstName}}
+
{{item.user.lastName}}
+
{{item.state}}
+
+
@@ -121,6 +138,9 @@
+
+ +