From c434b28fe385156fa3bdc6669dc9dcb4cb4d8e5a Mon Sep 17 00:00:00 2001 From: LeoMoulin Date: Mon, 15 Apr 2024 20:13:01 +0200 Subject: [PATCH] Add the display for unregister requests Rename all ocurrences of uninscription to unregister Rework the uninscriptionRequest so we have an history and it doesn't take an user so better security --- .../Inscription/RequestsController.java | 25 +++-- .../Clyde/EndPoints/MockController.java | 13 ++- .../UninscriptionRequestRepository.java | 7 -- .../UnregisterRequestRepository.java | 8 ++ .../Inscription/UninscriptionRequest.java | 67 ------------- .../Tables/Inscription/UnregisterRequest.java | 99 +++++++++++++++++++ .../src/Apps/Inscription/ManageRequests.vue | 35 +++++-- frontend/src/rest/requests.js | 6 +- 8 files changed, 162 insertions(+), 98 deletions(-) delete mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/UninscriptionRequestRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/UnregisterRequestRepository.java delete mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UninscriptionRequest.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UnregisterRequest.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 38b9117..d30dab7 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 @@ -6,16 +6,15 @@ import org.springframework.web.bind.annotation.*; import ovh.herisson.Clyde.Repositories.CourseRepository; import ovh.herisson.Clyde.Repositories.Inscription.ExemptionsRequestRepository; import ovh.herisson.Clyde.Repositories.Inscription.ScholarshipRequestRepository; -import ovh.herisson.Clyde.Repositories.Inscription.UninscriptionRequestRepository; +import ovh.herisson.Clyde.Repositories.Inscription.UnregisterRequestRepository; import ovh.herisson.Clyde.Repositories.UserRepository; import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Services.AuthenticatorService; import ovh.herisson.Clyde.Tables.*; import ovh.herisson.Clyde.Tables.Inscription.ExemptionsRequest; import ovh.herisson.Clyde.Tables.Inscription.ScholarshipRequest; -import ovh.herisson.Clyde.Tables.Inscription.UninscriptionRequest; +import ovh.herisson.Clyde.Tables.Inscription.UnregisterRequest; -import javax.swing.text.html.parser.Entity; import java.util.ArrayList; import java.util.Date; import java.util.Map; @@ -28,15 +27,16 @@ public class RequestsController { public final ScholarshipRequestRepository srr; public final UserRepository userRepository; public final AuthenticatorService authServ; - public final UninscriptionRequestRepository uninscriptionRequestRepository; + public final UnregisterRequestRepository unregisterRequestRepository; public final CourseRepository courseRepository; - public RequestsController(ExemptionsRequestRepository err, ScholarshipRequestRepository srr, UserRepository userRepository, AuthenticatorService authServ, UninscriptionRequestRepository uninscriptionRequestRepository, CourseRepository courseRepository) { + + public RequestsController(ExemptionsRequestRepository err, ScholarshipRequestRepository srr, UserRepository userRepository, AuthenticatorService authServ, UnregisterRequestRepository unregisterRequestRepository, CourseRepository courseRepository) { this.err = err; this.srr = srr; this.userRepository = userRepository; this.authServ = authServ; - this.uninscriptionRequestRepository = uninscriptionRequestRepository; + this.unregisterRequestRepository = unregisterRequestRepository; this.courseRepository = courseRepository; } @@ -88,11 +88,11 @@ public class RequestsController { return new ResponseEntity<>(toReturn, HttpStatus.OK); } - @PostMapping(value = "/uninscriptionreq") + @PostMapping(value = "/unregister") public ResponseEntity postUnregReq(@RequestBody Map uninscr){ User u = userRepository.findById((int) uninscr.get("userId")); - UninscriptionRequest ur = new UninscriptionRequest(RequestState.Pending, (String) uninscr.get("reason"), new Date(), u); - uninscriptionRequestRepository.save(ur); + UnregisterRequest ur = new UnregisterRequest(RequestState.Pending, (String) uninscr.get("reason"), new Date(), u.getRegNo(), u.getFirstName(), u.getLastName(), u.getEmail()); + unregisterRequestRepository.save(ur); return new ResponseEntity<>(HttpStatus.OK); } @@ -116,4 +116,11 @@ public class RequestsController { ScholarshipRequest toReturn = srr.findById(id); return new ResponseEntity<>(toReturn, HttpStatus.OK); } + + @GetMapping(value = "/unregister") + public ResponseEntity> getAllUnregReq(){ + ArrayList toReturn = new ArrayList<>(); + unregisterRequestRepository.findAll().forEach(toReturn::add); + return new ResponseEntity<>(toReturn, 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 14fd259..11ca6fd 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -6,13 +6,11 @@ import ovh.herisson.Clyde.Repositories.*; import ovh.herisson.Clyde.Repositories.Inscription.ExternalCurriculumRepository; import ovh.herisson.Clyde.Repositories.Inscription.MinervalRepository; import ovh.herisson.Clyde.Repositories.Inscription.ScholarshipRequestRepository; +import ovh.herisson.Clyde.Repositories.Inscription.UnregisterRequestRepository; import ovh.herisson.Clyde.Services.*; import ovh.herisson.Clyde.Services.Inscription.InscriptionService; import ovh.herisson.Clyde.Tables.*; -import ovh.herisson.Clyde.Tables.Inscription.ExternalCurriculum; -import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest; -import ovh.herisson.Clyde.Tables.Inscription.Minerval; -import ovh.herisson.Clyde.Tables.Inscription.ScholarshipRequest; +import ovh.herisson.Clyde.Tables.Inscription.*; import java.util.ArrayList; import java.util.Arrays; @@ -40,7 +38,8 @@ public class MockController { public final ScholarshipRequestRepository scholarshipRequestRepository; - public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, ExternalCurriculumRepository externalCurriculumRepository, InscriptionService inscriptionService, UserCurriculumRepository ucr, MinervalRepository minervalRepository, ScholarshipRequestRepository scholarshipRequestRepository){ + public final UnregisterRequestRepository uninscriptionRequestRepository; + public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, ExternalCurriculumRepository externalCurriculumRepository, InscriptionService inscriptionService, UserCurriculumRepository ucr, MinervalRepository minervalRepository, ScholarshipRequestRepository scholarshipRequestRepository, UnregisterRequestRepository unregisterRequestRepository){ this.tokenRepo = tokenRepo; this.userRepo = userRepo; this.tokenService = tokenService; @@ -52,6 +51,7 @@ public class MockController { this.ucr = ucr; this.minervalRepository = minervalRepository; this.scholarshipRequestRepository = scholarshipRequestRepository; + this.uninscriptionRequestRepository = unregisterRequestRepository; } /** Saves an example of each user type by : @@ -128,6 +128,9 @@ 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()); + uninscriptionRequestRepository.save(unregisterRequest); + ExternalCurriculum externalCurriculum = new ExternalCurriculum(inscriptionRequest, "HEH", "Bachelier en informatique", "Completed", 2015, 2018, null, null); externalCurriculumRepository.save(externalCurriculum); } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/UninscriptionRequestRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/UninscriptionRequestRepository.java deleted file mode 100644 index 6d38b8c..0000000 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/UninscriptionRequestRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package ovh.herisson.Clyde.Repositories.Inscription; - -import org.springframework.data.repository.CrudRepository; -import ovh.herisson.Clyde.Tables.Inscription.UninscriptionRequest; - -public interface UninscriptionRequestRepository extends CrudRepository { -} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/UnregisterRequestRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/UnregisterRequestRepository.java new file mode 100644 index 0000000..8e6ab5a --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/UnregisterRequestRepository.java @@ -0,0 +1,8 @@ +package ovh.herisson.Clyde.Repositories.Inscription; + +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.Inscription.UnregisterRequest; + +public interface UnregisterRequestRepository extends CrudRepository { + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UninscriptionRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UninscriptionRequest.java deleted file mode 100644 index e7858c6..0000000 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UninscriptionRequest.java +++ /dev/null @@ -1,67 +0,0 @@ -package ovh.herisson.Clyde.Tables.Inscription; - -import jakarta.persistence.*; -import ovh.herisson.Clyde.Tables.RequestState; -import ovh.herisson.Clyde.Tables.User; - -import java.util.Date; - -@Entity -public class UninscriptionRequest { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private long id; - private RequestState state; - private String reason; - private Date date; - - @JoinColumn(name = "Users") - @ManyToOne(fetch = FetchType.EAGER) - private User user; - - public UninscriptionRequest(RequestState state,String reason, Date date, User user){ - this.state = state; - this.reason = reason; - this.date = date; - this.user = user; - } - - public UninscriptionRequest(){} - - public RequestState getState() { - return state; - } - - public void setState(RequestState state) { - this.state = state; - } - - public String getReason() { - return reason; - } - - public void setReason(String reason) { - this.reason = reason; - } - - public long getId() { - return id; - } - - public User getUser() { - return user; - } - - public void setUser(User user) { - this.user = user; - } - - public void setDate(Date date) { - this.date = date; - } - - public Date getDate() { - return date; - } -} - 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 new file mode 100644 index 0000000..ba22294 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UnregisterRequest.java @@ -0,0 +1,99 @@ +package ovh.herisson.Clyde.Tables.Inscription; + +import jakarta.persistence.*; +import ovh.herisson.Clyde.Tables.RequestState; +import ovh.herisson.Clyde.Tables.User; + +import java.util.Date; + +@Entity +public class UnregisterRequest { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + private RequestState state; + private String reason; + private Date date; + + //We store these informations again so if the user is deleted we still have the informations for history + private long regNo; + + private String firstName; + + private String lastName; + + private String email; + + public UnregisterRequest(RequestState state, String reason, Date date, long regNo, String firstName, String lastName, String email){ + this.state = state; + this.reason = reason; + this.date = date; + this.regNo = regNo; + this.firstName = firstName; + this.lastName = lastName; + this.email = email; + } + + public UnregisterRequest(){} + + public RequestState getState() { + return state; + } + + public void setState(RequestState state) { + this.state = state; + } + + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + public long getId() { + return id; + } + + public void setDate(Date date) { + this.date = date; + } + + public Date getDate() { + return date; + } + + public String getEmail() { + return email; + } + + public String getLastName() { + return lastName; + } + + public String getFirstName() { + return firstName; + } + + public void setEmail(String email) { + this.email = email; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public void setRegNo(long regNo) { + this.regNo = regNo; + } + + public long getRegNo() { + return regNo; + } +} + diff --git a/frontend/src/Apps/Inscription/ManageRequests.vue b/frontend/src/Apps/Inscription/ManageRequests.vue index f3a2284..b6a1a50 100644 --- a/frontend/src/Apps/Inscription/ManageRequests.vue +++ b/frontend/src/Apps/Inscription/ManageRequests.vue @@ -3,7 +3,7 @@ import {ref} from 'vue' import {validateRegister, getAllRegisters } from '@/rest/ServiceInscription.js' import AboutRequest from "@/Apps/Inscription/AboutRequest.vue"; - import {getAllExemptionsRequest, getAllScholarShipsRequest} from "@/rest/requests.js"; + import {getAllExemptionsRequest, getAllScholarShipsRequest, getAllUnregisters} from "@/rest/requests.js"; import AboutScholarship from "@/Apps/Inscription/AboutScholarship.vue"; const requests = ref(await getAllRegisters()); @@ -22,14 +22,18 @@ } async function loadRequests(){ - if (requestType.value === "inscription"){ - requests.value = await getAllRegisters(); - } - if (requestType.value === "scholarship"){ - requests.value = await getAllScholarShipsRequest(); - } - if(requestType.value === "exemption"){ - requests.value = await getAllExemptionsRequest(); + switch (requestType.value){ + case "inscription": + requests.value = await getAllRegisters(); + break; + case "scholarship": + requests.value = await getAllScholarShipsRequest(); + break; + case "exemption": + requests.value = await getAllExemptionsRequest(); + break; + case "unregister": + requests.value = await getAllUnregisters(); } } @@ -47,6 +51,7 @@ + Filter : @@ -90,6 +95,14 @@
{{item.state}}
+
+
{{item.date.slice(0,10)}}
+
{{item.firstName}}
+
{{item.lastName}}
+
id : {{item.regNo}}
+
{{item.state}}
+
+
@@ -158,6 +171,10 @@ align-self:center; } + .regno{ + grid-area: regno; + align-self: center; + } .state{ grid-area:state; margin-left:40px; diff --git a/frontend/src/rest/requests.js b/frontend/src/rest/requests.js index e0ae1d6..05140ae 100644 --- a/frontend/src/rest/requests.js +++ b/frontend/src/rest/requests.js @@ -21,7 +21,7 @@ export async function editEquivalenceState(id, newstate){ } export async function addUninscReq(userId, reason){ - return restPost("/uninscriptionreq", {"userId" : userId, "reason" : reason}) + return restPost("/unregister", {"userId" : userId, "reason" : reason}) } export async function editScholarshipReq(body){ @@ -30,4 +30,8 @@ export async function editScholarshipReq(body){ export async function getScholarshipReqById(id){ return restGet("/scholarshipreq/"+id) +} + +export async function getAllUnregisters(){ + return restGet("/unregister") } \ No newline at end of file