Merge branch 'master' into Max/Backend/TeacherAdding
This commit is contained in:
commit
60ddad2dfc
@ -0,0 +1,62 @@
|
|||||||
|
package ovh.herisson.Clyde.EndPoints;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||||
|
import ovh.herisson.Clyde.Tables.Applications;
|
||||||
|
import ovh.herisson.Clyde.Tables.Role;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class ApplicationsController {
|
||||||
|
|
||||||
|
AuthenticatorService authServ;
|
||||||
|
|
||||||
|
public ApplicationsController(AuthenticatorService authServ){
|
||||||
|
this.authServ = authServ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** return a list of authorized applications.
|
||||||
|
* depends on the token
|
||||||
|
*/
|
||||||
|
@GetMapping("/apps")
|
||||||
|
public ResponseEntity<Iterable<Applications>> getAuthorizedApps(@RequestHeader("Authorization") String token){
|
||||||
|
|
||||||
|
return new ResponseEntity<>(getAuthorizedApplications(token), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/apps/{identifier}")
|
||||||
|
public ResponseEntity<Boolean> getAppAuthorization(@PathVariable Applications identifier, @RequestHeader("Authorization") String token){
|
||||||
|
|
||||||
|
if (getAuthorizedApplications(token).contains(identifier)){
|
||||||
|
return new ResponseEntity<>(true, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
return new ResponseEntity<>(false, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Applications> getAuthorizedApplications(String token){
|
||||||
|
Role posterRole = authServ.getUserFromToken(token).getRole();
|
||||||
|
ArrayList<Applications> authorizedApps = new ArrayList<>();
|
||||||
|
|
||||||
|
authorizedApps.add(Applications.Login);
|
||||||
|
authorizedApps.add(Applications.Profile);
|
||||||
|
|
||||||
|
if (posterRole == Role.Teacher || posterRole == Role.Student || posterRole == Role.Admin){
|
||||||
|
authorizedApps.add(Applications.Msg);
|
||||||
|
authorizedApps.add(Applications.Forum);
|
||||||
|
authorizedApps.add(Applications.Rdv);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (posterRole == Role.Teacher || posterRole == Role.Secretary || posterRole == Role.Admin) authorizedApps.add(Applications.ManageCourses);
|
||||||
|
|
||||||
|
if (posterRole == Role.InscriptionService || posterRole == Role.Admin) authorizedApps.add(Applications.Inscription);
|
||||||
|
|
||||||
|
return authorizedApps;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package ovh.herisson.Clyde.EndPoints;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||||
|
import ovh.herisson.Clyde.Services.CurriculumCourseService;
|
||||||
|
import ovh.herisson.Clyde.Services.CurriculumService;
|
||||||
|
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||||
|
import ovh.herisson.Clyde.Tables.CurriculumCourse;
|
||||||
|
import ovh.herisson.Clyde.Tables.Role;
|
||||||
|
import ovh.herisson.Clyde.Tables.User;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class CurriculumController {
|
||||||
|
|
||||||
|
|
||||||
|
private final CurriculumService curriculumServ;
|
||||||
|
private final AuthenticatorService authServ;
|
||||||
|
|
||||||
|
private final CurriculumCourseService curriculumCourseServ;
|
||||||
|
|
||||||
|
public CurriculumController(CurriculumService curriculumServ, AuthenticatorService authServ, CurriculumCourseService curriculumCourseServ){
|
||||||
|
this.curriculumServ = curriculumServ;
|
||||||
|
this.authServ = authServ;
|
||||||
|
this.curriculumCourseServ = curriculumCourseServ;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/curriculum/{id}")
|
||||||
|
public ResponseEntity<Curriculum> findById(@PathVariable long id){
|
||||||
|
return new ResponseEntity<>(curriculumServ.findById(id), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/curriculums")
|
||||||
|
public ResponseEntity<Iterable<Map<String, Object>>> findAllindDepth(){
|
||||||
|
return new ResponseEntity<>(curriculumCourseServ.getAllDepthCurriculum(),HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/curriculum")
|
||||||
|
public ResponseEntity<Iterable<CurriculumCourse>> findAll(){
|
||||||
|
return new ResponseEntity<>(curriculumCourseServ.findAll(),HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
@ -1,71 +0,0 @@
|
|||||||
package ovh.herisson.Clyde.EndPoints;
|
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
|
||||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
|
||||||
import ovh.herisson.Clyde.Services.CursusCourseService;
|
|
||||||
import ovh.herisson.Clyde.Services.CursusService;
|
|
||||||
import ovh.herisson.Clyde.Tables.Cursus;
|
|
||||||
import ovh.herisson.Clyde.Tables.CursusCourse;
|
|
||||||
import ovh.herisson.Clyde.Tables.Role;
|
|
||||||
import ovh.herisson.Clyde.Tables.User;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class CursusController {
|
|
||||||
|
|
||||||
|
|
||||||
private final CursusService cursusServ;
|
|
||||||
private final AuthenticatorService authServ;
|
|
||||||
|
|
||||||
private final CursusCourseService cursusCourseServ;
|
|
||||||
|
|
||||||
public CursusController(CursusService cursusServ, AuthenticatorService authServ, CursusCourseService cursusCourseServ){
|
|
||||||
this.cursusServ = cursusServ;
|
|
||||||
this.authServ = authServ;
|
|
||||||
this.cursusCourseServ = cursusCourseServ;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/cursus/{id}")
|
|
||||||
public ResponseEntity<Cursus> findById(@PathVariable long id){
|
|
||||||
return new ResponseEntity<>(cursusServ.findById(id), HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/curriculums")
|
|
||||||
public ResponseEntity<Iterable<Map<String, Object>>> findAllindDepth(){
|
|
||||||
return new ResponseEntity<>(cursusCourseServ.getAllDepthCursus(),HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/curriculum")
|
|
||||||
public ResponseEntity<Iterable<CursusCourse>> findAll(){
|
|
||||||
return new ResponseEntity<>(cursusCourseServ.findAll(),HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**@PostMapping("/cursus")
|
|
||||||
public ResponseEntity<String> postCursus(@RequestHeader("Authorization") String token,@RequestBody Cursus cursus){
|
|
||||||
|
|
||||||
if (!isSecretaryOrAdmin(token)){
|
|
||||||
return new UnauthorizedResponse<>("you're not allowed to post a cursus");
|
|
||||||
}
|
|
||||||
|
|
||||||
cursusServ.save(cursus);
|
|
||||||
|
|
||||||
return new ResponseEntity<>("created !",HttpStatus.CREATED);
|
|
||||||
}**/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private boolean isSecretaryOrAdmin(String authorization){
|
|
||||||
if (authorization ==null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
User poster = authServ.getUserFromToken(authorization);
|
|
||||||
if (poster == null) return false;
|
|
||||||
|
|
||||||
return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin;
|
|
||||||
}
|
|
||||||
}
|
|
@ -32,7 +32,7 @@ public class InscriptionController {
|
|||||||
@GetMapping("/requests/register")
|
@GetMapping("/requests/register")
|
||||||
public ResponseEntity<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){
|
public ResponseEntity<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){
|
||||||
|
|
||||||
if (!isSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);}
|
if (authServ.isNotSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);}
|
||||||
|
|
||||||
Iterable<InscriptionRequest> inscriptionRequests = inscriptionServ.getAll();
|
Iterable<InscriptionRequest> inscriptionRequests = inscriptionServ.getAll();
|
||||||
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
||||||
@ -64,7 +64,7 @@ public class InscriptionController {
|
|||||||
@RequestHeader("Authorize") String token,
|
@RequestHeader("Authorize") String token,
|
||||||
@RequestBody RequestState requestState)
|
@RequestBody RequestState requestState)
|
||||||
{
|
{
|
||||||
if (!isSecretaryOrAdmin(token)) return new UnauthorizedResponse<>(null);
|
if (authServ.isNotSecretaryOrAdmin(token)) return new UnauthorizedResponse<>(null);
|
||||||
inscriptionServ.modifyState(id, requestState);
|
inscriptionServ.modifyState(id, requestState);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -78,20 +78,9 @@ public class InscriptionController {
|
|||||||
toReturn.put("address", inscriptionRequest.getAddress());
|
toReturn.put("address", inscriptionRequest.getAddress());
|
||||||
toReturn.put("birthDate", inscriptionRequest.getBirthDate());
|
toReturn.put("birthDate", inscriptionRequest.getBirthDate());
|
||||||
toReturn.put("country", inscriptionRequest.getCountry());
|
toReturn.put("country", inscriptionRequest.getCountry());
|
||||||
toReturn.put("cursus", inscriptionRequest.getCursus());
|
toReturn.put("curriculum", inscriptionRequest.getCurriculum());
|
||||||
toReturn.put("profilePictureUrl", inscriptionRequest.getProfilePicture());
|
toReturn.put("profilePictureUrl", inscriptionRequest.getProfilePicture());
|
||||||
toReturn.put("state", inscriptionRequest.getState());
|
toReturn.put("state", inscriptionRequest.getState());
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean isSecretaryOrAdmin(String authorization){
|
|
||||||
if (authorization ==null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
User poster = authServ.getUserFromToken(authorization);
|
|
||||||
if (poster == null) return false;
|
|
||||||
|
|
||||||
return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -20,18 +20,18 @@ public class MockController {
|
|||||||
public final UserRepository userRepo;
|
public final UserRepository userRepo;
|
||||||
public final TokenRepository tokenRepo;
|
public final TokenRepository tokenRepo;
|
||||||
public final TokenService tokenService;
|
public final TokenService tokenService;
|
||||||
public final CursusCourseService cursusCourseService;
|
public final CurriculumCourseService CurriculumCourseService;
|
||||||
public final CursusService cursusService;
|
public final CurriculumService curriculumService;
|
||||||
public final CourseService courseService;
|
public final CourseService courseService;
|
||||||
ArrayList<User> mockUsers;
|
ArrayList<User> mockUsers;
|
||||||
|
|
||||||
|
|
||||||
public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CursusCourseService cursusCourseService, CursusService cursusService, CourseService courseService){
|
public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService){
|
||||||
this.tokenRepo = tokenRepo;
|
this.tokenRepo = tokenRepo;
|
||||||
this.userRepo = userRepo;
|
this.userRepo = userRepo;
|
||||||
this.tokenService = tokenService;
|
this.tokenService = tokenService;
|
||||||
this.cursusCourseService = cursusCourseService;
|
this.CurriculumCourseService = CurriculumCourseService;
|
||||||
this.cursusService = cursusService;
|
this.curriculumService = curriculumService;
|
||||||
this.courseService = courseService;
|
this.courseService = courseService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,20 +51,21 @@ public class MockController {
|
|||||||
User joe = new User("Mama","Joe","student@student.com","roundabout","DaWarudo",new Date(0), null,Role.Student,passwordEncoder.encode("student"));
|
User joe = new User("Mama","Joe","student@student.com","roundabout","DaWarudo",new Date(0), null,Role.Student,passwordEncoder.encode("student"));
|
||||||
User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), null,Role.Secretary,passwordEncoder.encode("secretary"));
|
User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), null,Role.Secretary,passwordEncoder.encode("secretary"));
|
||||||
User joke = new User("CthemBalls","Lemme","teacher@teacher.com","lab","faculty",new Date(0), null,Role.Teacher,passwordEncoder.encode("teacher"));
|
User joke = new User("CthemBalls","Lemme","teacher@teacher.com","lab","faculty",new Date(0), null,Role.Teacher,passwordEncoder.encode("teacher"));
|
||||||
mockUsers = new ArrayList<User>(Arrays.asList(herobrine,joe,meh,joke));
|
User lena = new User("Louille","Lena","inscriptionService@InscriptionService.com","no","yes",new Date(0), null,Role.Teacher,passwordEncoder.encode("inscriptionService"));
|
||||||
|
mockUsers = new ArrayList<>(Arrays.asList(herobrine,joe,meh,joke));
|
||||||
|
|
||||||
userRepo.saveAll(mockUsers);
|
userRepo.saveAll(mockUsers);
|
||||||
|
|
||||||
|
|
||||||
// Course / Curriculum part
|
// Course / Curriculum part
|
||||||
|
|
||||||
Cursus infoBab1 = new Cursus(1,"info");
|
Curriculum infoBab1 = new Curriculum(1,"info");
|
||||||
Cursus chemistryBab1 = new Cursus(1,"chemistry");
|
Curriculum chemistryBab1 = new Curriculum(1,"chemistry");
|
||||||
Cursus psychologyBab1 = new Cursus(1,"psychology");
|
Curriculum psychologyBab1 = new Curriculum(1,"psychology");
|
||||||
|
|
||||||
cursusService.save(infoBab1);
|
curriculumService.save(infoBab1);
|
||||||
cursusService.save(chemistryBab1);
|
curriculumService.save(chemistryBab1);
|
||||||
cursusService.save(psychologyBab1);
|
curriculumService.save(psychologyBab1);
|
||||||
|
|
||||||
|
|
||||||
Course progra1 = new Course(5,"Programmation et algorithimque 1","TODO DELETE");
|
Course progra1 = new Course(5,"Programmation et algorithimque 1","TODO DELETE");
|
||||||
@ -78,15 +79,15 @@ public class MockController {
|
|||||||
courseService.save(commun);
|
courseService.save(commun);
|
||||||
|
|
||||||
|
|
||||||
cursusCourseService.save(new CursusCourse(infoBab1,progra1));
|
CurriculumCourseService.save(new CurriculumCourse(infoBab1,progra1));
|
||||||
cursusCourseService.save(new CursusCourse(infoBab1,commun));
|
CurriculumCourseService.save(new CurriculumCourse(infoBab1,commun));
|
||||||
|
|
||||||
cursusCourseService.save(new CursusCourse(psychologyBab1,psycho1));
|
CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,psycho1));
|
||||||
cursusCourseService.save(new CursusCourse(psychologyBab1,commun));
|
CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,commun));
|
||||||
|
|
||||||
|
|
||||||
cursusCourseService.save(new CursusCourse(chemistryBab1,commun));
|
CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,commun));
|
||||||
cursusCourseService.save(new CursusCourse(chemistryBab1,chemistry1));
|
CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,chemistry1));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class UserController {
|
|||||||
@PostMapping("/user")
|
@PostMapping("/user")
|
||||||
public ResponseEntity<String> postUser(@RequestBody User user,@RequestHeader("Authorization") String authorization){
|
public ResponseEntity<String> postUser(@RequestBody User user,@RequestHeader("Authorization") String authorization){
|
||||||
|
|
||||||
if (!isSecretaryOrAdmin(authorization))
|
if (authServ.isNotSecretaryOrAdmin(authorization))
|
||||||
return new UnauthorizedResponse<>(null);
|
return new UnauthorizedResponse<>(null);
|
||||||
|
|
||||||
userService.save(user);
|
userService.save(user);
|
||||||
@ -50,7 +50,7 @@ public class UserController {
|
|||||||
@GetMapping("/users")
|
@GetMapping("/users")
|
||||||
public ResponseEntity<Iterable<HashMap<String,Object>>> getAllUsers(@RequestHeader("Authorization") String authorization){
|
public ResponseEntity<Iterable<HashMap<String,Object>>> getAllUsers(@RequestHeader("Authorization") String authorization){
|
||||||
|
|
||||||
if (!isSecretaryOrAdmin(authorization))
|
if (authServ.isNotSecretaryOrAdmin(authorization))
|
||||||
return new UnauthorizedResponse<>(null);
|
return new UnauthorizedResponse<>(null);
|
||||||
|
|
||||||
Iterable<User> users = userService.getAll();
|
Iterable<User> users = userService.getAll();
|
||||||
@ -97,7 +97,6 @@ public class UserController {
|
|||||||
*/
|
*/
|
||||||
private HashMap<String,Object> userWithoutPassword(User user){
|
private HashMap<String,Object> userWithoutPassword(User user){
|
||||||
HashMap<String,Object> toReturn = new HashMap<>();
|
HashMap<String,Object> toReturn = new HashMap<>();
|
||||||
|
|
||||||
toReturn.put("regNo",user.getRegNo());
|
toReturn.put("regNo",user.getRegNo());
|
||||||
toReturn.put("firstName",user.getFirstName());
|
toReturn.put("firstName",user.getFirstName());
|
||||||
toReturn.put("lastName",user.getLastName());
|
toReturn.put("lastName",user.getLastName());
|
||||||
@ -105,20 +104,7 @@ public class UserController {
|
|||||||
toReturn.put("country",user.getCountry());
|
toReturn.put("country",user.getCountry());
|
||||||
toReturn.put("address",user.getAddress());
|
toReturn.put("address",user.getAddress());
|
||||||
toReturn.put("role",user.getRole());
|
toReturn.put("role",user.getRole());
|
||||||
|
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSecretaryOrAdmin(String authorization){
|
|
||||||
System.out.println(authorization);
|
|
||||||
if (authorization ==null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
User poster = authServ.getUserFromToken(authorization);
|
|
||||||
if (poster == null) return false;
|
|
||||||
System.out.println(poster.getRole());
|
|
||||||
|
|
||||||
return poster.getRole() == Role.Secretary || poster.getRole() == Role.Admin;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
package ovh.herisson.Clyde.Repositories;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import ovh.herisson.Clyde.Tables.Course;
|
||||||
|
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||||
|
import ovh.herisson.Clyde.Tables.CurriculumCourse;
|
||||||
|
|
||||||
|
public interface CurriculumCourseRepository extends CrudRepository<CurriculumCourse,Long> {
|
||||||
|
|
||||||
|
@Query("select distinct cc.course from CurriculumCourse cc where cc.curriculum = ?1")
|
||||||
|
Iterable<Course> findCoursesByCurriculum(Curriculum curriculum);
|
||||||
|
|
||||||
|
|
||||||
|
@Query("select distinct cc.curriculum from CurriculumCourse cc")
|
||||||
|
Iterable<Curriculum> findDistinctCurriculums();
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package ovh.herisson.Clyde.Repositories;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||||
|
|
||||||
|
public interface CurriculumRepository extends CrudRepository<Curriculum,Long> {
|
||||||
|
Curriculum findById(long id);
|
||||||
|
}
|
@ -1,20 +0,0 @@
|
|||||||
package ovh.herisson.Clyde.Repositories;
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
|
||||||
import ovh.herisson.Clyde.Tables.Course;
|
|
||||||
import ovh.herisson.Clyde.Tables.Cursus;
|
|
||||||
import ovh.herisson.Clyde.Tables.CursusCourse;
|
|
||||||
|
|
||||||
public interface CursusCourseRepository extends CrudRepository<CursusCourse,Long> {
|
|
||||||
|
|
||||||
|
|
||||||
//todo faire custom query pour trouver tous les cours d'un cursus par un cursusId
|
|
||||||
|
|
||||||
@Query("select distinct cc.course from CursusCourse cc where cc.cursus = ?1")
|
|
||||||
Iterable<Course> findCoursesByCursus(Cursus cursus);
|
|
||||||
|
|
||||||
|
|
||||||
@Query("select distinct cc.cursus from CursusCourse cc")
|
|
||||||
Iterable<Cursus> findDistinctCursuses();
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package ovh.herisson.Clyde.Repositories;
|
|
||||||
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
|
||||||
import ovh.herisson.Clyde.Tables.Cursus;
|
|
||||||
|
|
||||||
public interface CursusRepository extends CrudRepository<Cursus,Long> {
|
|
||||||
Cursus findById(long id);
|
|
||||||
}
|
|
@ -1,9 +1,8 @@
|
|||||||
package ovh.herisson.Clyde.Services;
|
package ovh.herisson.Clyde.Services;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ovh.herisson.Clyde.EndPoints.LoginController;
|
|
||||||
import ovh.herisson.Clyde.Repositories.InscriptionRepository;
|
|
||||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
||||||
|
import ovh.herisson.Clyde.Tables.Role;
|
||||||
import ovh.herisson.Clyde.Tables.Token;
|
import ovh.herisson.Clyde.Tables.Token;
|
||||||
import ovh.herisson.Clyde.Tables.User;
|
import ovh.herisson.Clyde.Tables.User;
|
||||||
|
|
||||||
@ -39,4 +38,17 @@ public class AuthenticatorService {
|
|||||||
public void register(InscriptionRequest inscriptionRequest) {
|
public void register(InscriptionRequest inscriptionRequest) {
|
||||||
inscriptionService.save(inscriptionRequest);
|
inscriptionService.save(inscriptionRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isNotSecretaryOrAdmin(String authorization){
|
||||||
|
if (authorization ==null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
User poster = getUserFromToken(authorization);
|
||||||
|
if (poster == null) return true;
|
||||||
|
|
||||||
|
return poster.getRole() != Role.Secretary || poster.getRole() != Role.Admin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
package ovh.herisson.Clyde.Services;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
||||||
|
import ovh.herisson.Clyde.Repositories.CurriculumCourseRepository;
|
||||||
|
import ovh.herisson.Clyde.Repositories.CurriculumRepository;
|
||||||
|
import ovh.herisson.Clyde.Tables.Course;
|
||||||
|
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||||
|
import ovh.herisson.Clyde.Tables.CurriculumCourse;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CurriculumCourseService {
|
||||||
|
|
||||||
|
private final CurriculumCourseRepository curriculumCourseRepo;
|
||||||
|
|
||||||
|
private final CourseRepository courseRepo;
|
||||||
|
|
||||||
|
private final CurriculumRepository curriculumRepo;
|
||||||
|
|
||||||
|
public CurriculumCourseService(CurriculumCourseRepository curriculumCourseRepository, CourseRepository courseRepo, CurriculumRepository curriculumRepo) {
|
||||||
|
this.curriculumCourseRepo = curriculumCourseRepository;
|
||||||
|
this.courseRepo = courseRepo;
|
||||||
|
this.curriculumRepo = curriculumRepo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(CurriculumCourse curriculumCourse){
|
||||||
|
curriculumCourseRepo.save(curriculumCourse);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<CurriculumCourse> findAll(){
|
||||||
|
return curriculumCourseRepo.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Map<String, Object> getDepthCurriculum(Curriculum curriculum){
|
||||||
|
|
||||||
|
HashMap<String ,Object> toReturn = new HashMap<>();
|
||||||
|
ArrayList<Course> courses = new ArrayList<>();
|
||||||
|
for (Course c: curriculumCourseRepo.findCoursesByCurriculum(curriculum)){
|
||||||
|
courses.add(c);
|
||||||
|
}
|
||||||
|
toReturn.put("courses",courses);
|
||||||
|
toReturn.put("curriculumId", curriculum.getCurriculumId());
|
||||||
|
toReturn.put("year", curriculum.getYear());
|
||||||
|
toReturn.put("option", curriculum.getOption());
|
||||||
|
|
||||||
|
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<Map<String, Object>> getAllDepthCurriculum(){
|
||||||
|
|
||||||
|
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Curriculum curriculum : curriculumCourseRepo.findDistinctCurriculums()){
|
||||||
|
toReturn.add(getDepthCurriculum(curriculum));
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package ovh.herisson.Clyde.Services;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
||||||
|
import ovh.herisson.Clyde.Repositories.CurriculumRepository;
|
||||||
|
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CurriculumService {
|
||||||
|
|
||||||
|
private final CurriculumRepository curriculumRepo;
|
||||||
|
|
||||||
|
private final CourseRepository courseRepo;
|
||||||
|
|
||||||
|
public CurriculumService(CurriculumRepository curriculumRepo, CourseRepository courseRepo){
|
||||||
|
this.curriculumRepo = curriculumRepo;
|
||||||
|
this.courseRepo = courseRepo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void save(Curriculum curriculum){
|
||||||
|
curriculumRepo.save(curriculum);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Curriculum findById(long id){
|
||||||
|
return curriculumRepo.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<Curriculum> findAll(){
|
||||||
|
return curriculumRepo.findAll();
|
||||||
|
}
|
||||||
|
}
|
@ -1,68 +0,0 @@
|
|||||||
package ovh.herisson.Clyde.Services;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
|
||||||
import ovh.herisson.Clyde.Repositories.CursusCourseRepository;
|
|
||||||
import ovh.herisson.Clyde.Repositories.CursusRepository;
|
|
||||||
import ovh.herisson.Clyde.Tables.Course;
|
|
||||||
import ovh.herisson.Clyde.Tables.Cursus;
|
|
||||||
import ovh.herisson.Clyde.Tables.CursusCourse;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class CursusCourseService {
|
|
||||||
|
|
||||||
private final CursusCourseRepository cursusCourseRepo;
|
|
||||||
|
|
||||||
private final CourseRepository courseRepo;
|
|
||||||
|
|
||||||
private final CursusRepository cursusRepo;
|
|
||||||
|
|
||||||
public CursusCourseService(CursusCourseRepository cursusCourseRepo, CourseRepository courseRepo, CursusRepository cursusRepo) {
|
|
||||||
this.cursusCourseRepo = cursusCourseRepo;
|
|
||||||
this.courseRepo = courseRepo;
|
|
||||||
this.cursusRepo = cursusRepo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(CursusCourse cursusCourse){
|
|
||||||
cursusCourseRepo.save(cursusCourse);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterable<CursusCourse> findAll(){
|
|
||||||
return cursusCourseRepo.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Map<String, Object> getDepthCursus(Cursus cursus){
|
|
||||||
|
|
||||||
HashMap<String ,Object> toReturn = new HashMap<>();
|
|
||||||
ArrayList<Course> courses = new ArrayList<>();
|
|
||||||
for (Course c: cursusCourseRepo.findCoursesByCursus(cursus)){
|
|
||||||
courses.add(c);
|
|
||||||
}
|
|
||||||
toReturn.put("courses",courses);
|
|
||||||
toReturn.put("cursusId",cursus.getCursusId());
|
|
||||||
toReturn.put("year",cursus.getYear());
|
|
||||||
toReturn.put("option",cursus.getOption());
|
|
||||||
|
|
||||||
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterable<Map<String, Object>> getAllDepthCursus(){
|
|
||||||
|
|
||||||
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Cursus cursus : cursusCourseRepo.findDistinctCursuses()){
|
|
||||||
toReturn.add(getDepthCursus(cursus));
|
|
||||||
}
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
package ovh.herisson.Clyde.Services;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
|
||||||
import ovh.herisson.Clyde.Repositories.CursusRepository;
|
|
||||||
import ovh.herisson.Clyde.Tables.Cursus;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class CursusService {
|
|
||||||
|
|
||||||
|
|
||||||
private final CursusRepository cursusRepo;
|
|
||||||
|
|
||||||
private final CourseRepository courseRepo;
|
|
||||||
|
|
||||||
public CursusService(CursusRepository cursusRepo, CourseRepository courseRepo){
|
|
||||||
this.cursusRepo = cursusRepo;
|
|
||||||
this.courseRepo = courseRepo;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void save(Cursus cursus){
|
|
||||||
cursusRepo.save(cursus);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cursus findById(long id){
|
|
||||||
return cursusRepo.findById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterable<Cursus> findAll(){
|
|
||||||
return cursusRepo.findAll();
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,10 +4,8 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import ovh.herisson.Clyde.Repositories.FileRepository;
|
import ovh.herisson.Clyde.Repositories.FileRepository;
|
||||||
import ovh.herisson.Clyde.Tables.*;
|
import ovh.herisson.Clyde.Tables.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
@ -5,16 +5,15 @@ import org.springframework.stereotype.Service;
|
|||||||
import ovh.herisson.Clyde.Repositories.TokenRepository;
|
import ovh.herisson.Clyde.Repositories.TokenRepository;
|
||||||
import ovh.herisson.Clyde.Tables.Token;
|
import ovh.herisson.Clyde.Tables.Token;
|
||||||
import ovh.herisson.Clyde.Tables.User;
|
import ovh.herisson.Clyde.Tables.User;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class TokenService {
|
public class TokenService {
|
||||||
TokenRepository tokenRepo;
|
private final TokenRepository tokenRepo;
|
||||||
|
|
||||||
public TokenService(TokenRepository tokenRepo){
|
public TokenService(TokenRepository tokenRepo){
|
||||||
this.tokenRepo = tokenRepo;
|
this.tokenRepo = tokenRepo;
|
||||||
@ -30,13 +29,10 @@ public class TokenService {
|
|||||||
new SecureRandom().nextBytes(bytes);
|
new SecureRandom().nextBytes(bytes);
|
||||||
for (int i = 0; i < bytes.length; i++) {
|
for (int i = 0; i < bytes.length; i++) {
|
||||||
bytes[i] = (byte) (((bytes[i]+256)%256 %95+ 32));
|
bytes[i] = (byte) (((bytes[i]+256)%256 %95+ 32));
|
||||||
while ((char)bytes[i] == ';'){
|
|
||||||
bytes[i] = new SecureRandom().generateSeed(1)[0];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// will never end up in the catch because of the way that SecureRandom.nextBytes is implemented
|
// will never end up in the catch because of the way that SecureRandom.nextBytes is implemented
|
||||||
try {
|
try {
|
||||||
return new String(bytes,"ISO_8859_1");
|
return new String(Base64.getEncoder().encode(bytes),"ISO_8859_1");
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package ovh.herisson.Clyde.Tables;
|
||||||
|
|
||||||
|
public enum Applications {
|
||||||
|
// without any token
|
||||||
|
Login,
|
||||||
|
|
||||||
|
// with any token
|
||||||
|
Profile,
|
||||||
|
|
||||||
|
|
||||||
|
// Students and higher authorization
|
||||||
|
Msg,
|
||||||
|
Forum,
|
||||||
|
Rdv,
|
||||||
|
|
||||||
|
// teachers and Secretary authorization
|
||||||
|
ManageCourses,
|
||||||
|
|
||||||
|
// InscriptionService authorization
|
||||||
|
Inscription
|
||||||
|
}
|
@ -6,21 +6,21 @@ import jakarta.persistence.GenerationType;
|
|||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Cursus {
|
public class Curriculum {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private int cursusId;
|
private int curriculumId;
|
||||||
private int year;
|
private int year;
|
||||||
private String option;
|
private String option;
|
||||||
public Cursus(int year, String option){
|
public Curriculum(int year, String option){
|
||||||
this.year = year;
|
this.year = year;
|
||||||
this.option = option;
|
this.option = option;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursus() {}
|
public Curriculum() {}
|
||||||
|
|
||||||
public int getCursusId(){
|
public int getCurriculumId(){
|
||||||
return this.cursusId;
|
return this.curriculumId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getYear(){
|
public int getYear(){
|
@ -3,25 +3,25 @@ package ovh.herisson.Clyde.Tables;
|
|||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class CursusCourse {
|
public class CurriculumCourse {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "Cursus")
|
@JoinColumn(name = "Curriculum")
|
||||||
private Cursus cursus;
|
private Curriculum curriculum;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "Course")
|
@JoinColumn(name = "Course")
|
||||||
private Course course;
|
private Course course;
|
||||||
|
|
||||||
public CursusCourse(Cursus cursus, Course course){
|
public CurriculumCourse(Curriculum curriculum, Course course){
|
||||||
this.cursus = cursus;
|
this.curriculum = curriculum;
|
||||||
this.course = course;
|
this.course = course;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CursusCourse() {}
|
public CurriculumCourse() {}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
@ -35,11 +35,11 @@ public class CursusCourse {
|
|||||||
this.course = course;
|
this.course = course;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursus getCursus() {
|
public Curriculum getCurriculum() {
|
||||||
return cursus;
|
return curriculum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCursus(Cursus cursus) {
|
public void setCurriculum(Curriculum curriculum) {
|
||||||
this.cursus = cursus;
|
this.curriculum = curriculum;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,8 +18,8 @@ public class InscriptionRequest {
|
|||||||
private Date birthDate;
|
private Date birthDate;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name="Cursus")
|
@JoinColumn(name="Curriculum")
|
||||||
private Cursus cursus;
|
private Curriculum curriculum;
|
||||||
private RequestState state;
|
private RequestState state;
|
||||||
private String profilePicture;
|
private String profilePicture;
|
||||||
|
|
||||||
@ -89,12 +89,12 @@ public class InscriptionRequest {
|
|||||||
this.birthDate = birthDate;
|
this.birthDate = birthDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursus getCursus() {
|
public Curriculum getCurriculum() {
|
||||||
return cursus;
|
return curriculum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCursus(Cursus cursus) {
|
public void setCurriculum(Curriculum curriculum) {
|
||||||
this.cursus = cursus;
|
this.curriculum = curriculum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestState getState() {
|
public RequestState getState() {
|
||||||
|
@ -13,26 +13,26 @@ public class ReinscriptionRequest {
|
|||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "Cursus")
|
@JoinColumn(name = "Curriculum")
|
||||||
private Cursus newCursus;
|
private Curriculum newCurriculum;
|
||||||
private RequestState state;
|
private RequestState state;
|
||||||
|
|
||||||
//Permet de différencier les demandes de changement et une réinscription dans le même cursus
|
//Permet de différencier les demandes de changement et une réinscription dans le même Curriculum
|
||||||
//Pour la réinscription on va le mettre a 0
|
//Pour la réinscription on va le mettre a 0
|
||||||
private boolean type = false;
|
private boolean type = false;
|
||||||
|
|
||||||
public ReinscriptionRequest(){}
|
public ReinscriptionRequest(){}
|
||||||
|
|
||||||
public ReinscriptionRequest(User user, Cursus newCursus, RequestState state, boolean type){
|
public ReinscriptionRequest(User user, Curriculum newCurriculum, RequestState state, boolean type){
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.newCursus = newCursus;
|
this.newCurriculum = newCurriculum;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReinscriptionRequest(User user, Cursus newCursus, RequestState state){
|
public ReinscriptionRequest(User user, Curriculum newCurriculum, RequestState state){
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.newCursus = newCursus;
|
this.newCurriculum = newCurriculum;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,12 +48,12 @@ public class ReinscriptionRequest {
|
|||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursus getNewCursus() {
|
public Curriculum getNewCurriculum() {
|
||||||
return newCursus;
|
return newCurriculum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNewCursus(Cursus newCursus) {
|
public void setNewCurriculum(Curriculum newCurriculum) {
|
||||||
this.newCursus = newCursus;
|
this.newCurriculum = newCurriculum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestState getState() {
|
public RequestState getState() {
|
||||||
|
@ -3,5 +3,5 @@ package ovh.herisson.Clyde.Tables;
|
|||||||
public enum RequestState {
|
public enum RequestState {
|
||||||
Accepted,
|
Accepted,
|
||||||
Refused,
|
Refused,
|
||||||
Pending;
|
Pending
|
||||||
}
|
}
|
||||||
|
@ -5,5 +5,5 @@ public enum Role {
|
|||||||
Student,
|
Student,
|
||||||
Admin,
|
Admin,
|
||||||
InscriptionService,
|
InscriptionService,
|
||||||
Secretary;
|
Secretary
|
||||||
}
|
}
|
@ -3,26 +3,26 @@ package ovh.herisson.Clyde.Tables;
|
|||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class UserCursus {
|
public class UserCurriculum {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
//Un étudiant peut avoir plusieurs cursus
|
//Un étudiant peut avoir plusieurs curriculums
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "Users")
|
@JoinColumn(name = "Users")
|
||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
@OneToOne(fetch = FetchType.EAGER)
|
@OneToOne(fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "Cursus")
|
@JoinColumn(name = "Curriculum")
|
||||||
private Cursus cursus;
|
private Curriculum curriculum;
|
||||||
|
|
||||||
public UserCursus(User user, Cursus cursus){
|
public UserCurriculum(User user, Curriculum curriculum){
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.cursus = cursus;
|
this.curriculum = curriculum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserCursus() {}
|
public UserCurriculum() {}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
@ -36,11 +36,11 @@ public class UserCursus {
|
|||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursus getCursus() {
|
public Curriculum getCurriculum() {
|
||||||
return cursus;
|
return curriculum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCursus(Cursus cursus) {
|
public void setCurriculum(Curriculum curriculum) {
|
||||||
this.cursus = cursus;
|
this.curriculum = curriculum;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,6 +2,7 @@
|
|||||||
import { toast } from 'vue3-toastify';
|
import { toast } from 'vue3-toastify';
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import i18n, { setLang } from './i18n.js'
|
import i18n, { setLang } from './i18n.js'
|
||||||
|
import { isLogged } from '@/rest/Users.js'
|
||||||
|
|
||||||
|
|
||||||
// Liste des apps
|
// Liste des apps
|
||||||
@ -19,6 +20,7 @@
|
|||||||
const currentPath = ref(window.location.hash)
|
const currentPath = ref(window.location.hash)
|
||||||
|
|
||||||
window.addEventListener('hashchange', () => {
|
window.addEventListener('hashchange', () => {
|
||||||
|
Logged.value = isLogged();
|
||||||
currentPath.value = window.location.hash
|
currentPath.value = window.location.hash
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -32,6 +34,8 @@
|
|||||||
const login=ref(i18n("app.login"))
|
const login=ref(i18n("app.login"))
|
||||||
const active=ref(false)
|
const active=ref(false)
|
||||||
|
|
||||||
|
const Logged = ref(isLogged());
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -49,7 +53,7 @@
|
|||||||
</a></li>
|
</a></li>
|
||||||
<li style="float: right;" title=login>
|
<li style="float: right;" title=login>
|
||||||
<a class="icon" href="#/login">
|
<a class="icon" href="#/login">
|
||||||
<div class="fa-solid fa-user" style="margin-top: 7px; margin-bottom: 3px;"></div>
|
<div class="fa-solid fa-user" :style="Logged ? 'color: orange' : 'haha'" style="margin-top: 7px; margin-bottom: 3px; "></div>
|
||||||
</a></li>
|
</a></li>
|
||||||
<li style="float: right;" title=notifications>
|
<li style="float: right;" title=notifications>
|
||||||
<a class="icon" href="#Notifications">
|
<a class="icon" href="#Notifications">
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import i18n from '@/i18n.js'
|
import i18n from '@/i18n.js'
|
||||||
import { login , register } from '@/rest/Users.js'
|
import { login , register, disconnect } from '@/rest/Users.js'
|
||||||
import { uploadProfilePicture } from '@/rest/uploads.js'
|
import { uploadProfilePicture } from '@/rest/uploads.js'
|
||||||
|
|
||||||
const loginPage= ref(true)
|
const loginPage= ref(true)
|
||||||
@ -16,10 +16,13 @@
|
|||||||
const email=ref("")
|
const email=ref("")
|
||||||
const address=ref("")
|
const address=ref("")
|
||||||
const country=ref("")
|
const country=ref("")
|
||||||
const cursus=ref("")
|
const curriculum=ref("")
|
||||||
|
|
||||||
const imageSaved = ref(false)
|
const imageSaved = ref(false)
|
||||||
const ppData = ref(false)
|
const ppData = ref(false)
|
||||||
|
|
||||||
|
disconnect()
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
@ -49,7 +52,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<form @submit.prevent="register(firstname, surname, birthday, password, mail, address, country, cursus)" class="form">
|
<form @submit.prevent="register(firstname, surname, birthday, password, mail, address, country, curriculum)" class="form">
|
||||||
<h1 style="color:rgb(239,60,168); font-family: sans-serif; text-align:center;">
|
<h1 style="color:rgb(239,60,168); font-family: sans-serif; text-align:center;">
|
||||||
{{i18n("login.guest.welcome")}}
|
{{i18n("login.guest.welcome")}}
|
||||||
</h1>
|
</h1>
|
||||||
@ -103,7 +106,7 @@
|
|||||||
</form>
|
</form>
|
||||||
<div class="inputBox">
|
<div class="inputBox">
|
||||||
<p>{{i18n("curriculum").toUpperCase()}}</p>
|
<p>{{i18n("curriculum").toUpperCase()}}</p>
|
||||||
<select v-model="cursus">
|
<select v-model="curriculum">
|
||||||
<option value="Chemistry">Chemistry</option>
|
<option value="Chemistry">Chemistry</option>
|
||||||
<option value="Psycho">Psychology</option>
|
<option value="Psycho">Psychology</option>
|
||||||
<option value="IT">IT</option>
|
<option value="IT">IT</option>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import i18n from "@/i18n.js"
|
import i18n from "@/i18n.js"
|
||||||
import {ref} from 'vue'
|
import {ref} from 'vue'
|
||||||
const cursus=[
|
const curriculum=[
|
||||||
{
|
{
|
||||||
"id": 12,
|
"id": 12,
|
||||||
"name": "Math pour l'info",
|
"name": "Math pour l'info",
|
||||||
@ -51,8 +51,8 @@ const cursus=[
|
|||||||
let toAdd = Object.assign({}, pattern);
|
let toAdd = Object.assign({}, pattern);
|
||||||
|
|
||||||
function addToCourse (){
|
function addToCourse (){
|
||||||
if (cursus.length>0){
|
if (curriculum.length>0){
|
||||||
toAdd.id=(cursus[cursus.length-1].id)-1;}
|
toAdd.id=(curriculum[curriculum.length-1].id)-1;}
|
||||||
else{
|
else{
|
||||||
toAdd.id=0;
|
toAdd.id=0;
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ const cursus=[
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isnull){
|
if (!isnull){
|
||||||
cursus.push(toAdd);
|
curriculum.push(toAdd);
|
||||||
}
|
}
|
||||||
toAdd= Object.assign({},pattern);
|
toAdd= Object.assign({},pattern);
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ const cursus=[
|
|||||||
console.log("ok");
|
console.log("ok");
|
||||||
console.log(toRemove);
|
console.log(toRemove);
|
||||||
let rem=-1;
|
let rem=-1;
|
||||||
for(const [key, value] of Object.entries(cursus)){
|
for(const [key, value] of Object.entries(curriculum)){
|
||||||
console.log(key);
|
console.log(key);
|
||||||
console.log(value)
|
console.log(value)
|
||||||
if(value.name === toRemove){
|
if(value.name === toRemove){
|
||||||
@ -86,8 +86,8 @@ const cursus=[
|
|||||||
}
|
}
|
||||||
console.log(rem)
|
console.log(rem)
|
||||||
if (rem > -1){
|
if (rem > -1){
|
||||||
cursus.splice(rem, 1);}
|
curriculum.splice(rem, 1);}
|
||||||
console.log(cursus);
|
console.log(curriculum);
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@ -130,7 +130,7 @@ const cursus=[
|
|||||||
<div style="margin-bottom:20px;">
|
<div style="margin-bottom:20px;">
|
||||||
{{i18n("courses.toDelete")}} :
|
{{i18n("courses.toDelete")}} :
|
||||||
<select style="max-width:200px;" class="teacher" v-model="toRemove">
|
<select style="max-width:200px;" class="teacher" v-model="toRemove">
|
||||||
<option v-for="item in cursus">{{item.name}}</option>
|
<option v-for="item in curriculum">{{item.name}}</option>
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@ -147,7 +147,7 @@ const cursus=[
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="!createMod && !deleteMod" v-for="item in cursus" :key="item.name">
|
<div v-if="!createMod && !deleteMod" v-for="item in curriculum" :key="item.name">
|
||||||
<div style ="padding:15px 15px 15px 15px;">
|
<div style ="padding:15px 15px 15px 15px;">
|
||||||
<button v-if="editElementID !== item.name" @click="editElementID = item.name">
|
<button v-if="editElementID !== item.name" @click="editElementID = item.name">
|
||||||
{{i18n("courses.modify")}}
|
{{i18n("courses.modify")}}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
role:"student",
|
role:"student",
|
||||||
address: "Radiator Springs",
|
address: "Radiator Springs",
|
||||||
email:"ClydeGhost@gmail.com",
|
email:"ClydeGhost@gmail.com",
|
||||||
cursus:[
|
curriculum:[
|
||||||
{
|
{
|
||||||
"id": 12,
|
"id": 12,
|
||||||
"name": "Math pour l'info",
|
"name": "Math pour l'info",
|
||||||
@ -132,7 +132,7 @@ const toModify = Object.assign({}, user);
|
|||||||
{{i18n("profile.course.list")}}
|
{{i18n("profile.course.list")}}
|
||||||
</div>
|
</div>
|
||||||
<div class="listElement "
|
<div class="listElement "
|
||||||
v-for="item in user.cursus">
|
v-for="item in user.curriculum">
|
||||||
<div class=" containerElement">
|
<div class=" containerElement">
|
||||||
<div class="name"> {{item.name}} </div>
|
<div class="name"> {{item.name}} </div>
|
||||||
<div class="teacher">{{item.teacher}}</div>
|
<div class="teacher">{{item.teacher}}</div>
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
address: String,
|
address: String,
|
||||||
country: String,
|
country: String,
|
||||||
birthDate: String,
|
birthDate: String,
|
||||||
cursus:String,
|
curriculum:String,
|
||||||
degree:String,});
|
degree:String,});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ export async function createRegister(){
|
|||||||
* - country
|
* - country
|
||||||
* - birthdate
|
* - birthdate
|
||||||
* - email
|
* - email
|
||||||
* - cursus
|
* - curriculum
|
||||||
* - degree
|
* - degree
|
||||||
*/
|
*/
|
||||||
export async function getRegisters(id){
|
export async function getRegisters(id){
|
||||||
|
@ -1,9 +1,18 @@
|
|||||||
import { restGet, restPost } from './restConsumer.js'
|
import { restGet, restPost } from './restConsumer.js'
|
||||||
|
import { getCookie, setCookie } from '@/utils.js'
|
||||||
|
|
||||||
export async function login(user, pass, exp){
|
export async function login(user, pass, exp){
|
||||||
return restPost("/login", {identifier: user, password: pass, expirationDate: exp});
|
return restPost("/login", {identifier: user, password: pass, expirationDate: exp});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isLogged(){
|
||||||
|
return getCookie("session_token") != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
export function disconnect(){
|
||||||
|
setCookie("session_token", ";expires= Thu, 01 Jan 1970 00:00:01 GMT")
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a user (tokenless)
|
* Register a user (tokenless)
|
||||||
*
|
*
|
||||||
@ -14,10 +23,10 @@ export async function login(user, pass, exp){
|
|||||||
* @param mail
|
* @param mail
|
||||||
* @param address
|
* @param address
|
||||||
* @param country
|
* @param country
|
||||||
* @param cursus
|
* @param curriculum
|
||||||
* @param imageId id of the image in database returned when uploaded
|
* @param imageId id of the image in database returned when uploaded
|
||||||
*/
|
*/
|
||||||
export async function register(firstname, lastname, birthDate, password, email, address, country, cursus, imageId){
|
export async function register(firstname, lastname, birthDate, password, email, address, country, curriculum, imageId){
|
||||||
return restPost("/register", {
|
return restPost("/register", {
|
||||||
firstname: firstname,
|
firstname: firstname,
|
||||||
lastname: lastname,
|
lastname: lastname,
|
||||||
@ -26,7 +35,7 @@ export async function register(firstname, lastname, birthDate, password, email,
|
|||||||
email: email,
|
email: email,
|
||||||
address: address,
|
address: address,
|
||||||
country: country,
|
country: country,
|
||||||
cursus: cursus
|
curriculum: curriculum
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
frontend/src/rest/apps.js
Normal file
9
frontend/src/rest/apps.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { restGet } from './restConsumer.js'
|
||||||
|
|
||||||
|
export async function appList(){
|
||||||
|
return restGet("/apps")
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function checkPage(page){
|
||||||
|
return restGet("/apps/" + page)
|
||||||
|
}
|
41
frontend/src/rest/curriculum.js
Normal file
41
frontend/src/rest/curriculum.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/**
|
||||||
|
* curriculum API
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { restGet, restPostn, restDelete, restPatch } from './restConsumer.js'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new curriculum (bundle of courses)
|
||||||
|
* @param courses list of courses
|
||||||
|
*/
|
||||||
|
export async function createcurriculum(courses){
|
||||||
|
return restPost("/curriculum", {courses: courses} );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the specified curriculum
|
||||||
|
*/
|
||||||
|
export async function deletecurriculum(id){
|
||||||
|
return restDelete("/curriculum/" + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get informations on a particular curriculum
|
||||||
|
*
|
||||||
|
* @param id identification of the curriculum
|
||||||
|
*
|
||||||
|
* @return list of courses
|
||||||
|
*/
|
||||||
|
export async function getcurriculum(id){
|
||||||
|
return restGet("/curriculum/" + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modify the courses of a curriculum
|
||||||
|
*
|
||||||
|
* @param id the id of the curriculum
|
||||||
|
* @param courses list of new courses
|
||||||
|
*/
|
||||||
|
export async function altercurriculum(id, courses){
|
||||||
|
return restPatch("/curriculum/" + id, courses);
|
||||||
|
}
|
@ -1,41 +0,0 @@
|
|||||||
/**
|
|
||||||
* cursus API
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { restGet, restPostn, restDelete, restPatch } from './restConsumer.js'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new cursus (bundle of courses)
|
|
||||||
* @param courses list of courses
|
|
||||||
*/
|
|
||||||
export async function createCursus(courses){
|
|
||||||
return restPost("/cursus", {courses: courses} );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete the specified cursus
|
|
||||||
*/
|
|
||||||
export async function deleteCursus(id){
|
|
||||||
return restDelete("/cursus/" + id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get informations on a particular cursus
|
|
||||||
*
|
|
||||||
* @param id identification of the cursus
|
|
||||||
*
|
|
||||||
* @return list of courses
|
|
||||||
*/
|
|
||||||
export async function getCursus(id){
|
|
||||||
return restGet("/cursus/" + id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modify the courses of a cursus
|
|
||||||
*
|
|
||||||
* @param id the id of the cursus
|
|
||||||
* @param courses list of new courses
|
|
||||||
*/
|
|
||||||
export async function alterCursus(id, courses){
|
|
||||||
return restPatch("/cursus/" + id, courses);
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user