From 058c53dbbc6e5c92555666ed4c47155554c3afd7 Mon Sep 17 00:00:00 2001 From: LeoMoulin Date: Wed, 17 Apr 2024 11:55:56 +0200 Subject: [PATCH] Add the actual in UserCurriculum Rework the unregister procedure Add ChangeCurriculumRequest Add the changeCurriculumRequest submit --- .../Inscription/RequestsController.java | 35 +++++++- .../Clyde/EndPoints/MockController.java | 12 +-- .../ChangeCurriculumRequestRepository.java | 7 ++ .../Inscription/InscriptionService.java | 4 +- .../Clyde/Services/UserCurriculumService.java | 3 +- .../Clyde/Tables/ChangeCurriculumRequest.java | 83 +++++++++++++++++++ .../herisson/Clyde/Tables/UserCurriculum.java | 14 +++- .../src/Apps/Inscription/AboutStudent.vue | 12 +-- frontend/src/Apps/Profil.vue | 37 +++++---- frontend/src/rest/requests.js | 4 + 10 files changed, 179 insertions(+), 32 deletions(-) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ChangeCurriculumRequestRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/ChangeCurriculumRequest.java 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 934e37c..2b4f9d3 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 @@ -4,9 +4,12 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import ovh.herisson.Clyde.Repositories.CourseRepository; +import ovh.herisson.Clyde.Repositories.CurriculumRepository; +import ovh.herisson.Clyde.Repositories.Inscription.ChangeCurriculumRequestRepository; import ovh.herisson.Clyde.Repositories.Inscription.ExemptionsRequestRepository; import ovh.herisson.Clyde.Repositories.Inscription.ScholarshipRequestRepository; import ovh.herisson.Clyde.Repositories.Inscription.UnregisterRequestRepository; +import ovh.herisson.Clyde.Repositories.UserCurriculumRepository; import ovh.herisson.Clyde.Repositories.UserRepository; import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Services.AuthenticatorService; @@ -31,8 +34,12 @@ public class RequestsController { public final UnregisterRequestRepository unregisterRequestRepository; public final CourseRepository courseRepository; public final UserService userService; + public final UserCurriculumRepository userCurriculumRepository; + public final CurriculumRepository curriculumRepository; - public RequestsController(ExemptionsRequestRepository err, ScholarshipRequestRepository srr, UserRepository userRepository, AuthenticatorService authServ, UnregisterRequestRepository unregisterRequestRepository, CourseRepository courseRepository, UserService userService) { + public final ChangeCurriculumRequestRepository changeCurriculumRequestRepository; + + public RequestsController(ExemptionsRequestRepository err, ScholarshipRequestRepository srr, UserRepository userRepository, AuthenticatorService authServ, UnregisterRequestRepository unregisterRequestRepository, CourseRepository courseRepository, UserService userService, UserCurriculumRepository userCurriculumRepository, CurriculumRepository curriculumRepository, ChangeCurriculumRequestRepository changeCurriculumRequestRepository) { this.err = err; this.srr = srr; this.userRepository = userRepository; @@ -40,6 +47,9 @@ public class RequestsController { this.unregisterRequestRepository = unregisterRequestRepository; this.courseRepository = courseRepository; this.userService = userService; + this.userCurriculumRepository = userCurriculumRepository; + this.curriculumRepository = curriculumRepository; + this.changeCurriculumRequestRepository = changeCurriculumRequestRepository; } @PostMapping(value="/exemptionreq") @@ -135,14 +145,33 @@ public class RequestsController { @PatchMapping(value = "/unregister/{id}/{newstate}") public ResponseEntity pathUnregReq(@PathVariable long id, @PathVariable RequestState newstate){ UnregisterRequest unregisterRequest = unregisterRequestRepository.findById(id); - + User u = userRepository.findById(unregisterRequest.getRegNo()); unregisterRequest.setState(newstate); if (newstate == RequestState.Accepted){ - userService.delete(userRepository.findById(unregisterRequest.getRegNo())); + ArrayList userCurricula = userCurriculumRepository.findByUserOrderByCurriculum(u); + for (int i = 0; i < userCurricula.size(); i++){ + userCurricula.get(i).setActual(false); + } + userCurriculumRepository.saveAll(userCurricula); } unregisterRequestRepository.save(unregisterRequest); return new ResponseEntity<>(HttpStatus.OK); } + + @PostMapping("/changecurriculumreq") + public ResponseEntity addChangeCurrReq(@RequestBody Map reqInfos){ + User user = userRepository.findById((Integer) reqInfos.get("userId")); + + Curriculum actualCurriculum = curriculumRepository.findById((Integer) reqInfos.get("actualcursus")); + + Curriculum destinationCurriculum = curriculumRepository.findById((Integer) reqInfos.get("newcursus")); + + ChangeCurriculumRequest changeCurriculumRequest = new ChangeCurriculumRequest(user, actualCurriculum, destinationCurriculum, new Date(), RequestState.Pending); + + changeCurriculumRequestRepository.save(changeCurriculumRequest); + + return new ResponseEntity<>(HttpStatus.OK); + } } 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 11ca6fd..918a924 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -93,12 +93,12 @@ public class MockController { curriculumService.save(masterinfo1); curriculumService.save(masterinfo2); - ucr.save(new UserCurriculum(joe, infoBab1, 2022)); - ucr.save(new UserCurriculum(joe, chemistryBab1, 2023)); - ucr.save(new UserCurriculum(joe, infoBab1, 2023)); - ucr.save(new UserCurriculum(joe, psychologyBab1, 2020)); - ucr.save(new UserCurriculum(popo, infoBab1, 2022)); - ucr.save(new UserCurriculum(popo, infoBab2, 2023)); + ucr.save(new UserCurriculum(joe, infoBab1, 2022, false)); + ucr.save(new UserCurriculum(joe, chemistryBab1, 2023, true)); + ucr.save(new UserCurriculum(joe, infoBab1, 2023, true)); + ucr.save(new UserCurriculum(joe, psychologyBab1, 2020, false)); + ucr.save(new UserCurriculum(popo, infoBab1, 2022, false)); + ucr.save(new UserCurriculum(popo, infoBab2, 2023, true)); Course progra1 = new Course(5,"Programmation et algorithmique 1",joke); Course chemistry1 = new Course(12, "Thermochimie",joke); 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 new file mode 100644 index 0000000..414f119 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ChangeCurriculumRequestRepository.java @@ -0,0 +1,7 @@ +package ovh.herisson.Clyde.Repositories.Inscription; + +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.ChangeCurriculumRequest; + +public interface ChangeCurriculumRequestRepository extends CrudRepository { +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java index c80e2d9..a40f537 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java @@ -12,6 +12,7 @@ import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest; import ovh.herisson.Clyde.Tables.Inscription.Minerval; import java.util.ArrayList; +import java.util.Calendar; @Service public class InscriptionService { @@ -85,7 +86,8 @@ public class InscriptionService { ); userRepo.save(userFromRequest); - userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId()),0)); + Calendar c = Calendar.getInstance(); + userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId()),c.get(Calendar.YEAR), true)); //Create a minerval for the new student Minerval minerval = new Minerval(userFromRequest.getRegNo(), 0, 852, 2023); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/UserCurriculumService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/UserCurriculumService.java index 8b446df..2861a6e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/UserCurriculumService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/UserCurriculumService.java @@ -35,11 +35,12 @@ public class UserCurriculumService { HashMap element = new HashMap<>(); Curriculum c = list.get(i).getCurriculum(); - element.put("curriculumId", c.getCurriculumId()); element.put("year", c.getYear()); element.put("option", c.getOption()); element.put("dateyear", list.get(i).getYear()); + element.put("actual", list.get(i).isActual()); + curriculumlist.add(element); } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/ChangeCurriculumRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/ChangeCurriculumRequest.java new file mode 100644 index 0000000..72feebd --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/ChangeCurriculumRequest.java @@ -0,0 +1,83 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + +import java.util.Date; + +@Entity +public class ChangeCurriculumRequest { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @ManyToOne + @JoinColumn(name="Users") + private User user; + + @ManyToOne + @JoinColumn(name = "ActualCurriculum") + private Curriculum actualCurriculum; + + @ManyToOne + @JoinColumn(name = "DestCurriculum") + private Curriculum destinationCurriculum; + + private Date date; + + private RequestState state; + + public ChangeCurriculumRequest(){} + + public ChangeCurriculumRequest(User user, Curriculum actualCurriculum, Curriculum destinationCurriculum, Date date, RequestState state){ + this.user = user; + this.actualCurriculum = actualCurriculum; + this.destinationCurriculum = destinationCurriculum; + this.date = date; + this.state = state; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + + public Curriculum getActualCurriculum() { + return actualCurriculum; + } + + public void setActualCurriculum(Curriculum actualCurriculum) { + this.actualCurriculum = actualCurriculum; + } + + public Curriculum getDestinationCurriculum() { + return destinationCurriculum; + } + + public void setDestinationCurriculum(Curriculum destinationCurriculum) { + this.destinationCurriculum = destinationCurriculum; + } + + public void setDate(Date date) { + this.date = date; + } + + public Date getDate() { + return date; + } + + public RequestState getState() { + return state; + } + + public void setState(RequestState state) { + this.state = state; + } + + public int getId() { + return id; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCurriculum.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCurriculum.java index b79295b..395eca7 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCurriculum.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCurriculum.java @@ -23,10 +23,14 @@ public class UserCurriculum { private int year; - public UserCurriculum(User user, Curriculum curriculum, int year){ + //True if the user has that curriculum at the moment false if not + private boolean actual; + + public UserCurriculum(User user, Curriculum curriculum, int year, boolean actual){ this.user = user; this.curriculum = curriculum; this.year = year; + this.actual = actual; } public UserCurriculum() {} @@ -58,4 +62,12 @@ public class UserCurriculum { public void setYear(int year) { this.year = year; } + + public void setActual(boolean actual) { + this.actual = actual; + } + + public boolean isActual() { + return actual; + } } diff --git a/frontend/src/Apps/Inscription/AboutStudent.vue b/frontend/src/Apps/Inscription/AboutStudent.vue index 03368c2..54d81fc 100644 --- a/frontend/src/Apps/Inscription/AboutStudent.vue +++ b/frontend/src/Apps/Inscription/AboutStudent.vue @@ -66,9 +66,9 @@
-
Bac {{item.year}}
-
{{item.option}}
-
Année {{item.dateyear}}-{{item.dateyear+1}}
+
Bac {{item.year}}
+
{{item.option}}
+
Année {{item.dateyear}}-{{item.dateyear+1}}
@@ -78,9 +78,9 @@
-
Bac {{item.year}}
-
{{item.option}}
-
Année {{item.dateyear}}-{{item.dateyear+1}}
+
Bac {{item.year}}
+
{{item.option}}
+
Année {{item.dateyear}}-{{item.dateyear+1}}
diff --git a/frontend/src/Apps/Profil.vue b/frontend/src/Apps/Profil.vue index f31f5da..28a0763 100644 --- a/frontend/src/Apps/Profil.vue +++ b/frontend/src/Apps/Profil.vue @@ -8,7 +8,7 @@ import CourseList from "@/Apps/Inscription/CourseList.vue"; import {editMinerval, getCurrentMinerval} from "@/rest/minerval.js"; import {postPayment} from "@/rest/payment.js"; - import {addUninscReq, createScholarshipRequest} from "@/rest/requests.js"; + import {addUninscReq, createScholarshipRequest, postChangeCurrReq} from "@/rest/requests.js"; const user = ref(await getSelf()); const UserCurriculum = ref(""); @@ -62,6 +62,12 @@ residencyDocUrl : "" }) + const changecurrdata = reactive({ + userId : user.value.regNo, + actualcursus:null, + newcursus:null + }) + //Used to post a uninscription request const uninscriptionData = reactive({ reason : null, @@ -132,7 +138,7 @@ function getActualCurriculumList(){ let actualCurriculumList = []; for (let i = 0; i < UserCurriculum.value.curriculumList.length; i++){ - if (UserCurriculum.value.curriculumList[i].dateyear === getYear()){ + if (UserCurriculum.value.curriculumList[i].actual === true){ actualCurriculumList.push(UserCurriculum.value.curriculumList[i]); } } @@ -281,20 +287,23 @@
- +
- {{i18n("Curriculum")}}: - + + + New Curriculum : +
-
- +
@@ -329,9 +338,9 @@
-
Bac {{item.year}}
-
{{item.option}}
-
Année {{item.dateyear}}-{{item.dateyear+1}}
+
Bac {{item.year}}
+
{{item.option}}
+
Année {{item.dateyear}}-{{item.dateyear+1}}
@@ -341,9 +350,9 @@
-
Bac {{item.year}}
-
{{item.option}}
-
Année {{item.dateyear}}-{{item.dateyear+1}}
+
Bac {{item.year}}
+
{{item.option}}
+
Année {{item.dateyear}}-{{item.dateyear+1}}
diff --git a/frontend/src/rest/requests.js b/frontend/src/rest/requests.js index 9d43968..a4396a4 100644 --- a/frontend/src/rest/requests.js +++ b/frontend/src/rest/requests.js @@ -46,4 +46,8 @@ export async function editUnregReq(id, newstate){ export async function getAllPayments(){ return restGet("/payment") +} + +export async function postChangeCurrReq(item){ + return restPost("/changecurriculumreq", item) } \ No newline at end of file