Fix the implementation of externalCurriculum upload

This commit is contained in:
LeoMoulin 2024-04-04 16:54:11 +02:00
parent 8442101c40
commit 648b73b585
7 changed files with 167 additions and 44 deletions

View File

@ -4,11 +4,11 @@ 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.*; import org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Repositories.ExternalCurriculumRepository;
import ovh.herisson.Clyde.Repositories.InscriptionRepository;
import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
import ovh.herisson.Clyde.Services.*; import ovh.herisson.Clyde.Services.*;
import ovh.herisson.Clyde.Tables.Curriculum; import ovh.herisson.Clyde.Tables.*;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.User;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -23,15 +23,18 @@ public class CurriculumController {
private final UserCurriculumService userCurriculumServ; private final UserCurriculumService userCurriculumServ;
private final CurriculumCourseService curriculumCourseServ; private final CurriculumCourseService curriculumCourseServ;
private final InscriptionRepository ir;
private final UserService userServ; private final UserService userServ;
public CurriculumController(CurriculumService curriculumServ, AuthenticatorService authServ, UserCurriculumService userCurriculumServ, CurriculumCourseService curriculumCourseServ, UserService userServ){ private final ExternalCurriculumRepository ecr;
public CurriculumController(CurriculumService curriculumServ, AuthenticatorService authServ, UserCurriculumService userCurriculumServ, CurriculumCourseService curriculumCourseServ, InscriptionRepository ir, UserService userServ, ExternalCurriculumRepository ecr){
this.curriculumServ = curriculumServ; this.curriculumServ = curriculumServ;
this.authServ = authServ; this.authServ = authServ;
this.userCurriculumServ = userCurriculumServ; this.userCurriculumServ = userCurriculumServ;
this.curriculumCourseServ = curriculumCourseServ; this.curriculumCourseServ = curriculumCourseServ;
this.ir = ir;
this.userServ = userServ; this.userServ = userServ;
this.ecr = ecr;
} }
@GetMapping("/curriculum/{id}") @GetMapping("/curriculum/{id}")
@ -116,13 +119,12 @@ public class CurriculumController {
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);
} }
@GetMapping("/externalcurriculum/{userId}") @GetMapping("/externalcurriculum/{inscriptionRequestId}")
public ResponseEntity<Map<String,Object>> getStudentsExternalCurriculum(@RequestHeader("Authorization") String token, @PathVariable String userId){ public ResponseEntity<Map<String,Object>> getInscriptionRequestExternalCurriculum(@RequestHeader("Authorization") String token, @PathVariable String inscriptionRequestId){
if (authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin, Role.Teacher},token)) if (authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin, Role.Teacher},token))
return new UnauthorizedResponse<>(null); return new UnauthorizedResponse<>(null);
User u = userServ.getUserById(Long.parseLong(userId)); HashMap<String,Object> toReturn = userCurriculumServ.findAllExternalCurriculumByInscriptionRequestId(Long.parseLong(inscriptionRequestId));
HashMap<String,Object> toReturn = userCurriculumServ.findAllExternalCurriculumByStudent(u);
if (toReturn == null) if (toReturn == null)
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
@ -131,4 +133,11 @@ public class CurriculumController {
} }
//Note : everyone can post some externalcurriculums (the validity of the elements is assured by the inscription service)
@PostMapping("/externalcurriculum")
public ResponseEntity<ExternalCurriculum> postExternalCurriculum(@RequestBody ExternalCurriculum ec){
ec.setState(RequestState.Pending);
return new ResponseEntity<>(ecr.save(ec), HttpStatus.OK);
}
} }

View File

@ -2,10 +2,11 @@ package ovh.herisson.Clyde.Repositories;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import ovh.herisson.Clyde.Tables.ExternalCurriculum; import ovh.herisson.Clyde.Tables.ExternalCurriculum;
import ovh.herisson.Clyde.Tables.InscriptionRequest;
import ovh.herisson.Clyde.Tables.User; import ovh.herisson.Clyde.Tables.User;
import java.util.ArrayList; import java.util.ArrayList;
public interface ExternalCurriculumRepository extends CrudRepository<ExternalCurriculum, Long> { public interface ExternalCurriculumRepository extends CrudRepository<ExternalCurriculum, Long> {
ArrayList<ExternalCurriculum> getExternalCurriculumByUser(User user); ArrayList<ExternalCurriculum> getExternalCurriculumByInscriptionRequestId(Long id);
} }

View File

@ -4,10 +4,7 @@ import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Repositories.CurriculumRepository; import ovh.herisson.Clyde.Repositories.CurriculumRepository;
import ovh.herisson.Clyde.Repositories.ExternalCurriculumRepository; import ovh.herisson.Clyde.Repositories.ExternalCurriculumRepository;
import ovh.herisson.Clyde.Repositories.UserCurriculumRepository; import ovh.herisson.Clyde.Repositories.UserCurriculumRepository;
import ovh.herisson.Clyde.Tables.Curriculum; import ovh.herisson.Clyde.Tables.*;
import ovh.herisson.Clyde.Tables.ExternalCurriculum;
import ovh.herisson.Clyde.Tables.User;
import ovh.herisson.Clyde.Tables.UserCurriculum;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -52,16 +49,16 @@ public class UserCurriculumService {
} }
public HashMap<String,Object> findAllExternalCurriculumByStudent(User student) { public HashMap<String,Object> findAllExternalCurriculumByInscriptionRequestId(Long id) {
ArrayList<ExternalCurriculum> list = externalCurriculumRepo.getExternalCurriculumByUser(student); ArrayList<ExternalCurriculum> list = externalCurriculumRepo.getExternalCurriculumByInscriptionRequestId(id);
ArrayList<HashMap<String, Object>> externalCurriculumList = new ArrayList<HashMap<String, Object>>(); ArrayList<HashMap<String, Object>> externalCurriculumList = new ArrayList<HashMap<String, Object>>();
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
HashMap<String, Object> element = new HashMap<>(); HashMap<String, Object> element = new HashMap<>();
element.put("id", list.get(0).getId()); element.put("id", list.get(0).getId());
element.put("user", list.get(0).getUser()); element.put("inscriptionRequestId", list.get(0).getInscriptionRequestId());
element.put("university", list.get(0).getUniversity()); element.put("school", list.get(0).getSchool());
element.put("formation", list.get(0).getFormation()); element.put("formation", list.get(0).getFormation());
element.put("completion", list.get(0).getCompletion()); element.put("completion", list.get(0).getCompletion());
element.put("startYear", list.get(0).getStartYear()); element.put("startYear", list.get(0).getStartYear());

View File

@ -10,13 +10,9 @@ public class ExternalCurriculum {
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
private int id; private int id;
@ManyToOne private Long inscriptionRequestId;
@JoinColumn(name="Users")
private User user;
@ManyToOne private String school;
@JoinColumn(name="University")
private University university;
private String formation; private String formation;
@ -32,9 +28,9 @@ public class ExternalCurriculum {
public ExternalCurriculum(){} public ExternalCurriculum(){}
public ExternalCurriculum(User user, University university, String formation, String completion, int startYear, int endYear, String justifdocUrl, RequestState state){ public ExternalCurriculum(Long ir, String school, String formation, String completion, int startYear, int endYear, String justifdocUrl, RequestState state){
this.user = user; this.inscriptionRequestId = ir;
this.university = university; this.school = school;
this.formation = formation; this.formation = formation;
this.completion = completion; this.completion = completion;
this.startYear = startYear; this.startYear = startYear;
@ -47,20 +43,20 @@ public class ExternalCurriculum {
return id; return id;
} }
public User getUser() { public Long getInscriptionRequestId() {
return user; return inscriptionRequestId;
} }
public void setUser(User user) { public void setInscriptionRequest(Long inscriptionRequestId) {
this.user = user; this.inscriptionRequestId = inscriptionRequestId;
} }
public University getUniversity() { public String getSchool() {
return university; return school;
} }
public void setUniversity(University university) { public void setSchool(String school) {
this.university = university; this.school = school;
} }
public String getFormation() { public String getFormation() {

View File

@ -15,7 +15,6 @@ public class InscriptionRequest {
private String email; private String email;
private String country; private String country;
private Date birthDate; private Date birthDate;
private Long curriculumId; private Long curriculumId;
private RequestState state; private RequestState state;
private String profilePicture; private String profilePicture;

View File

@ -1,13 +1,12 @@
<script setup> <script setup>
import {reactive, ref } from 'vue' import {reactive, ref } from 'vue'
import i18n from '@/i18n.js' import i18n from '@/i18n.js'
import { login , register , disconnect, isLogged} from '@/rest/Users.js' import {login, register, disconnect, isLogged} from '@/rest/Users.js'
import { getAllCurriculums } from '@/rest/curriculum.js' import {createExternalCurriculum, getAllCurriculums, getcurriculum} from '@/rest/curriculum.js'
import { uploadProfilePicture } from '@/rest/uploads.js' import { uploadProfilePicture } from '@/rest/uploads.js'
import {toast} from 'vue3-toastify' import {toast} from 'vue3-toastify'
import 'vue3-toastify/dist/index.css'; import 'vue3-toastify/dist/index.css';
const loginPage= ref(true) const loginPage= ref(true)
const page = ref(0) const page = ref(0)
@ -22,12 +21,30 @@
curriculum:null, curriculum:null,
}) })
const notcompletedCheck = ref(false);
const externalCurr = reactive({
inscriptionRequestId : null,
school:null,
formation :null,
completion : null,
startYear : null,
endYear: null,
justifdocUrl : null
})
//Stores some externalCurriculums in order to upload them all at the confirmation of the registration request
const externalCurrTab = ref([]);
const submitValue= ref(i18n("login.guest.submit")) const submitValue= ref(i18n("login.guest.submit"))
const passwordConfirm=ref("") const passwordConfirm=ref("")
const imageSaved = ref(false) const imageSaved = ref(false)
let ppData = "" let ppData = ""
//Contains the id of the newly created request (useful to link the student's formations informations to the request)
let requestId = ""
const curricula= await getAllCurriculums(); const curricula= await getAllCurriculums();
function goBackHome(){ function goBackHome(){
@ -69,6 +86,26 @@
let id = cursus.substring(0, cursus.indexOf(" ")+1); let id = cursus.substring(0, cursus.indexOf(" ")+1);
return id; return id;
} }
async function getCurriculumYear(curriculumId){
const curriculum = await getcurriculum(curriculumId);
return parseInt(curriculum.year);
}
//Post the register request and return the id of the newly created request and also post the external curriculum list in the database
async function postRegisterReq(){
const val = await register(outputs.firstname, outputs.surname, outputs.birthday, outputs.password, outputs.email, outputs.address, outputs.country, parseDecoratedCursus(outputs.curriculum), ppData, null, new Date());
for (let item in externalCurrTab.value){
await createExternalCurriculum(val.id, externalCurrTab.value[item].school, externalCurrTab.value[item].formation, externalCurrTab.value[item].completion, externalCurrTab.value[item].startYear, externalCurrTab.value[item].endYear, externalCurrTab.value[item].justifdocUrl);
}
}
function deleteExtCursus(extcursus){
externalCurrTab.value.splice(externalCurrTab.value.indexOf(extcursus),1)
}
</script> </script>
@ -168,7 +205,7 @@
changer de cursus/réinscription sinon continuez ici. changer de cursus/réinscription sinon continuez ici.
</p> </p>
<div style="align-self:center;" class="inputBox"> <div style="align-self:center;" class="inputBox">
<button style="margin-top:25px;" @click="page++; register(outputs.firstname, outputs.surname, outputs.birthday, outputs.password, outputs.email, outputs.address, outputs.country, parseDecoratedCursus(outputs.curriculum), ppData, null, new Date());"> <button style="margin-top:25px;" @click="page++;">
{{i18n("login.guest.nextpage")}} {{i18n("login.guest.nextpage")}}
</button> </button>
</div> </div>
@ -183,9 +220,63 @@
<form novalidate enctype="multipart/form-data" class="inputBox"> <form novalidate enctype="multipart/form-data" class="inputBox">
Carte d'identité : Carte d'identité :
</form> </form>
<button @click="page++">{{i18n("login.guest.nextpage")}}</button>
</div>
<div v-if="page === 3">
<p>
Vous avez séléctionné un cursus qui possède des prérequis veuillez ajouter vos formations antérieures
dans l'enseignement supérieur, votre dossier sera vérifié par un membre du service d'inscription.
</p>
<button @click="page++">Ajouter une formation</button>
<button @click="postRegisterReq();">Envoyer la demande d'inscription</button>
</div>
<div v-if="page===4">
<form @submit.prevent=""class="form">
<div class="inputBox">
<p>Ecole</p>
<input type="text" v-model="externalCurr.school">
</div>
<div class="inputBox">
<p>Formation</p>
<input type="text" v-model="externalCurr.formation">
</div>
<div class="inputBox">
<p>Cochez la case si vous n'avez terminé cette formation</p>
<input v-model="notcompletedCheck" type="checkbox" id="checkboxformation">
<div v-if="notcompletedCheck">
<p>En quelle année de la formation vous êtes vous arrété (exemple: 3ème) ?</p>
<input type="text" v-model="externalCurr.completion">
</div>
</div>
<div class="inputBox">
<p>Année de début</p>
<input type="text" v-model="externalCurr.startYear">
</div>
<div class="inputBox">
<p>Année de fin</p>
<input type="text" v-model="externalCurr.endYear">
</div>
<div class="inputBox" style="margin-bottom:35px;">
<input type="submit" v-model="submitValue" @click="externalCurrTab.push({inscriptionReqId:null, school:externalCurr.school, formation:externalCurr.formation, completion:externalCurr.completion, startYear:externalCurr.startYear, endYear:externalCurr.endYear, justifdocUrl:externalCurr.justifdocUrl});console.log(externalCurrTab);page--;">
</div> </div>
</form> </form>
</div> </div>
</form>
</div>
</div>
</div>
<div style="display:flex; justify-content:center; " v-for="item in externalCurrTab" v-if="page===3">
<div class="bodu">
<div class="container">
<div class="school"><a style="margin-left:30px;">{{item.school}}</a></div>
<div class="formation"><a>{{item.formation}}</a></div>
<div class="edit">
<button style="background-color:rgb(105,05,105);font-size:15px;height:50px;width:75%;border:none;border-radius:20px;" @click="externalCurr.school=item.school; externalCurr.completion=item.completion; externalCurr.formation=item.formation;externalCurr.endYear=item.endYear; externalCurr.startYear=item.startYear; externalCurr.justifdocUrl;page++;">Edit </button>
</div>
<div class="remove">
<button style="background-color:rgb(105,05,105);font-size:15px;height:50px;width:75%;border:none;border-radius:20px;" @click="deleteExtCursus(item)">Remove </button>
</div>
</div>
</div> </div>
</div> </div>
</template> </template>
@ -196,9 +287,8 @@
margin-left: auto; margin-left: auto;
margin-right:auto; margin-right:auto;
min-width:400px; min-width:400px;
width:25%; width:25%;
height:60%; height:50%;
} }
@ -251,6 +341,14 @@
cursor: pointer; cursor: pointer;
} }
.bodu {
margin-top:2%;
width:50%;
border:2px solid black;
border-radius:9px;
background-color:rgb(50,50,50);
}
.switchpage{ .switchpage{
width:100px; width:100px;
border: none; border: none;
@ -290,11 +388,22 @@ input[type=file]{
background:#FFFFFF; background:#FFFFFF;
} }
.container{
margin-top: 2%;
color:white;
height:60px;
font-size:30px;
display:grid;
grid-template-columns:30% 30% 20% 20%;
grid-template-areas:
"school formation completion edit remove";
column-gap:10px;
}
button:active ,.switchpage:active{ button:active ,.switchpage:active{
opacity:0.8; opacity:0.8;
} }
</style> </style>

View File

@ -52,3 +52,15 @@ export async function getSelfCurriculum(){
export async function getSomeonesCurriculumList(user){ export async function getSomeonesCurriculumList(user){
return restGet("/onescurriculum/"+user) return restGet("/onescurriculum/"+user)
} }
export async function createExternalCurriculum(inscriptionRequestId,school, formation, completion, startYear, endYear, justifdocUrl){
return restPost("/externalcurriculum", {
inscriptionRequestId: inscriptionRequestId,
school:school,
formation :formation,
completion : completion,
startYear : startYear,
endYear: endYear,
justifdocUrl : justifdocUrl
})
}