Link the ExternalCurriculum to a user after the inscription.
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 1m31s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 24s

Add the ExternalCurriculum lists in AboutStudent.vue
This commit is contained in:
LeoMoulin 2024-04-12 09:28:56 +02:00
parent 8ebedec689
commit 98c9d2d754
8 changed files with 67 additions and 14 deletions

View File

@ -5,8 +5,10 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Repositories.Inscription.ExternalCurriculumRepository;
import ovh.herisson.Clyde.Repositories.Inscription.InscriptionRepository;
import ovh.herisson.Clyde.Repositories.UserRepository;
import ovh.herisson.Clyde.Tables.Inscription.ExternalCurriculum;
import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest;
import ovh.herisson.Clyde.Tables.User;
import java.util.ArrayList;
import java.util.Map;
@ -17,10 +19,12 @@ public class ExternalCurriculumController {
public final ExternalCurriculumRepository ecr;
public final InscriptionRepository inscriptionRepository;
public final UserRepository userRepository;
public ExternalCurriculumController(ExternalCurriculumRepository ecr, InscriptionRepository inscriptionRepository) {
public ExternalCurriculumController(ExternalCurriculumRepository ecr, InscriptionRepository inscriptionRepository, UserRepository userRepository) {
this.ecr = ecr;
this.inscriptionRepository = inscriptionRepository;
this.userRepository = userRepository;
}
//everyone can post some externalcurriculums (the validity of the elements is assured by the inscription service)
@ -28,7 +32,7 @@ public class ExternalCurriculumController {
public ResponseEntity<ExternalCurriculum> postExternalCurriculum(@RequestBody Map<String, Object> externalCurrInfos){
InscriptionRequest ir = inscriptionRepository.findById((Integer) externalCurrInfos.get("inscriptionRequestId"));
ExternalCurriculum toSave = new ExternalCurriculum(ir, (String) externalCurrInfos.get("school"),(String) externalCurrInfos.get("formation"),(String) externalCurrInfos.get("completion"), (Integer)externalCurrInfos.get("startYear"), (Integer)externalCurrInfos.get("endYear"), (String)externalCurrInfos.get("justifDocUrl"));
ExternalCurriculum toSave = new ExternalCurriculum(ir, (String) externalCurrInfos.get("school"),(String) externalCurrInfos.get("formation"),(String) externalCurrInfos.get("completion"), (Integer)externalCurrInfos.get("startYear"), (Integer)externalCurrInfos.get("endYear"), (String)externalCurrInfos.get("justifDocUrl"), null);
return new ResponseEntity<>(ecr.save(toSave), HttpStatus.OK);
}
@ -40,4 +44,12 @@ public class ExternalCurriculumController {
ArrayList<ExternalCurriculum> toReturn = ecr.getExternalCurriculumByInscriptionRequest(ir);
return new ResponseEntity<>(toReturn, HttpStatus.OK);
}
@GetMapping("/externalcurriculumbyuser/{userId}")
public ResponseEntity<ArrayList<ExternalCurriculum>> getExternalCurrByUser(@PathVariable long userId){
User user = userRepository.findById(userId);
ArrayList<ExternalCurriculum> toReturn = ecr.getExternalCurriculumByUser(user);
return new ResponseEntity<>(toReturn, HttpStatus.OK);
}
}

View File

@ -128,7 +128,7 @@ public class MockController {
inscriptionService.save(inscriptionRequest);
ExternalCurriculum externalCurriculum = new ExternalCurriculum(inscriptionRequest, "HEH", "Bachelier en informatique", "Completed", 2015, 2018, null);
ExternalCurriculum externalCurriculum = new ExternalCurriculum(inscriptionRequest, "HEH", "Bachelier en informatique", "Completed", 2015, 2018, null, null);
externalCurriculumRepository.save(externalCurriculum);
}
}

View File

@ -3,11 +3,13 @@ package ovh.herisson.Clyde.Repositories.Inscription;
import org.springframework.data.repository.CrudRepository;
import ovh.herisson.Clyde.Tables.Inscription.ExternalCurriculum;
import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest;
import ovh.herisson.Clyde.Tables.User;
import java.util.ArrayList;
public interface ExternalCurriculumRepository extends CrudRepository<ExternalCurriculum, Long> {
ArrayList<ExternalCurriculum> getExternalCurriculumByInscriptionRequest(InscriptionRequest ir);
ArrayList<ExternalCurriculum> getExternalCurriculumByUser(User user);
ExternalCurriculum getExternalCurriculumById(long id);
}

View File

@ -3,12 +3,16 @@ package ovh.herisson.Clyde.Services.Inscription;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Repositories.*;
import ovh.herisson.Clyde.Repositories.Inscription.ExternalCurriculumRepository;
import ovh.herisson.Clyde.Repositories.Inscription.InscriptionRepository;
import ovh.herisson.Clyde.Repositories.Inscription.MinervalRepository;
import ovh.herisson.Clyde.Tables.*;
import ovh.herisson.Clyde.Tables.Inscription.ExternalCurriculum;
import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest;
import ovh.herisson.Clyde.Tables.Inscription.Minerval;
import java.util.ArrayList;
@Service
public class InscriptionService {
@ -22,14 +26,15 @@ public class InscriptionService {
private final MinervalRepository minervalRepository;
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
private final ExternalCurriculumRepository externalCurriculumRepository;
public InscriptionService(InscriptionRepository inscriptionRepo, UserRepository userRepo, UserCurriculumRepository userCurriculumRepo, CurriculumRepository curriculumRepo, MinervalRepository minervalRepository){
public InscriptionService(InscriptionRepository inscriptionRepo, UserRepository userRepo, UserCurriculumRepository userCurriculumRepo, CurriculumRepository curriculumRepo, MinervalRepository minervalRepository, ExternalCurriculumRepository externalCurriculumRepository){
this.inscriptionRepo = inscriptionRepo;
this.userRepo = userRepo;
this.userCurriculumRepo = userCurriculumRepo;
this.curriculumRepo = curriculumRepo;
this.minervalRepository = minervalRepository;
this.externalCurriculumRepository = externalCurriculumRepository;
}
public InscriptionRequest save(InscriptionRequest inscriptionRequest){
@ -86,6 +91,12 @@ public class InscriptionService {
Minerval minerval = new Minerval(userFromRequest.getRegNo(), 0, 852, 2023);
minervalRepository.save(minerval);
//Assign the externals curriculums from the inscription request to newly created student
ArrayList<ExternalCurriculum> extCurrList = externalCurriculumRepository.getExternalCurriculumByInscriptionRequest(inscrRequest);
for (int i = 0; i < extCurrList.size(); i++){
extCurrList.get(i).setUser(userFromRequest);
externalCurriculumRepository.save(extCurrList.get(i));
}
return true;
}
public void delete(InscriptionRequest toDelete) {

View File

@ -2,6 +2,7 @@ package ovh.herisson.Clyde.Tables.Inscription;
import jakarta.persistence.*;
import ovh.herisson.Clyde.Tables.User;
//This table stores a student's curriculum from another university
@Entity
@ -10,10 +11,15 @@ public class ExternalCurriculum {
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
//An external curriculum is first linked to an inscription request and when it is accepted and the user is created we link it to the user
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="InscriptionRequest")
private InscriptionRequest inscriptionRequest;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="Users")
private User user;
private String school;
private String formation;
@ -27,7 +33,7 @@ public class ExternalCurriculum {
public ExternalCurriculum(){}
public ExternalCurriculum(InscriptionRequest ir, String school, String formation, String completion, int startYear, int endYear, String justifdocUrl){
public ExternalCurriculum(InscriptionRequest ir, String school, String formation, String completion, int startYear, int endYear, String justifdocUrl,User user){
this.inscriptionRequest = ir;
this.school = school;
this.formation = formation;
@ -35,6 +41,7 @@ public class ExternalCurriculum {
this.startYear = startYear;
this.endYear = endYear;
this.justifdocUrl = justifdocUrl;
this.user = user;
}
public int getId() {
@ -96,4 +103,12 @@ public class ExternalCurriculum {
public String getJustifdocUrl() {
return justifdocUrl;
}
public void setUser(User user) {
this.user = user;
}
public User getUser() {
return user;
}
}

View File

@ -2,10 +2,15 @@
import i18n from "@/i18n.js"
import {getUser} from '../../rest/Users.js'
import {getSomeonesCurriculumList} from "@/rest/curriculum.js";
import {ref} from "vue";
import ExternalCurriculumList from "@/Apps/Inscription/ExternalCurriculumList.vue";
import {getExternalCurriculumByUser} from "@/rest/externalCurriculum.js";
const props = defineProps(['target']);
let user = await getUser(props.target);
let UserCurriculum = await getSomeonesCurriculumList(props.target);
const props = defineProps(['target'])
const user = await getUser(props.target)
const UserCurriculum = await getSomeonesCurriculumList(props.target)
const externalcurrlist = await getExternalCurriculumByUser(user.regNo)
const extercurrlist = ref(false)
function getPP(){
if(user.profilePictureUrl === null){
@ -27,7 +32,7 @@
</script>
<template>
<div class="body">
<div class="body" v-if="extercurrlist==false">
<div class="container">
<div class="profilPic">
<img class="subContainter" :src=getPP()>
@ -49,6 +54,9 @@
<div>
Date de naissance : {{user.birthDate}}
</div>
<div>
<button @click="extercurrlist=!extercurrlist">See external curriculums</button>
</div>
</div>
</div>
<div class="moreInfos">
@ -79,7 +87,9 @@
</div>
</div>
</div>
<div v-if="extercurrlist==true">
<ExternalCurriculumList :ext-curr-list="externalcurrlist"></ExternalCurriculumList>
</div>
</template>

View File

@ -2,10 +2,10 @@
import i18n from "@/i18n.js";
import {ref} from "vue";
const props = defineProps(["extCurrList","inscrReqId"])
const props = defineProps(["extCurrList"])
const extCurrList = ref(props.extCurrList)
console.log(extCurrList)
</script>
<template style="margin-top:5%;">
@ -19,7 +19,6 @@
<div class="download"><button>Download document</button></div>
</div>
</div>
</div>
</template>

View File

@ -17,3 +17,7 @@ export async function getExternalCurriculumByInscrReq(inscrReqId){
return restGet("/externalcurriculum/"+inscrReqId)
}
export async function getExternalCurriculumByUser(userId){
return restGet("/externalcurriculumbyuser/"+userId)
}