From 21a5dbdb229c76deda3a4cc1639dcb6c4c79ca4d Mon Sep 17 00:00:00 2001 From: LeoMoulin Date: Tue, 9 Apr 2024 15:58:10 +0200 Subject: [PATCH] Implements the possibility to ask for a scholarship for a student --- .../Clyde/EndPoints/RequestsController.java | 18 +++++- .../ScholarshipRequestRepository.java | 8 +++ .../Clyde/Tables/ScholarshipRequest.java | 64 +++++++++++++------ frontend/src/Apps/CourseList.vue | 5 -- frontend/src/Apps/Profil.vue | 56 +++++++++++++++- frontend/src/rest/requests.js | 4 ++ 6 files changed, 126 insertions(+), 29 deletions(-) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/ScholarshipRequestRepository.java 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 e5865d2..3c94497 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/RequestsController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/RequestsController.java @@ -7,26 +7,42 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; 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; @RestController @CrossOrigin(originPatterns = "*", allowCredentials = "true") public class RequestsController { public final ExemptionsRequestRepository err; + public final ScholarshipRequestRepository srr; - public RequestsController(ExemptionsRequestRepository err) { + public RequestsController(ExemptionsRequestRepository err, ScholarshipRequestRepository srr) { this.err = err; + this.srr = srr; } @PostMapping(value="/exemptionreq") public ResponseEntity register(@RequestBody ExemptionsRequest exemptionsRequest){ + //This line ensures that the request is sent in pending state not matter what exemptionsRequest.setState(RequestState.Pending); err.save(exemptionsRequest); return new ResponseEntity<>(HttpStatus.CREATED); } + + @PostMapping(value="/scholarshipreq") + public ResponseEntity register(@RequestBody ScholarshipRequest scholarshipRequest){ + + //This line ensures that the request is sent in pending state not matter what + scholarshipRequest.setState(RequestState.Pending); + + srr.save(scholarshipRequest); + + return new ResponseEntity<>(HttpStatus.CREATED); + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScholarshipRequestRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScholarshipRequestRepository.java new file mode 100644 index 0000000..4404a11 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScholarshipRequestRepository.java @@ -0,0 +1,8 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.ScholarshipRequest; + +public interface ScholarshipRequestRepository extends CrudRepository { + +} 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 1182911..6d8b27d 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/ScholarshipRequest.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/ScholarshipRequest.java @@ -2,35 +2,39 @@ package ovh.herisson.Clyde.Tables; import jakarta.persistence.*; +import java.util.Date; + @Entity public class ScholarshipRequest { @Id @GeneratedValue(strategy = GenerationType.AUTO) - private int id; + private long id; - @ManyToOne - @JoinColumn(name = "Users") - private User user; + private long userId; private RequestState state; - private String requestForm; + private Date date; private int amount; + private String taxDocUrl; + private String residencyDocUrl; - public ScholarshipRequest(User user, RequestState state, String requestForm, int amount){ - this.user = user; + public ScholarshipRequest(long userId, RequestState state, int amount, Date date, String taxDocUrl, String residencyDocUrl){ + this.userId = userId; this.state = state; - this.requestForm = requestForm; this.amount = amount; + this.date = date; + this.taxDocUrl = taxDocUrl; + this.residencyDocUrl = residencyDocUrl; } public ScholarshipRequest(){} - public User getUser() { - return user; + public Long getUserId() { + return userId; } - public void setUser(User user) { - this.user = user; + public void setUserId(Long userId) { + this.userId = userId; } public RequestState getState() { @@ -41,14 +45,6 @@ public class ScholarshipRequest { this.state = state; } - public String getRequestForm() { - return requestForm; - } - - public void setRequestForm(String requestForm) { - this.requestForm = requestForm; - } - public int getAmount() { return amount; } @@ -56,4 +52,32 @@ public class ScholarshipRequest { public void setAmount(int amount) { this.amount = amount; } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public long getId() { + return id; + } + + public String getResidencyDocUrl() { + return residencyDocUrl; + } + + public void setResidencyDocUrl(String residencyDocUrl) { + this.residencyDocUrl = residencyDocUrl; + } + + public String getTaxDocUrl() { + return taxDocUrl; + } + + public void setTaxDocUrl(String taxDocUrl) { + this.taxDocUrl = taxDocUrl; + } } diff --git a/frontend/src/Apps/CourseList.vue b/frontend/src/Apps/CourseList.vue index 77a7dba..22df6fc 100644 --- a/frontend/src/Apps/CourseList.vue +++ b/frontend/src/Apps/CourseList.vue @@ -20,11 +20,6 @@ async function updateCourseList(){ courseslist.value = await getcurriculum(selectedCurriculum.value.curriculumId) } -async function uploadfileandgetpath(file, type){ - const a = await uploadFile(file, type); - exemptReq.justifDocument = a.url -} - async function postExemptionRequest(file, type){ const a = await uploadFile(file, type); exemptReq.justifDocument = a.url diff --git a/frontend/src/Apps/Profil.vue b/frontend/src/Apps/Profil.vue index 4d6052f..65fd97b 100644 --- a/frontend/src/Apps/Profil.vue +++ b/frontend/src/Apps/Profil.vue @@ -4,10 +4,11 @@ import {getSelfCurriculum, getAllCurriculums, getSomeonesCurriculumList} from '../rest/curriculum.js' import {getCourses} from "../rest/courses.js" import i18n from "@/i18n.js" - import { uploadProfilePicture } from '@/rest/uploads.js' + import {uploadFile, uploadProfilePicture} from '@/rest/uploads.js' import CourseList from "@/Apps/CourseList.vue"; import {editMinerval, getCurrentMinerval} from "@/rest/minerval.js"; import {postPayment} from "@/rest/payment.js"; + import {createScholarshipRequest} from "@/rest/requests.js"; const user = ref(await getSelf()); const UserCurriculum = ref(""); @@ -27,6 +28,8 @@ const courseslist = ref(false); const minerval = ref(false); const paymentPage = ref(false); + const scholarship = ref(false); + const scholarshipinfos = ref(false); const pattern = { profilPictureUrl:null, email:null, @@ -50,6 +53,17 @@ expDate:null, amount: null } + + //Used to modelize a scholarship request + const scholarshipData=reactive({ + userId: user.value.regNo, + state:null, + date:null, + amount:0, + taxDocUrl : "", + residencyDocUrl : "" + }) + const paymentAmount = ref(0); let toModify= Object.assign({}, pattern); let personnalInfos = Object.assign({}, patternInfos); @@ -121,6 +135,18 @@ } return actualCurriculumList } + + async function postScholarshipRequest(file1, type1, file2, type2){ + const a = await uploadFile(file1, type1) + scholarshipData.taxDocUrl = a.url; + + const b = await uploadFile(file2, type2) + scholarshipData.residencyDocUrl = b.url; + + scholarshipData.date = Date.now(); + + await createScholarshipRequest(scholarshipData) + }