Add the backend logic for ExternalCurriculum class (need to do one more endpoint)

This commit is contained in:
LeoMoulin 2024-03-29 15:31:02 +01:00
parent a3c9d6a7c0
commit 4a314449ad
6 changed files with 202 additions and 2 deletions

View File

@ -115,4 +115,20 @@ public class CurriculumController {
curriculumServ.delete(toDelete);
return new ResponseEntity<>(HttpStatus.OK);
}
@GetMapping("/externalcurriculum/{userId}")
public ResponseEntity<Map<String,Object>> getStudentsExternalCursus(@RequestHeader("Authorization") String token, @PathVariable String userId){
if (authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin, Role.Teacher},token))
return new UnauthorizedResponse<>(null);
User u = userServ.getUserById(Long.parseLong(userId));
HashMap<String,Object> toReturn = userCurriculumServ.findAllExternalCurriculumByStudent(u);
if (toReturn == null)
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
return new ResponseEntity<>(toReturn,HttpStatus.OK);
}
}

View File

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

View File

@ -2,8 +2,10 @@ package ovh.herisson.Clyde.Services;
import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Repositories.CurriculumRepository;
import ovh.herisson.Clyde.Repositories.ExternalCurriculumRepository;
import ovh.herisson.Clyde.Repositories.UserCurriculumRepository;
import ovh.herisson.Clyde.Tables.Curriculum;
import ovh.herisson.Clyde.Tables.ExternalCurriculum;
import ovh.herisson.Clyde.Tables.User;
import ovh.herisson.Clyde.Tables.UserCurriculum;
@ -16,9 +18,11 @@ public class UserCurriculumService {
private final UserCurriculumRepository userCurriculumRepository;
private final CurriculumRepository curriculumRepo;
public UserCurriculumService(UserCurriculumRepository userCurriculumRepository, CurriculumRepository curriculumRepo) {
private final ExternalCurriculumRepository externalCurriculumRepo;
public UserCurriculumService(UserCurriculumRepository userCurriculumRepository, CurriculumRepository curriculumRepo, ExternalCurriculumRepository externalCurriculumRepo) {
this.userCurriculumRepository = userCurriculumRepository;
this.curriculumRepo = curriculumRepo;
this.externalCurriculumRepo = externalCurriculumRepo;
}
public Curriculum findByUser(User student){
@ -47,4 +51,29 @@ public class UserCurriculumService {
return toReturn;
}
public HashMap<String,Object> findAllExternalCurriculumByStudent(User student) {
ArrayList<ExternalCurriculum> list = externalCurriculumRepo.getExternalCurriculumByUser(student);
ArrayList<HashMap<String, Object>> externalCurriculumList = new ArrayList<HashMap<String, Object>>();
for (int i = 0; i < list.size(); i++) {
HashMap<String, Object> element = new HashMap<>();
element.put("id", list.get(0).getId());
element.put("user", list.get(0).getUser());
element.put("university", list.get(0).getUniversity());
element.put("formation", list.get(0).getFormation());
element.put("completion", list.get(0).getCompletion());
element.put("startYear", list.get(0).getStartYear());
element.put("endYear", list.get(0).getEndYear());
element.put("justifDocUrl", list.get(0).getJustifdocUrl());
element.put("state", list.get(0).getState());
externalCurriculumList.add(element);
}
HashMap<String, Object> toReturn = new HashMap<String, Object>();
toReturn.put("externalCurriculumList", externalCurriculumList);
return toReturn;
}
}

View File

@ -0,0 +1,113 @@
package ovh.herisson.Clyde.Tables;
import jakarta.persistence.*;
//This table stores a student's curriculum from another university
@Entity
public class ExternalCurriculum {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@ManyToOne
@JoinColumn(name="Users")
private User user;
@ManyToOne
@JoinColumn(name="University")
private University university;
private String formation;
//This string denotes the completion of the external formation or the last year completed by the student in this formation
private String completion;
private int startYear;
private int endYear;
private String justifdocUrl;
//Accepted if the document justifies the claimed formation
private RequestState state;
public ExternalCurriculum(){}
public ExternalCurriculum(User user, University university, String formation, String completion, int startYear, int endYear, String justifdocUrl, RequestState state){
this.user = user;
this.university = university;
this.formation = formation;
this.completion = completion;
this.startYear = startYear;
this.endYear = endYear;
this.justifdocUrl = justifdocUrl;
this.state = state;
}
public int getId() {
return id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public University getUniversity() {
return university;
}
public void setUniversity(University university) {
this.university = university;
}
public String getFormation() {
return formation;
}
public void setFormation(String formation) {
this.formation = formation;
}
public String getCompletion(){
return completion;
}
public void setCompletion(String completion) {
this.completion = completion;
}
public int getStartYear() {
return startYear;
}
public void setStartYear(int startYear) {
this.startYear = startYear;
}
public int getEndYear() {
return endYear;
}
public void setEndYear(int endYear) {
this.endYear = endYear;
}
public void setJustifdocUrl(String justifdocUrl) {
this.justifdocUrl = justifdocUrl;
}
public String getJustifdocUrl() {
return justifdocUrl;
}
public RequestState getState() {
return state;
}
public void setState(RequestState state) {
this.state = state;
}
}

View File

@ -0,0 +1,27 @@
package ovh.herisson.Clyde.Tables;
import jakarta.persistence.*;
@Entity
public class University {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
public University(){}
public University(String name){
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -27,7 +27,6 @@
//Allows to display MA or BAB for years
let yearprefix = "";
const imageSaved = ref(false)
let ppData = "";
@ -154,6 +153,11 @@
<option v-for="item in curricula">{{getCursusDisplay(item)}}</option>
</select>
</div>
<p style="color:rgb(239,60,168);">
Si vous êtes déja inscrits dans cette université veuillez vous connecter a votre compte et utilisez les fonctions
changer de cursus/réinscription sinon continuez ici.
</p>
<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, outputs.curriculum, ppData, null, new Date());">
{{i18n("login.guest.nextpage")}}