Leo/InscriptionDesEtudiants #156

Merged
LeoMoulin merged 23 commits from Leo/InscriptionDesEtudiants into master 2024-04-14 19:49:17 +02:00
8 changed files with 199 additions and 64 deletions
Showing only changes of commit 9d0b3da9d3 - Show all commits

View File

@ -2,10 +2,7 @@ package ovh.herisson.Clyde.EndPoints;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Repositories.MinervalRepository; import ovh.herisson.Clyde.Repositories.*;
import ovh.herisson.Clyde.Repositories.TokenRepository;
import ovh.herisson.Clyde.Repositories.UserCurriculumRepository;
import ovh.herisson.Clyde.Repositories.UserRepository;
import ovh.herisson.Clyde.Services.*; import ovh.herisson.Clyde.Services.*;
import ovh.herisson.Clyde.Tables.*; import ovh.herisson.Clyde.Tables.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -32,7 +29,9 @@ public class MockController {
public final MinervalRepository minervalRepository; 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.tokenRepo = tokenRepo;
this.userRepo = userRepo; this.userRepo = userRepo;
this.tokenService = tokenService; this.tokenService = tokenService;
@ -42,6 +41,7 @@ public class MockController {
this.inscriptionService = inscriptionService; this.inscriptionService = inscriptionService;
this.ucr = ucr; this.ucr = ucr;
this.minervalRepository = minervalRepository; this.minervalRepository = minervalRepository;
this.scholarshipRequestRepository = scholarshipRequestRepository;
} }
/** Saves an example of each user type by : /** Saves an example of each user type by :
@ -100,6 +100,8 @@ public class MockController {
courseService.save(psycho1); courseService.save(psycho1);
courseService.save(commun); 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,progra1));
CurriculumCourseService.save(new CurriculumCourse(infoBab1,commun)); CurriculumCourseService.save(new CurriculumCourse(infoBab1,commun));

View File

@ -2,15 +2,18 @@ package ovh.herisson.Clyde.EndPoints;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping; import ovh.herisson.Clyde.Repositories.CourseRepository;
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.ExemptionsRequestRepository;
import ovh.herisson.Clyde.Repositories.ScholarshipRequestRepository; import ovh.herisson.Clyde.Repositories.ScholarshipRequestRepository;
import ovh.herisson.Clyde.Tables.ExemptionsRequest; import ovh.herisson.Clyde.Repositories.UserRepository;
import ovh.herisson.Clyde.Tables.RequestState; import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
import ovh.herisson.Clyde.Tables.ScholarshipRequest; import ovh.herisson.Clyde.Services.AuthenticatorService;
import ovh.herisson.Clyde.Tables.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
@RestController @RestController
@CrossOrigin(originPatterns = "*", allowCredentials = "true") @CrossOrigin(originPatterns = "*", allowCredentials = "true")
@ -18,17 +21,25 @@ public class RequestsController {
public final ExemptionsRequestRepository err; public final ExemptionsRequestRepository err;
public final ScholarshipRequestRepository srr; 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.err = err;
this.srr = srr; this.srr = srr;
this.userRepository = userRepository;
this.authServ = authServ;
this.courseRepository = courseRepository;
} }
@PostMapping(value="/exemptionreq") @PostMapping(value="/exemptionreq")
public ResponseEntity<String> register(@RequestBody ExemptionsRequest exemptionsRequest){ public ResponseEntity<String> createExemptionReq(@RequestBody Map<String, Object> 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 exemptionsRequest = new ExemptionsRequest(user, course, (String) exemptionsRequestInfo.get("justifDocument"), RequestState.Pending, new Date());
exemptionsRequest.setState(RequestState.Pending);
err.save(exemptionsRequest); err.save(exemptionsRequest);
@ -36,13 +47,38 @@ public class RequestsController {
} }
@PostMapping(value="/scholarshipreq") @PostMapping(value="/scholarshipreq")
public ResponseEntity<String> register(@RequestBody ScholarshipRequest scholarshipRequest){ public ResponseEntity<String> createScholarshipReq(@RequestBody Map<String, Object> 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 srr.save(toCreate);
scholarshipRequest.setState(RequestState.Pending);
srr.save(scholarshipRequest);
return new ResponseEntity<>(HttpStatus.CREATED); return new ResponseEntity<>(HttpStatus.CREATED);
} }
//Get all the exemptions Request
@GetMapping(value = "/exemptionsreq")
public ResponseEntity<ArrayList<ExemptionsRequest>> getAllExemptionsRequests(@RequestHeader("Authorization") String token){
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token))
return new UnauthorizedResponse<>(null);
ArrayList<ExemptionsRequest> toReturn = new ArrayList<>();
err.findAll().forEach(toReturn::add);
return new ResponseEntity<>(toReturn, HttpStatus.OK);
}
//Get all the scholarships requests
@GetMapping(value = "/scholarshipreq")
public ResponseEntity<ArrayList<ScholarshipRequest>> getAllScholarshipRequests(@RequestHeader("Authorization") String token){
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token))
return new UnauthorizedResponse<>(null);
ArrayList<ScholarshipRequest> toReturn = new ArrayList<>();
srr.findAll().forEach(toReturn::add);
return new ResponseEntity<>(toReturn, HttpStatus.OK);
}
} }

View File

@ -2,6 +2,10 @@ package ovh.herisson.Clyde.Tables;
import jakarta.persistence.*; import jakarta.persistence.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import java.util.Date;
@Entity @Entity
public class ExemptionsRequest { public class ExemptionsRequest {
@ -9,37 +13,44 @@ public class ExemptionsRequest {
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
private int id; private int id;
private long userRegNo; @JoinColumn(name = "Users")
private long courseId; @ManyToOne(fetch = FetchType.EAGER)
private User user;
@JoinColumn(name = "Course")
@ManyToOne(fetch = FetchType.EAGER)
private Course course;
private String justifDocument; private String justifDocument;
private RequestState state; private RequestState state;
private Date date;
public ExemptionsRequest(Long userRegNo, long courseId, String justifDocument, RequestState state){ public ExemptionsRequest(User user, Course course, String justifDocument, RequestState state, Date date){
this.userRegNo = userRegNo; this.user = user;
this.courseId = courseId; this.course = course;
this.justifDocument = justifDocument; this.justifDocument = justifDocument;
this.state = state; this.state = state;
this.date = date;
} }
public ExemptionsRequest(){} public ExemptionsRequest(){}
public Long getUserRegNo() { public User getUser() {
return userRegNo; return user;
} }
public void setUserRegNo(Long userRegNo) { public void setUser(User user) {
this.userRegNo = userRegNo; this.user = user;
} }
public long getCourseId() { public Course getCourse() {
return courseId; return course;
} }
public void setCourseId(long courseId) { public void setCourse(Course course) {
this.courseId = courseId; this.course = course;
} }
public String getJustifDocument() { public String getJustifDocument() {
@ -58,4 +69,12 @@ public class ExemptionsRequest {
public void setState(RequestState state) { public void setState(RequestState state) {
this.state = state; this.state = state;
} }
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
} }

View File

@ -1,6 +1,8 @@
package ovh.herisson.Clyde.Tables; package ovh.herisson.Clyde.Tables;
import jakarta.persistence.*; import jakarta.persistence.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import java.util.Date; import java.util.Date;
@ -10,16 +12,17 @@ public class ScholarshipRequest {
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
private long id; private long id;
private long userId; @JoinColumn(name="Users")
@ManyToOne(fetch = FetchType.EAGER)
private User user;
private RequestState state; private RequestState state;
private Date date; private Date date;
private int amount; private int amount;
private String taxDocUrl; private String taxDocUrl;
private String residencyDocUrl; private String residencyDocUrl;
public ScholarshipRequest(long userId, RequestState state, int amount, Date date, String taxDocUrl, String residencyDocUrl){ public ScholarshipRequest(User user, RequestState state, int amount, Date date, String taxDocUrl, String residencyDocUrl){
this.userId = userId; this.user = user;
this.state = state; this.state = state;
this.amount = amount; this.amount = amount;
this.date = date; this.date = date;
@ -29,12 +32,12 @@ public class ScholarshipRequest {
public ScholarshipRequest(){} public ScholarshipRequest(){}
public Long getUserId() { public User getUser() {
return userId; return user;
} }
public void setUserId(Long userId) { public void setUser(User user) {
this.userId = userId; this.user = user;
} }
public RequestState getState() { public RequestState getState() {

View File

@ -28,8 +28,7 @@ async function postExemptionRequest(file, type){
const exemptReq = reactive({ const exemptReq = reactive({
userRegNo : user.regNo, userRegNo : user.regNo,
courseId : null, courseId : null,
justifDocument : "e", justifDocument : "",
state : null
}) })
</script> </script>

View File

@ -3,10 +3,14 @@
import {ref} from 'vue' import {ref} from 'vue'
import {validateRegister, getAllRegisters } from '@/rest/ServiceInscription.js' import {validateRegister, getAllRegisters } from '@/rest/ServiceInscription.js'
import AboutRequest from "@/Apps/AboutRequest.vue"; import AboutRequest from "@/Apps/AboutRequest.vue";
import {getAllExemptionsRequest, getAllScholarShipsRequest} from "@/rest/requests.js";
const requests = ref(await getAllRegisters()); const requests = ref(await getAllRegisters());
let targetId = ""; let targetId = "";
const requestType = ref("inscription");
const filterType = ref("None");
//0 = liste, 1 = détails, 2 = sure? //0 = liste, 1 = détails, 2 = sure?
let windowsState = ref(0); let windowsState = ref(0);
@ -17,6 +21,18 @@
} }
requests.value = await getAllRegisters(); 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();
}
}
</script> </script>
@ -27,18 +43,55 @@
<button style="background-color:rgb(105,05,105);margin-left: 30%" @click="windowsState=0;">Retour</button> <button style="background-color:rgb(105,05,105);margin-left: 30%" @click="windowsState=0;">Retour</button>
</div> </div>
<div v-if="windowsState === 0"> <div v-if="windowsState === 0">
<div style="margin-top: 2%;margin-left: 2%">
<span>Request type : </span>
<select v-model="requestType" @change="loadRequests()">
<option>inscription</option>
<option>scholarship</option>
<option>exemption</option>
</select>
<span style="margin-left: 5%">
Filter :
<select v-model="filterType">
<option>None</option>
<option>Pending</option>
<option>Accepted</option>
<option>Refused</option>
</select>
</span>
</div>
<div style='display:flex; justify-content:center; min-width:1140px;' v-for="item of requests"> <div style='display:flex; justify-content:center; min-width:1140px;' v-for="item of requests">
<div class="bodu"> <div class="bodu" v-if="filterType == 'None' || filterType == item.state">
<div class="container"> <div class="container" style="grid-template-columns:15% 15% 10% 14.2% 14.2% 14.2% 14.2%;grid-template-areas:'date state surname firstname accept refuse infos';" v-if="requestType === 'inscription'">
<div class="date">{{item.submissionDate.slice(0, 10)}}</div> <!--
<div class="state">{{item.state}}</div> The condition below avoids an error occuring because loadRequests() finishes after the vue refresh
<div class="surname">{{item.lastName}}</div> then submissionDate is undefined an it triggers an error in the console despite the fact that it is working
<div class="firstname">{{item.firstName}}</div> properly at the end.
<div class="accept" v-if="item.state === 'Pending'"><button @click="windowsState=2;targetId=item.id;" style="background-color:rgb(0,105,50);">{{i18n("request.accept")}}</button></div> -->
<div class="refuse" v-if="item.state === 'Pending'"><button @click="upPage(item.id,'Refused')" style="background-color:rgb(105,0,0);">{{i18n("request.refuse")}}</button></div> <div class="date" v-if="item.submissionDate !== undefined">{{item.submissionDate.slice(0, 10)}}</div>
<div class="infos"><button style="background-color:rgb(105,05,105);" @click="targetId=item.id;windowsState=1;">{{i18n("request.moreInfos")}}</button></div> <div class="state">{{item.state}}</div>
</div> <div class="surname">{{item.lastName}}</div>
</div> <div class="firstname">{{item.firstName}}</div>
<div class="accept" v-if="item.state === 'Pending'"><button @click="windowsState=2;targetId=item.id;" style="background-color:rgb(0,105,50);">{{i18n("request.accept")}}</button></div>
<div class="refuse" v-if="item.state === 'Pending'"><button @click="upPage(item.id,'Refused')" style="background-color:rgb(105,0,0);">{{i18n("request.refuse")}}</button></div>
<div class="infos"><button style="background-color:rgb(105,05,105);" @click="targetId=item.id;windowsState=1;">{{i18n("request.moreInfos")}}</button></div>
</div>
<div class="container" style="grid-template-columns:25% 15% 15% 25% 14.2%;grid-template-areas:'date reqState studentfirstname studentlastname infos';" v-if="requestType === 'scholarship'">
<div class="date" v-if="item.date !== undefined"> {{item.date.slice(0,10)}}</div>
<div class="studentfirstname">{{item.user.firstName}}</div>
<div class="studentlastname">{{item.user.lastName}}</div>
<div class="reqState">{{item.state}}</div>
<div class="infos"><button>More infos</button></div>
</div>
<div class="container" style="grid-template-columns:17% 15% 12% 15% 25%;grid-template-areas:'date reqState studentfirstname studentlastname course infos';"v-if="requestType === 'exemption'">
<div class="date" v-if="item.date != undefined">{{item.date.slice(0,10)}}</div>
<div class="studentfirstname">{{item.user.firstName}}</div>
<div class="studentlastname">{{item.user.lastName}}</div>
<div class="course">{{item.course.title}}</div>
<div class="reqState">{{item.state}}</div>
<div class="infos"><button>More infos</button></div>
</div>
</div>
</div> </div>
</div> </div>
<div style='display:flex; justify-content:center; min-width:1140px;margin-top: 10%' v-if="windowsState === 2"> <div style='display:flex; justify-content:center; min-width:1140px;margin-top: 10%' v-if="windowsState === 2">
@ -54,12 +107,27 @@
height:100px; height:100px;
font-size:20px; font-size:20px;
display:grid; 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; 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 { .infos {
grid-area:infos; grid-area:infos;
align-self:center; align-self:center;

View File

@ -306,8 +306,8 @@
</div> </div>
</div> </div>
</div> </div>
<div v-if="modif==false && curric==false && reg==false && minerval==false && scholarship == false"class="moreInfos"> <div v-if="user.role == 'Student' && modif==false && curric==false && reg==false && minerval==false && scholarship == false" class="moreInfos">
<div class = "oldcursus"> <div class = "oldcursus">
<div class="listTitle"> <div class="listTitle">
Anciens Cursus Anciens Cursus
</div> </div>

View File

@ -1,9 +1,17 @@
import {restPost} from "@/rest/restConsumer.js"; import {restGet, restPost} from "@/rest/restConsumer.js";
export async function createExemptionsRequest(exempReq){ export async function createExemptionsRequest(exempReq){
return restPost("/exemptionreq", exempReq) return restPost("/exemptionreq", exempReq)
} }
export async function createScholarshipRequest(scholReq){ export async function createScholarshipRequest(reqInfo){
return restPost("/scholarshipreq", scholReq) return restPost("/scholarshipreq", reqInfo)
}
export async function getAllScholarShipsRequest(){
return restGet("/scholarshipreq")
}
export async function getAllExemptionsRequest(){
return restGet("/exemptionsreq")
} }