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 2b4f9d3..faeefb2 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 @@ -103,7 +103,15 @@ public class RequestsController { @PostMapping(value = "/unregister") public ResponseEntity postUnregReq(@RequestBody Map uninscr){ User u = userRepository.findById((int) uninscr.get("userId")); - UnregisterRequest ur = new UnregisterRequest(RequestState.Pending, (String) uninscr.get("reason"), new Date(), u.getRegNo(), u.getFirstName(), u.getLastName(), u.getEmail()); + Curriculum c; + + if (uninscr.get("curriculumId") == null){ + c = null; + }else{ + c = curriculumRepository.findById((Integer) uninscr.get("curriculumId")); + } + + UnregisterRequest ur = new UnregisterRequest(RequestState.Pending, (String) uninscr.get("reason"), new Date(), u.getRegNo(), u.getFirstName(), u.getLastName(), u.getEmail(), c); unregisterRequestRepository.save(ur); return new ResponseEntity<>(HttpStatus.OK); } @@ -149,11 +157,18 @@ public class RequestsController { unregisterRequest.setState(newstate); if (newstate == RequestState.Accepted){ - ArrayList userCurricula = userCurriculumRepository.findByUserOrderByCurriculum(u); - for (int i = 0; i < userCurricula.size(); i++){ - userCurricula.get(i).setActual(false); + if (unregisterRequest.getCurriculum() == null){ + ArrayList userCurricula = userCurriculumRepository.findByUserOrderByCurriculum(u); + for (int i = 0; i < userCurricula.size(); i++){ + userCurricula.get(i).setActual(false); + } + userCurriculumRepository.saveAll(userCurricula); + }else{ + //This usercurriculum will contain the usercurriculum to set false + UserCurriculum userCurriculum = userCurriculumRepository.findByUserAndCurriculumAndActual(u, unregisterRequest.getCurriculum(), true); + userCurriculum.setActual(false); + userCurriculumRepository.save(userCurriculum); } - userCurriculumRepository.saveAll(userCurricula); } unregisterRequestRepository.save(unregisterRequest); diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java index 918a924..3919597 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -128,7 +128,7 @@ public class MockController { inscriptionService.save(inscriptionRequest); - UnregisterRequest unregisterRequest = new UnregisterRequest(RequestState.Pending, "je veux partir", new Date(), joe.getRegNo(), joe.getFirstName(), joe.getLastName(), joe.getEmail()); + UnregisterRequest unregisterRequest = new UnregisterRequest(RequestState.Pending, "je veux partir", new Date(), joe.getRegNo(), joe.getFirstName(), joe.getLastName(), joe.getEmail(), null); uninscriptionRequestRepository.save(unregisterRequest); ExternalCurriculum externalCurriculum = new ExternalCurriculum(inscriptionRequest, "HEH", "Bachelier en informatique", "Completed", 2015, 2018, null, null); 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 2f1c2a3..dbf203e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserCurriculumRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserCurriculumRepository.java @@ -14,4 +14,5 @@ public interface UserCurriculumRepository extends CrudRepository findByUserOrderByCurriculum(User student); + UserCurriculum findByUserAndCurriculumAndActual(User user, Curriculum curriculum, boolean actual); } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UnregisterRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UnregisterRequest.java index ba22294..9127ecb 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UnregisterRequest.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UnregisterRequest.java @@ -1,6 +1,7 @@ package ovh.herisson.Clyde.Tables.Inscription; import jakarta.persistence.*; +import ovh.herisson.Clyde.Tables.Curriculum; import ovh.herisson.Clyde.Tables.RequestState; import ovh.herisson.Clyde.Tables.User; @@ -24,7 +25,12 @@ public class UnregisterRequest { private String email; - public UnregisterRequest(RequestState state, String reason, Date date, long regNo, String firstName, String lastName, String email){ + //Null if the user unregister for the academic year, contains a curriculum if the user wants to unregister from a specific curriculum + @ManyToOne + @JoinColumn(name = "Curriculum") + private Curriculum curriculum; + + public UnregisterRequest(RequestState state, String reason, Date date, long regNo, String firstName, String lastName, String email, Curriculum curriculum){ this.state = state; this.reason = reason; this.date = date; @@ -32,6 +38,7 @@ public class UnregisterRequest { this.firstName = firstName; this.lastName = lastName; this.email = email; + this.curriculum = curriculum; } public UnregisterRequest(){} @@ -95,5 +102,14 @@ public class UnregisterRequest { public long getRegNo() { return regNo; } + + public void setCurriculum(Curriculum curriculum) { + this.curriculum = curriculum; + } + + public Curriculum getCurriculum() { + return curriculum; + } + } diff --git a/frontend/src/Apps/Profil.vue b/frontend/src/Apps/Profil.vue index 28a0763..7a9fbc0 100644 --- a/frontend/src/Apps/Profil.vue +++ b/frontend/src/Apps/Profil.vue @@ -28,6 +28,8 @@ //0 base, 1 modif, 2 curriculum, 3 register, 4 courselist, 5 minerval, 6 payment, 7 scholarship, 8 scholarshipinfos, 9 unregister, 10 sure, 11 aboutunregister const windowState = ref(0); + const isChecked = ref(false); + const pattern = { profilPictureUrl:null, email:null, @@ -71,7 +73,8 @@ //Used to post a uninscription request const uninscriptionData = reactive({ reason : null, - userId : user.value.regNo + userId : user.value.regNo, + curriculumId:null }) const paymentAmount = ref(0); let toModify= Object.assign({}, pattern); @@ -194,14 +197,24 @@
-
Please enter the reason you leave the university
+
Please enter the reason you leave
+
+ I only want to unregister from a specific cursus + +
+
+ Please select that cursus + +
Are you sure that you want to unregister ? - +

You request has been send !

diff --git a/frontend/src/rest/requests.js b/frontend/src/rest/requests.js index a4396a4..4bf8411 100644 --- a/frontend/src/rest/requests.js +++ b/frontend/src/rest/requests.js @@ -20,8 +20,8 @@ export async function editEquivalenceState(id, newstate){ return restPatch("/request/registerequiv/"+id+"/"+newstate) } -export async function addUninscReq(userId, reason){ - return restPost("/unregister", {"userId" : userId, "reason" : reason}) +export async function addUninscReq(userId, reason, curriculumId){ + return restPost("/unregister", {"userId" : userId, "reason" : reason, "curriculumId":curriculumId}) } export async function editScholarshipReq(body){