From 98c9d2d754d7c10b5088dad38424fe4210992414 Mon Sep 17 00:00:00 2001 From: LeoMoulin Date: Fri, 12 Apr 2024 09:28:56 +0200 Subject: [PATCH] Link the ExternalCurriculum to a user after the inscription. Add the ExternalCurriculum lists in AboutStudent.vue --- .../ExternalCurriculumController.java | 16 +++++++++++++-- .../Clyde/EndPoints/MockController.java | 2 +- .../ExternalCurriculumRepository.java | 2 ++ .../Inscription/InscriptionService.java | 15 ++++++++++++-- .../Inscription/ExternalCurriculum.java | 17 +++++++++++++++- .../src/Apps/Inscription/AboutStudent.vue | 20 ++++++++++++++----- .../Inscription/ExternalCurriculumList.vue | 5 ++--- frontend/src/rest/externalCurriculum.js | 4 ++++ 8 files changed, 67 insertions(+), 14 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/ExternalCurriculumController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/ExternalCurriculumController.java index 1067071..e88c759 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/ExternalCurriculumController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/ExternalCurriculumController.java @@ -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 postExternalCurriculum(@RequestBody Map 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 toReturn = ecr.getExternalCurriculumByInscriptionRequest(ir); return new ResponseEntity<>(toReturn, HttpStatus.OK); } + + @GetMapping("/externalcurriculumbyuser/{userId}") + public ResponseEntity> getExternalCurrByUser(@PathVariable long userId){ + User user = userRepository.findById(userId); + + ArrayList toReturn = ecr.getExternalCurriculumByUser(user); + return new ResponseEntity<>(toReturn, HttpStatus.OK); + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java index 1e207e0..14fd259 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -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); } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ExternalCurriculumRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ExternalCurriculumRepository.java index 41ef507..7b4ee4e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ExternalCurriculumRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ExternalCurriculumRepository.java @@ -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 { ArrayList getExternalCurriculumByInscriptionRequest(InscriptionRequest ir); + ArrayList getExternalCurriculumByUser(User user); ExternalCurriculum getExternalCurriculumById(long id); } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java index e897c7a..c80e2d9 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java @@ -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 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) { diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/ExternalCurriculum.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/ExternalCurriculum.java index 09d59bb..893971b 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/ExternalCurriculum.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/ExternalCurriculum.java @@ -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; + } } diff --git a/frontend/src/Apps/Inscription/AboutStudent.vue b/frontend/src/Apps/Inscription/AboutStudent.vue index 640ea1b..03368c2 100644 --- a/frontend/src/Apps/Inscription/AboutStudent.vue +++ b/frontend/src/Apps/Inscription/AboutStudent.vue @@ -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 @@ diff --git a/frontend/src/Apps/Inscription/ExternalCurriculumList.vue b/frontend/src/Apps/Inscription/ExternalCurriculumList.vue index d23cf24..a642840 100644 --- a/frontend/src/Apps/Inscription/ExternalCurriculumList.vue +++ b/frontend/src/Apps/Inscription/ExternalCurriculumList.vue @@ -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) diff --git a/frontend/src/rest/externalCurriculum.js b/frontend/src/rest/externalCurriculum.js index 8274cff..f1b403d 100644 --- a/frontend/src/rest/externalCurriculum.js +++ b/frontend/src/rest/externalCurriculum.js @@ -17,3 +17,7 @@ export async function getExternalCurriculumByInscrReq(inscrReqId){ return restGet("/externalcurriculum/"+inscrReqId) } +export async function getExternalCurriculumByUser(userId){ + return restGet("/externalcurriculumbyuser/"+userId) +} +