From 9d0b3da9d31cbe6102a85e348947cb973336b366 Mon Sep 17 00:00:00 2001 From: LeoMoulin Date: Wed, 10 Apr 2024 14:40:41 +0200 Subject: [PATCH] Implements the backend and frontend methods to get some scholarshipRequests and exemptionsRequest Extends the inscription.vue so that it also list scholarship and exemptions requests (not only inscription) this vue should be renamed later. Also implements some filters and parameters to select the data displayed in the list. --- .../Clyde/EndPoints/MockController.java | 12 ++- .../Clyde/EndPoints/RequestsController.java | 68 ++++++++++--- .../Clyde/Tables/ExemptionsRequest.java | 45 ++++++--- .../Clyde/Tables/ScholarshipRequest.java | 19 ++-- frontend/src/Apps/CourseList.vue | 3 +- frontend/src/Apps/Inscription.vue | 98 ++++++++++++++++--- frontend/src/Apps/Profil.vue | 4 +- frontend/src/rest/requests.js | 14 ++- 8 files changed, 199 insertions(+), 64 deletions(-) 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 0a5d145..1b675ee 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -2,10 +2,7 @@ package ovh.herisson.Clyde.EndPoints; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.web.bind.annotation.*; -import ovh.herisson.Clyde.Repositories.MinervalRepository; -import ovh.herisson.Clyde.Repositories.TokenRepository; -import ovh.herisson.Clyde.Repositories.UserCurriculumRepository; -import ovh.herisson.Clyde.Repositories.UserRepository; +import ovh.herisson.Clyde.Repositories.*; import ovh.herisson.Clyde.Services.*; import ovh.herisson.Clyde.Tables.*; import java.util.ArrayList; @@ -32,7 +29,9 @@ public class MockController { public final MinervalRepository minervalRepository; - public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService, UserCurriculumRepository ucr, MinervalRepository minervalRepository){ + public final ScholarshipRequestRepository scholarshipRequestRepository; + + public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService, UserCurriculumRepository ucr, MinervalRepository minervalRepository, ScholarshipRequestRepository scholarshipRequestRepository){ this.tokenRepo = tokenRepo; this.userRepo = userRepo; this.tokenService = tokenService; @@ -42,6 +41,7 @@ public class MockController { this.inscriptionService = inscriptionService; this.ucr = ucr; this.minervalRepository = minervalRepository; + this.scholarshipRequestRepository = scholarshipRequestRepository; } /** Saves an example of each user type by : @@ -100,6 +100,8 @@ public class MockController { courseService.save(psycho1); courseService.save(commun); + ScholarshipRequest ssr1 = new ScholarshipRequest(joe, RequestState.Pending, 0, new Date(), "test", "test"); + scholarshipRequestRepository.save(ssr1); CurriculumCourseService.save(new CurriculumCourse(infoBab1,progra1)); CurriculumCourseService.save(new CurriculumCourse(infoBab1,commun)); diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/RequestsController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/RequestsController.java index 3c94497..0d39bf7 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/RequestsController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/RequestsController.java @@ -2,15 +2,18 @@ package ovh.herisson.Clyde.EndPoints; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import ovh.herisson.Clyde.Repositories.CourseRepository; import ovh.herisson.Clyde.Repositories.ExemptionsRequestRepository; import ovh.herisson.Clyde.Repositories.ScholarshipRequestRepository; -import ovh.herisson.Clyde.Tables.ExemptionsRequest; -import ovh.herisson.Clyde.Tables.RequestState; -import ovh.herisson.Clyde.Tables.ScholarshipRequest; +import ovh.herisson.Clyde.Repositories.UserRepository; +import ovh.herisson.Clyde.Responses.UnauthorizedResponse; +import ovh.herisson.Clyde.Services.AuthenticatorService; +import ovh.herisson.Clyde.Tables.*; + +import java.util.ArrayList; +import java.util.Date; +import java.util.Map; @RestController @CrossOrigin(originPatterns = "*", allowCredentials = "true") @@ -18,17 +21,25 @@ public class RequestsController { public final ExemptionsRequestRepository err; public final ScholarshipRequestRepository srr; + public final UserRepository userRepository; + public final AuthenticatorService authServ; - public RequestsController(ExemptionsRequestRepository err, ScholarshipRequestRepository srr) { + public final CourseRepository courseRepository; + + public RequestsController(ExemptionsRequestRepository err, ScholarshipRequestRepository srr, UserRepository userRepository, AuthenticatorService authServ, CourseRepository courseRepository) { this.err = err; this.srr = srr; + this.userRepository = userRepository; + this.authServ = authServ; + this.courseRepository = courseRepository; } @PostMapping(value="/exemptionreq") - public ResponseEntity register(@RequestBody ExemptionsRequest exemptionsRequest){ + public ResponseEntity createExemptionReq(@RequestBody Map exemptionsRequestInfo){ + User user = userRepository.findById((Integer) exemptionsRequestInfo.get("userRegNo")); + Course course = courseRepository.findById((Integer) exemptionsRequestInfo.get("courseId")); - //This line ensures that the request is sent in pending state not matter what - exemptionsRequest.setState(RequestState.Pending); + ExemptionsRequest exemptionsRequest = new ExemptionsRequest(user, course, (String) exemptionsRequestInfo.get("justifDocument"), RequestState.Pending, new Date()); err.save(exemptionsRequest); @@ -36,13 +47,38 @@ public class RequestsController { } @PostMapping(value="/scholarshipreq") - public ResponseEntity register(@RequestBody ScholarshipRequest scholarshipRequest){ + public ResponseEntity createScholarshipReq(@RequestBody Map scholarshipRequestInfo){ + User user = userRepository.findById((Integer)scholarshipRequestInfo.get("userId")); + ScholarshipRequest toCreate = new ScholarshipRequest(user, RequestState.Pending, 0, new Date(), (String) scholarshipRequestInfo.get("taxDocUrl"), (String) scholarshipRequestInfo.get("residencyDocUrl")); - //This line ensures that the request is sent in pending state not matter what - scholarshipRequest.setState(RequestState.Pending); - - srr.save(scholarshipRequest); + srr.save(toCreate); return new ResponseEntity<>(HttpStatus.CREATED); } + + //Get all the exemptions Request + @GetMapping(value = "/exemptionsreq") + public ResponseEntity> getAllExemptionsRequests(@RequestHeader("Authorization") String token){ + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token)) + return new UnauthorizedResponse<>(null); + + ArrayList toReturn = new ArrayList<>(); + + err.findAll().forEach(toReturn::add); + + return new ResponseEntity<>(toReturn, HttpStatus.OK); + } + + //Get all the scholarships requests + @GetMapping(value = "/scholarshipreq") + public ResponseEntity> getAllScholarshipRequests(@RequestHeader("Authorization") String token){ + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token)) + return new UnauthorizedResponse<>(null); + + ArrayList toReturn = new ArrayList<>(); + + srr.findAll().forEach(toReturn::add); + + return new ResponseEntity<>(toReturn, HttpStatus.OK); + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/ExemptionsRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/ExemptionsRequest.java index ba01d15..c38e559 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/ExemptionsRequest.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/ExemptionsRequest.java @@ -2,6 +2,10 @@ package ovh.herisson.Clyde.Tables; import jakarta.persistence.*; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +import java.util.Date; @Entity public class ExemptionsRequest { @@ -9,37 +13,44 @@ public class ExemptionsRequest { @GeneratedValue(strategy = GenerationType.AUTO) private int id; - private long userRegNo; - private long courseId; + @JoinColumn(name = "Users") + @ManyToOne(fetch = FetchType.EAGER) + private User user; + + @JoinColumn(name = "Course") + @ManyToOne(fetch = FetchType.EAGER) + private Course course; private String justifDocument; private RequestState state; + private Date date; - public ExemptionsRequest(Long userRegNo, long courseId, String justifDocument, RequestState state){ - this.userRegNo = userRegNo; - this.courseId = courseId; + public ExemptionsRequest(User user, Course course, String justifDocument, RequestState state, Date date){ + this.user = user; + this.course = course; this.justifDocument = justifDocument; this.state = state; + this.date = date; } public ExemptionsRequest(){} - public Long getUserRegNo() { - return userRegNo; + public User getUser() { + return user; } - public void setUserRegNo(Long userRegNo) { - this.userRegNo = userRegNo; + public void setUser(User user) { + this.user = user; } - public long getCourseId() { - return courseId; + public Course getCourse() { + return course; } - public void setCourseId(long courseId) { - this.courseId = courseId; + public void setCourse(Course course) { + this.course = course; } public String getJustifDocument() { @@ -58,4 +69,12 @@ public class ExemptionsRequest { public void setState(RequestState state) { this.state = state; } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/ScholarshipRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/ScholarshipRequest.java index 6d8b27d..3de71ba 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/ScholarshipRequest.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/ScholarshipRequest.java @@ -1,6 +1,8 @@ package ovh.herisson.Clyde.Tables; import jakarta.persistence.*; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import java.util.Date; @@ -10,16 +12,17 @@ public class ScholarshipRequest { @GeneratedValue(strategy = GenerationType.AUTO) private long id; - private long userId; + @JoinColumn(name="Users") + @ManyToOne(fetch = FetchType.EAGER) + private User user; private RequestState state; private Date date; private int amount; - private String taxDocUrl; private String residencyDocUrl; - public ScholarshipRequest(long userId, RequestState state, int amount, Date date, String taxDocUrl, String residencyDocUrl){ - this.userId = userId; + public ScholarshipRequest(User user, RequestState state, int amount, Date date, String taxDocUrl, String residencyDocUrl){ + this.user = user; this.state = state; this.amount = amount; this.date = date; @@ -29,12 +32,12 @@ public class ScholarshipRequest { public ScholarshipRequest(){} - public Long getUserId() { - return userId; + public User getUser() { + return user; } - public void setUserId(Long userId) { - this.userId = userId; + public void setUser(User user) { + this.user = user; } public RequestState getState() { diff --git a/frontend/src/Apps/CourseList.vue b/frontend/src/Apps/CourseList.vue index 22df6fc..7442076 100644 --- a/frontend/src/Apps/CourseList.vue +++ b/frontend/src/Apps/CourseList.vue @@ -28,8 +28,7 @@ async function postExemptionRequest(file, type){ const exemptReq = reactive({ userRegNo : user.regNo, courseId : null, - justifDocument : "e", - state : null + justifDocument : "", }) diff --git a/frontend/src/Apps/Inscription.vue b/frontend/src/Apps/Inscription.vue index 7069c9e..e306d38 100644 --- a/frontend/src/Apps/Inscription.vue +++ b/frontend/src/Apps/Inscription.vue @@ -3,10 +3,14 @@ import {ref} from 'vue' import {validateRegister, getAllRegisters } from '@/rest/ServiceInscription.js' import AboutRequest from "@/Apps/AboutRequest.vue"; + import {getAllExemptionsRequest, getAllScholarShipsRequest} from "@/rest/requests.js"; const requests = ref(await getAllRegisters()); let targetId = ""; + const requestType = ref("inscription"); + const filterType = ref("None"); + //0 = liste, 1 = détails, 2 = sure? let windowsState = ref(0); @@ -17,6 +21,18 @@ } requests.value = await getAllRegisters(); } + + 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(); + } + } @@ -27,18 +43,55 @@
+
+ Request type : + + + Filter : + + +
-
-
-
{{item.submissionDate.slice(0, 10)}}
-
{{item.state}}
-
{{item.lastName}}
-
{{item.firstName}}
-
-
-
-
-
+
+
+ +
{{item.submissionDate.slice(0, 10)}}
+
{{item.state}}
+
{{item.lastName}}
+
{{item.firstName}}
+
+
+
+
+
+
{{item.date.slice(0,10)}}
+
{{item.user.firstName}}
+
{{item.user.lastName}}
+
{{item.state}}
+
+
+
+
{{item.date.slice(0,10)}}
+
{{item.user.firstName}}
+
{{item.user.lastName}}
+
{{item.course.title}}
+
{{item.state}}
+
+
+
@@ -54,12 +107,27 @@ height:100px; font-size:20px; display:grid; - grid-template-columns:15% 15% 10% 14.2% 14.2% 14.2% 14.2%; - grid-template-areas: - "date state surname firstname accept refuse infos"; column-gap:10px; } - + + .studentfirstname{ + grid-area: studentfirstname; + align-self: center; + } + + .studentlastname{ + grid-area: studentlastname; + align-self: center; + } + + .course{ + grid-area: course; + align-self: center; + } + .reqState{ + grid-area: reqState; + align-self: center; + } .infos { grid-area:infos; align-self:center; diff --git a/frontend/src/Apps/Profil.vue b/frontend/src/Apps/Profil.vue index 65fd97b..7d3edb8 100644 --- a/frontend/src/Apps/Profil.vue +++ b/frontend/src/Apps/Profil.vue @@ -306,8 +306,8 @@
-
-
+
+
Anciens Cursus
diff --git a/frontend/src/rest/requests.js b/frontend/src/rest/requests.js index 140be60..eda7418 100644 --- a/frontend/src/rest/requests.js +++ b/frontend/src/rest/requests.js @@ -1,9 +1,17 @@ -import {restPost} from "@/rest/restConsumer.js"; +import {restGet, restPost} from "@/rest/restConsumer.js"; export async function createExemptionsRequest(exempReq){ return restPost("/exemptionreq", exempReq) } -export async function createScholarshipRequest(scholReq){ - return restPost("/scholarshipreq", scholReq) +export async function createScholarshipRequest(reqInfo){ + return restPost("/scholarshipreq", reqInfo) +} + +export async function getAllScholarShipsRequest(){ + return restGet("/scholarshipreq") +} + +export async function getAllExemptionsRequest(){ + return restGet("/exemptionsreq") } \ No newline at end of file