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 f423984..0d9dbd5 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 @@ -176,6 +176,16 @@ public class RequestsController { return new ResponseEntity<>(HttpStatus.OK); } + //We look in the usercursus table if the student has already the previous year of a curriculum + public boolean studentHasPrevYear(Curriculum curriculum, User user){ + ArrayList userCurrList = userCurriculumRepository.findByUserOrderByCurriculum(user); + for (int i = 0; i < userCurrList.size(); i++){ + if (userCurrList.get(i).getCurriculum().getOption().equals(curriculum.getOption()) && userCurrList.get(i).getCurriculum().getYear() == curriculum.getYear()-1){ + return true; + } + } + return false; + } @PostMapping("/changecurriculumreq") public ResponseEntity addChangeCurrReq(@RequestBody Map reqInfos){ User user = userRepository.findById((Integer) reqInfos.get("userId")); @@ -191,8 +201,12 @@ public class RequestsController { Curriculum destinationCurriculum = curriculumRepository.findById((Integer) reqInfos.get("newcursus")); - ChangeCurriculumRequest changeCurriculumRequest = new ChangeCurriculumRequest(user, actualCurriculum, destinationCurriculum, new Date(), RequestState.Pending); + ChangeCurriculumRequest changeCurriculumRequest = new ChangeCurriculumRequest(user, actualCurriculum, destinationCurriculum, new Date(), RequestState.Pending, RequestState.Unrequired); + //Si l'année du cursus est plus grande que 1 et que l'étudiant n'a pas dans sa liste de cursus l'année d'en dessous alors on demande l'accord du prof + if (destinationCurriculum.getYear() > 1 && !studentHasPrevYear(destinationCurriculum, user)){ + changeCurriculumRequest.setTeacherApprovalState(RequestState.Pending); + } changeCurriculumRequestRepository.save(changeCurriculumRequest); return new ResponseEntity<>(HttpStatus.OK); @@ -228,27 +242,49 @@ public class RequestsController { toEdit.setState(newState); - if (newState == RequestState.Accepted){ + if (newState == RequestState.Accepted && (toEdit.getTeacherApprovalState() == RequestState.Accepted || toEdit.getTeacherApprovalState() == RequestState.Unrequired)){ //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); + acceptProcedure(toEdit); } changeCurriculumRequestRepository.save(toEdit); return new ResponseEntity<>(HttpStatus.OK); } + + @PatchMapping("/changecurriculumreqteacher/{id}/{newteacherstate}") + public ResponseEntity editCCReqTeacherState(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newteacherstate){ + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token)) + return new UnauthorizedResponse<>(null); + + ChangeCurriculumRequest toEdit = changeCurriculumRequestRepository.findById(id); + + toEdit.setState(newteacherstate); + + if (newteacherstate == RequestState.Accepted && toEdit.getState() == RequestState.Accepted){ + //If actual curriculum is not null then we need to set that the user doesn't follow it anymore + acceptProcedure(toEdit); + } + + changeCurriculumRequestRepository.save(toEdit); + return new ResponseEntity<>(HttpStatus.OK); + } + + private void acceptProcedure(ChangeCurriculumRequest toEdit) { + 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); + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/ChangeCurriculumRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/ChangeCurriculumRequest.java index 72feebd..a309023 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/ChangeCurriculumRequest.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/ChangeCurriculumRequest.java @@ -26,14 +26,16 @@ public class ChangeCurriculumRequest { private RequestState state; + private RequestState teacherApprovalState; public ChangeCurriculumRequest(){} - public ChangeCurriculumRequest(User user, Curriculum actualCurriculum, Curriculum destinationCurriculum, Date date, RequestState state){ + public ChangeCurriculumRequest(User user, Curriculum actualCurriculum, Curriculum destinationCurriculum, Date date, RequestState state, RequestState teacherApprovalState){ this.user = user; this.actualCurriculum = actualCurriculum; this.destinationCurriculum = destinationCurriculum; this.date = date; this.state = state; + this.teacherApprovalState = teacherApprovalState; } public User getUser() { @@ -80,4 +82,14 @@ public class ChangeCurriculumRequest { public int getId() { return id; } + + public RequestState getTeacherApprovalState() { + return teacherApprovalState; + } + + public void setTeacherApprovalState(RequestState teacherApprovalState) { + this.teacherApprovalState = teacherApprovalState; + } } + + diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/ReInscriptionRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/ReInscriptionRequest.java deleted file mode 100644 index cafffe6..0000000 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/ReInscriptionRequest.java +++ /dev/null @@ -1,81 +0,0 @@ -package ovh.herisson.Clyde.Tables.Inscription; - -import jakarta.persistence.*; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; -import ovh.herisson.Clyde.Tables.Curriculum; -import ovh.herisson.Clyde.Tables.RequestState; -import ovh.herisson.Clyde.Tables.User; - -@Entity -public class ReInscriptionRequest { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private int id; - - @ManyToOne - @JoinColumn(name = "Users") - @OnDelete(action = OnDeleteAction.CASCADE) - private User user; - - @ManyToOne - @JoinColumn(name = "Curriculum") - @OnDelete(action = OnDeleteAction.CASCADE) - private Curriculum newCurriculum; - private RequestState state; - - //Permet de différencier les demandes de changement et une réinscription dans le même Curriculum - //Pour la réinscription on va le mettre a 0 - private boolean type = false; - - public ReInscriptionRequest(){} - - public ReInscriptionRequest(User user, Curriculum newCurriculum, RequestState state, boolean type){ - this.user = user; - this.newCurriculum = newCurriculum; - this.state = state; - this.type = type; - } - - public ReInscriptionRequest(User user, Curriculum newCurriculum, RequestState state){ - this.user = user; - this.newCurriculum = newCurriculum; - this.state = state; - } - - public int getId() { - return id; - } - - public User getUser() { - return user; - } - - public void setUser(User user) { - this.user = user; - } - - public Curriculum getNewCurriculum() { - return newCurriculum; - } - - public void setNewCurriculum(Curriculum newCurriculum) { - this.newCurriculum = newCurriculum; - } - - public RequestState getState() { - return state; - } - - public void setState(RequestState state) { - this.state = state; - } - - public boolean isType() { - return type; - } - - public void setType(boolean type) { - this.type = type; - } -} diff --git a/frontend/src/Apps/Inscription/AboutChangeCurriculum.vue b/frontend/src/Apps/Inscription/AboutChangeCurriculum.vue index 1427446..82c850d 100644 --- a/frontend/src/Apps/Inscription/AboutChangeCurriculum.vue +++ b/frontend/src/Apps/Inscription/AboutChangeCurriculum.vue @@ -1,21 +1,21 @@ @@ -52,6 +56,10 @@ async function uploadandrefreshChangeRequest(state){ +
+ + +
diff --git a/frontend/src/Apps/Inscription/ManageRequests.vue b/frontend/src/Apps/Inscription/ManageRequests.vue index cb8345e..8fd7ddf 100644 --- a/frontend/src/Apps/Inscription/ManageRequests.vue +++ b/frontend/src/Apps/Inscription/ManageRequests.vue @@ -114,11 +114,12 @@
{{item.state}}
-
+
{{item.date.slice(0,10)}}
{{item.user.firstName}}
{{item.user.lastName}}
-
{{item.state}}
+
IS approval : {{item.state}}
+
Teacher approval : {{item.teacherApprovalState}}
@@ -156,6 +157,11 @@ grid-area: equivalencestate; align-self: center; } + + .teacherApproval{ + grid-area: teacherApproval; + align-self: center; + } .studentfirstname{ grid-area: studentfirstname; align-self: center; diff --git a/frontend/src/Apps/Profil.vue b/frontend/src/Apps/Profil.vue index 70e2451..a9164b2 100644 --- a/frontend/src/Apps/Profil.vue +++ b/frontend/src/Apps/Profil.vue @@ -375,7 +375,7 @@ The cursus you selected has some prerequisites
- +
diff --git a/frontend/src/rest/requests.js b/frontend/src/rest/requests.js index 96c1b14..1d0dfe9 100644 --- a/frontend/src/rest/requests.js +++ b/frontend/src/rest/requests.js @@ -62,4 +62,8 @@ export async function getChangeCurrReqById(id){ export async function editChangeCurrReq(id, newState){ return restPatch("/changecurriculumreq/"+id+"/"+newState) +} + +export async function editChangeCurrReqTeacherState(id, newState){ + return restPatch("/changecurriculumreqteacher/"+id+"/"+newState) } \ No newline at end of file