Leo/InscriptionDesEtudiant #161

Merged
LeoMoulin merged 10 commits from Leo/InscriptionDesEtudiant into master 2024-04-18 21:43:48 +02:00
10 changed files with 179 additions and 32 deletions
Showing only changes of commit 058c53dbbc - Show all commits

View File

@ -4,9 +4,12 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Repositories.CourseRepository; import ovh.herisson.Clyde.Repositories.CourseRepository;
import ovh.herisson.Clyde.Repositories.CurriculumRepository;
import ovh.herisson.Clyde.Repositories.Inscription.ChangeCurriculumRequestRepository;
import ovh.herisson.Clyde.Repositories.Inscription.ExemptionsRequestRepository; import ovh.herisson.Clyde.Repositories.Inscription.ExemptionsRequestRepository;
import ovh.herisson.Clyde.Repositories.Inscription.ScholarshipRequestRepository; import ovh.herisson.Clyde.Repositories.Inscription.ScholarshipRequestRepository;
import ovh.herisson.Clyde.Repositories.Inscription.UnregisterRequestRepository; import ovh.herisson.Clyde.Repositories.Inscription.UnregisterRequestRepository;
import ovh.herisson.Clyde.Repositories.UserCurriculumRepository;
import ovh.herisson.Clyde.Repositories.UserRepository; import ovh.herisson.Clyde.Repositories.UserRepository;
import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
import ovh.herisson.Clyde.Services.AuthenticatorService; import ovh.herisson.Clyde.Services.AuthenticatorService;
@ -31,8 +34,12 @@ public class RequestsController {
public final UnregisterRequestRepository unregisterRequestRepository; public final UnregisterRequestRepository unregisterRequestRepository;
public final CourseRepository courseRepository; public final CourseRepository courseRepository;
public final UserService userService; public final UserService userService;
public final UserCurriculumRepository userCurriculumRepository;
public final CurriculumRepository curriculumRepository;
public RequestsController(ExemptionsRequestRepository err, ScholarshipRequestRepository srr, UserRepository userRepository, AuthenticatorService authServ, UnregisterRequestRepository unregisterRequestRepository, CourseRepository courseRepository, UserService userService) { public final ChangeCurriculumRequestRepository changeCurriculumRequestRepository;
public RequestsController(ExemptionsRequestRepository err, ScholarshipRequestRepository srr, UserRepository userRepository, AuthenticatorService authServ, UnregisterRequestRepository unregisterRequestRepository, CourseRepository courseRepository, UserService userService, UserCurriculumRepository userCurriculumRepository, CurriculumRepository curriculumRepository, ChangeCurriculumRequestRepository changeCurriculumRequestRepository) {
this.err = err; this.err = err;
this.srr = srr; this.srr = srr;
this.userRepository = userRepository; this.userRepository = userRepository;
@ -40,6 +47,9 @@ public class RequestsController {
this.unregisterRequestRepository = unregisterRequestRepository; this.unregisterRequestRepository = unregisterRequestRepository;
this.courseRepository = courseRepository; this.courseRepository = courseRepository;
this.userService = userService; this.userService = userService;
this.userCurriculumRepository = userCurriculumRepository;
this.curriculumRepository = curriculumRepository;
this.changeCurriculumRequestRepository = changeCurriculumRequestRepository;
} }
@PostMapping(value="/exemptionreq") @PostMapping(value="/exemptionreq")
@ -135,14 +145,33 @@ public class RequestsController {
@PatchMapping(value = "/unregister/{id}/{newstate}") @PatchMapping(value = "/unregister/{id}/{newstate}")
public ResponseEntity<String> pathUnregReq(@PathVariable long id, @PathVariable RequestState newstate){ public ResponseEntity<String> pathUnregReq(@PathVariable long id, @PathVariable RequestState newstate){
UnregisterRequest unregisterRequest = unregisterRequestRepository.findById(id); UnregisterRequest unregisterRequest = unregisterRequestRepository.findById(id);
User u = userRepository.findById(unregisterRequest.getRegNo());
unregisterRequest.setState(newstate); unregisterRequest.setState(newstate);
if (newstate == RequestState.Accepted){ if (newstate == RequestState.Accepted){
userService.delete(userRepository.findById(unregisterRequest.getRegNo())); ArrayList<UserCurriculum> userCurricula = userCurriculumRepository.findByUserOrderByCurriculum(u);
for (int i = 0; i < userCurricula.size(); i++){
userCurricula.get(i).setActual(false);
}
userCurriculumRepository.saveAll(userCurricula);
} }
unregisterRequestRepository.save(unregisterRequest); unregisterRequestRepository.save(unregisterRequest);
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);
} }
@PostMapping("/changecurriculumreq")
public ResponseEntity<String> addChangeCurrReq(@RequestBody Map<String,Object> reqInfos){
User user = userRepository.findById((Integer) reqInfos.get("userId"));
Curriculum actualCurriculum = curriculumRepository.findById((Integer) reqInfos.get("actualcursus"));
Curriculum destinationCurriculum = curriculumRepository.findById((Integer) reqInfos.get("newcursus"));
ChangeCurriculumRequest changeCurriculumRequest = new ChangeCurriculumRequest(user, actualCurriculum, destinationCurriculum, new Date(), RequestState.Pending);
changeCurriculumRequestRepository.save(changeCurriculumRequest);
return new ResponseEntity<>(HttpStatus.OK);
}
} }

View File

@ -93,12 +93,12 @@ public class MockController {
curriculumService.save(masterinfo1); curriculumService.save(masterinfo1);
curriculumService.save(masterinfo2); curriculumService.save(masterinfo2);
ucr.save(new UserCurriculum(joe, infoBab1, 2022)); ucr.save(new UserCurriculum(joe, infoBab1, 2022, false));
ucr.save(new UserCurriculum(joe, chemistryBab1, 2023)); ucr.save(new UserCurriculum(joe, chemistryBab1, 2023, true));
ucr.save(new UserCurriculum(joe, infoBab1, 2023)); ucr.save(new UserCurriculum(joe, infoBab1, 2023, true));
ucr.save(new UserCurriculum(joe, psychologyBab1, 2020)); ucr.save(new UserCurriculum(joe, psychologyBab1, 2020, false));
ucr.save(new UserCurriculum(popo, infoBab1, 2022)); ucr.save(new UserCurriculum(popo, infoBab1, 2022, false));
ucr.save(new UserCurriculum(popo, infoBab2, 2023)); ucr.save(new UserCurriculum(popo, infoBab2, 2023, true));
Course progra1 = new Course(5,"Programmation et algorithmique 1",joke); Course progra1 = new Course(5,"Programmation et algorithmique 1",joke);
Course chemistry1 = new Course(12, "Thermochimie",joke); Course chemistry1 = new Course(12, "Thermochimie",joke);

View File

@ -0,0 +1,7 @@
package ovh.herisson.Clyde.Repositories.Inscription;
import org.springframework.data.repository.CrudRepository;
import ovh.herisson.Clyde.Tables.ChangeCurriculumRequest;
public interface ChangeCurriculumRequestRepository extends CrudRepository<ChangeCurriculumRequest, Long> {
}

View File

@ -12,6 +12,7 @@ import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest;
import ovh.herisson.Clyde.Tables.Inscription.Minerval; import ovh.herisson.Clyde.Tables.Inscription.Minerval;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
@Service @Service
public class InscriptionService { public class InscriptionService {
@ -85,7 +86,8 @@ public class InscriptionService {
); );
userRepo.save(userFromRequest); userRepo.save(userFromRequest);
userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId()),0)); Calendar c = Calendar.getInstance();
userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId()),c.get(Calendar.YEAR), true));
//Create a minerval for the new student //Create a minerval for the new student
Minerval minerval = new Minerval(userFromRequest.getRegNo(), 0, 852, 2023); Minerval minerval = new Minerval(userFromRequest.getRegNo(), 0, 852, 2023);

View File

@ -35,11 +35,12 @@ public class UserCurriculumService {
HashMap<String, Object> element = new HashMap<>(); HashMap<String, Object> element = new HashMap<>();
Curriculum c = list.get(i).getCurriculum(); Curriculum c = list.get(i).getCurriculum();
element.put("curriculumId", c.getCurriculumId()); element.put("curriculumId", c.getCurriculumId());
element.put("year", c.getYear()); element.put("year", c.getYear());
element.put("option", c.getOption()); element.put("option", c.getOption());
element.put("dateyear", list.get(i).getYear()); element.put("dateyear", list.get(i).getYear());
element.put("actual", list.get(i).isActual());
curriculumlist.add(element); curriculumlist.add(element);
} }

View File

@ -0,0 +1,83 @@
package ovh.herisson.Clyde.Tables;
import jakarta.persistence.*;
import java.util.Date;
@Entity
public class ChangeCurriculumRequest {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@ManyToOne
@JoinColumn(name="Users")
private User user;
@ManyToOne
@JoinColumn(name = "ActualCurriculum")
private Curriculum actualCurriculum;
@ManyToOne
@JoinColumn(name = "DestCurriculum")
private Curriculum destinationCurriculum;
private Date date;
private RequestState state;
public ChangeCurriculumRequest(){}
public ChangeCurriculumRequest(User user, Curriculum actualCurriculum, Curriculum destinationCurriculum, Date date, RequestState state){
this.user = user;
this.actualCurriculum = actualCurriculum;
this.destinationCurriculum = destinationCurriculum;
this.date = date;
this.state = state;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Curriculum getActualCurriculum() {
return actualCurriculum;
}
public void setActualCurriculum(Curriculum actualCurriculum) {
this.actualCurriculum = actualCurriculum;
}
public Curriculum getDestinationCurriculum() {
return destinationCurriculum;
}
public void setDestinationCurriculum(Curriculum destinationCurriculum) {
this.destinationCurriculum = destinationCurriculum;
}
public void setDate(Date date) {
this.date = date;
}
public Date getDate() {
return date;
}
public RequestState getState() {
return state;
}
public void setState(RequestState state) {
this.state = state;
}
public int getId() {
return id;
}
}

View File

@ -23,10 +23,14 @@ public class UserCurriculum {
private int year; private int year;
public UserCurriculum(User user, Curriculum curriculum, int year){ //True if the user has that curriculum at the moment false if not
private boolean actual;
public UserCurriculum(User user, Curriculum curriculum, int year, boolean actual){
this.user = user; this.user = user;
this.curriculum = curriculum; this.curriculum = curriculum;
this.year = year; this.year = year;
this.actual = actual;
} }
public UserCurriculum() {} public UserCurriculum() {}
@ -58,4 +62,12 @@ public class UserCurriculum {
public void setYear(int year) { public void setYear(int year) {
this.year = year; this.year = year;
} }
public void setActual(boolean actual) {
this.actual = actual;
}
public boolean isActual() {
return actual;
}
} }

View File

@ -66,9 +66,9 @@
</div> </div>
<div class="listElement"> <div class="listElement">
<div class=" containerElement" v-for="item in UserCurriculum.curriculumList"> <div class=" containerElement" v-for="item in UserCurriculum.curriculumList">
<div class="year" v-if="parseInt(item.dateyear) !== getYear()">Bac {{item.year}}</div> <div class="year" v-if="item.actual === false">Bac {{item.year}}</div>
<div class="option" v-if="parseInt(item.dateyear) !== getYear()">{{item.option}}</div> <div class="option" v-if="item.actual === false">{{item.option}}</div>
<div class="dateyear" v-if="parseInt(item.dateyear) !== getYear()">Année {{item.dateyear}}-{{item.dateyear+1}}</div> <div class="dateyear" v-if="item.actual === false">Année {{item.dateyear}}-{{item.dateyear+1}}</div>
</div> </div>
</div> </div>
</div> </div>
@ -78,9 +78,9 @@
</div> </div>
<div class="listElement"> <div class="listElement">
<div class=" containerElement" v-for="item in UserCurriculum.curriculumList" > <div class=" containerElement" v-for="item in UserCurriculum.curriculumList" >
<div class="year" v-if="parseInt(item.dateyear) === getYear()">Bac {{item.year}}</div> <div class="year" v-if="item.actual === true">Bac {{item.year}}</div>
<div class="option" v-if="parseInt(item.dateyear) === getYear()">{{item.option}}</div> <div class="option" v-if="item.actual === true">{{item.option}}</div>
<div class="dateyear" v-if="parseInt(item.dateyear) === getYear()">Année {{item.dateyear}}-{{item.dateyear+1}}</div> <div class="dateyear" v-if="item.actual === true">Année {{item.dateyear}}-{{item.dateyear+1}}</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -8,7 +8,7 @@
import CourseList from "@/Apps/Inscription/CourseList.vue"; import CourseList from "@/Apps/Inscription/CourseList.vue";
import {editMinerval, getCurrentMinerval} from "@/rest/minerval.js"; import {editMinerval, getCurrentMinerval} from "@/rest/minerval.js";
import {postPayment} from "@/rest/payment.js"; import {postPayment} from "@/rest/payment.js";
import {addUninscReq, createScholarshipRequest} from "@/rest/requests.js"; import {addUninscReq, createScholarshipRequest, postChangeCurrReq} from "@/rest/requests.js";
const user = ref(await getSelf()); const user = ref(await getSelf());
const UserCurriculum = ref(""); const UserCurriculum = ref("");
@ -62,6 +62,12 @@
residencyDocUrl : "" residencyDocUrl : ""
}) })
const changecurrdata = reactive({
userId : user.value.regNo,
actualcursus:null,
newcursus:null
})
//Used to post a uninscription request //Used to post a uninscription request
const uninscriptionData = reactive({ const uninscriptionData = reactive({
reason : null, reason : null,
@ -132,7 +138,7 @@
function getActualCurriculumList(){ function getActualCurriculumList(){
let actualCurriculumList = []; let actualCurriculumList = [];
for (let i = 0; i < UserCurriculum.value.curriculumList.length; i++){ for (let i = 0; i < UserCurriculum.value.curriculumList.length; i++){
if (UserCurriculum.value.curriculumList[i].dateyear === getYear()){ if (UserCurriculum.value.curriculumList[i].actual === true){
actualCurriculumList.push(UserCurriculum.value.curriculumList[i]); actualCurriculumList.push(UserCurriculum.value.curriculumList[i]);
} }
} }
@ -281,20 +287,23 @@
<input type="password" v-model="toModify.passwordConfirm"> <input type="password" v-model="toModify.passwordConfirm">
</div> </div>
<div> <div>
<button @click=" windowState = 0; ChangeInfos();">{{i18n("courses.confirm")}}</button> <button @click="windowState = 0; ChangeInfos();">{{i18n("courses.confirm")}}</button>
<button @click="windowState = 0; resetInputs(toModify,pattern);" style="float:right;">{{i18n("courses.back")}}</button> <button @click="windowState = 0; resetInputs(toModify,pattern);" style="float:right;">{{i18n("courses.back")}}</button>
</div> </div>
</div> </div>
<div v-else-if="windowState === 2" class="infosContainer"> <div v-else-if="windowState === 2" class="infosContainer">
<div style="height:40px;"> <div style="height:40px;">
{{i18n("Curriculum")}}: {{i18n("Curriculum")}}:
<select v-model="curriculum" > <select v-model="changecurrdata.actualcursus" style="margin-right: 3%">
<option v-for="item in curricula" style="font-size:20px;" :value="item">{{item.option}}</option> <option v-for="item in getActualCurriculumList()" style="font-size:20px;" :value="item.curriculumId">Bac {{item.year}} {{item.option}}</option>
</select>
New Curriculum :
<select v-model="changecurrdata.newcursus">
<option v-for="item in curricula" :value="item.curriculumId">Bac {{item.year}} {{item.option}}</option>
</select> </select>
</div> </div>
<div> <div>
<button @click=" windowState = 0;">{{i18n("courses.confirm")}}</button> <button @click=" windowState = 0;postChangeCurrReq(changecurrdata)">{{i18n("courses.confirm")}}</button>
<button @click="windowState = 0; resetInputs(personnalInfos,patternInfos);" style="float:right;">{{i18n("courses.back")}}</button> <button @click="windowState = 0; resetInputs(personnalInfos,patternInfos);" style="float:right;">{{i18n("courses.back")}}</button>
</div> </div>
</div> </div>
@ -329,9 +338,9 @@
</div> </div>
<div class="listElement"> <div class="listElement">
<div class=" containerElement" v-for="item in UserCurriculum.curriculumList"> <div class=" containerElement" v-for="item in UserCurriculum.curriculumList">
<div class="year" v-if="parseInt(item.dateyear) !== getYear()">Bac {{item.year}}</div> <div class="year" v-if="item.actual === false">Bac {{item.year}}</div>
<div class="option" v-if="parseInt(item.dateyear) !== getYear()">{{item.option}}</div> <div class="option" v-if="item.actual === false">{{item.option}}</div>
<div class="dateyear" v-if="parseInt(item.dateyear) !== getYear()">Année {{item.dateyear}}-{{item.dateyear+1}}</div> <div class="dateyear" v-if="item.actual === false">Année {{item.dateyear}}-{{item.dateyear+1}}</div>
</div> </div>
</div> </div>
</div> </div>
@ -341,9 +350,9 @@
</div> </div>
<div class="listElement"> <div class="listElement">
<div class=" containerElement" v-for="item in UserCurriculum.curriculumList" > <div class=" containerElement" v-for="item in UserCurriculum.curriculumList" >
<div class="year" v-if="parseInt(item.dateyear) === getYear()">Bac {{item.year}}</div> <div class="year" v-if="item.actual === true">Bac {{item.year}}</div>
<div class="option" v-if="parseInt(item.dateyear) === getYear()">{{item.option}}</div> <div class="option" v-if="item.actual === true">{{item.option}}</div>
<div class="dateyear" v-if="parseInt(item.dateyear) === getYear()">Année {{item.dateyear}}-{{item.dateyear+1}}</div> <div class="dateyear" v-if="item.actual === true">Année {{item.dateyear}}-{{item.dateyear+1}}</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -47,3 +47,7 @@ export async function editUnregReq(id, newstate){
export async function getAllPayments(){ export async function getAllPayments(){
return restGet("/payment") return restGet("/payment")
} }
export async function postChangeCurrReq(item){
return restPost("/changecurriculumreq", item)
}