From 05bff0fa7721e0aa11f1aea298d066afe585078a Mon Sep 17 00:00:00 2001 From: LeoMoulin Date: Sun, 14 Apr 2024 18:29:23 +0200 Subject: [PATCH] Add the uninscription request submission --- .../Inscription/RequestsController.java | 15 +++++- .../UninscriptionRequestRepository.java | 7 +++ .../Inscription/UninscriptionRequest.java | 50 ++++++++++++++++--- frontend/src/Apps/Profil.vue | 31 ++++++++++-- frontend/src/rest/requests.js | 4 ++ 5 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/UninscriptionRequestRepository.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 e67f8ff..61489bf 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,12 +6,14 @@ 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.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 java.util.ArrayList; import java.util.Date; @@ -25,14 +27,15 @@ public class RequestsController { public final ScholarshipRequestRepository srr; public final UserRepository userRepository; public final AuthenticatorService authServ; - + public final UninscriptionRequestRepository uninscriptionRequestRepository; public final CourseRepository courseRepository; - public RequestsController(ExemptionsRequestRepository err, ScholarshipRequestRepository srr, UserRepository userRepository, AuthenticatorService authServ, CourseRepository courseRepository) { + public RequestsController(ExemptionsRequestRepository err, ScholarshipRequestRepository srr, UserRepository userRepository, AuthenticatorService authServ, UninscriptionRequestRepository uninscriptionRequestRepository, CourseRepository courseRepository) { this.err = err; this.srr = srr; this.userRepository = userRepository; this.authServ = authServ; + this.uninscriptionRequestRepository = uninscriptionRequestRepository; this.courseRepository = courseRepository; } @@ -83,4 +86,12 @@ public class RequestsController { return new ResponseEntity<>(toReturn, HttpStatus.OK); } + + @PostMapping(value = "/uninscriptionreq") + 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); + return new ResponseEntity<>(HttpStatus.OK); + } } 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 new file mode 100644 index 0000000..6d38b8c --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/UninscriptionRequestRepository.java @@ -0,0 +1,7 @@ +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/Tables/Inscription/UninscriptionRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UninscriptionRequest.java index 2264b67..e7858c6 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UninscriptionRequest.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UninscriptionRequest.java @@ -1,20 +1,29 @@ package ovh.herisson.Clyde.Tables.Inscription; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +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 int id; + private long id; private RequestState state; + private String reason; + private Date date; - public UninscriptionRequest(RequestState state){ + @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(){} @@ -26,4 +35,33 @@ public class UninscriptionRequest { 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/frontend/src/Apps/Profil.vue b/frontend/src/Apps/Profil.vue index c33a11d..f0a7c2b 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 {createScholarshipRequest} from "@/rest/requests.js"; + import {addUninscReq, createScholarshipRequest} from "@/rest/requests.js"; const user = ref(await getSelf()); const UserCurriculum = ref(""); @@ -30,6 +30,9 @@ const paymentPage = ref(false); const scholarship = ref(false); const scholarshipinfos = ref(false); + const uninscr = ref(false); + const sure = ref(0); + const pattern = { profilPictureUrl:null, email:null, @@ -64,6 +67,11 @@ residencyDocUrl : "" }) + //Used to post a uninscription request + const uninscriptionData = reactive({ + reason : null, + userId : user.value.regNo + }) const paymentAmount = ref(0); let toModify= Object.assign({}, pattern); let personnalInfos = Object.assign({}, patternInfos); @@ -156,7 +164,7 @@
-
+
{{user.firstName}} {{user.lastName}}
@@ -174,7 +182,7 @@
- +
@@ -184,6 +192,19 @@
+
+
Please enter the reason you leave the university
+ +
+ +
+
+ Are you sure that you want to unregister ? + + +
+

You request has been send !

+
Payment : {{minerv.value.toPay}}€ left to pay @@ -306,7 +327,7 @@
-
+
Anciens Cursus @@ -405,7 +426,7 @@ display:flex; align-items:center; justify-content:center; - margin-top:5%; + margin-top:7%; } .containerElement{ justify-content:center; diff --git a/frontend/src/rest/requests.js b/frontend/src/rest/requests.js index 0b52d7e..9df8a1c 100644 --- a/frontend/src/rest/requests.js +++ b/frontend/src/rest/requests.js @@ -18,4 +18,8 @@ export async function getAllExemptionsRequest(){ export async function editEquivalenceState(id, newstate){ return restPatch("/request/registerequiv/"+id+"/"+newstate) +} + +export async function addUninscReq(userId, reason){ + return restPost("/uninscriptionreq", {"userId" : userId, "reason" : reason}) } \ No newline at end of file