Merge branch 'master' into tonitch/feat/notifications
This commit is contained in:
		@ -70,6 +70,9 @@ public class ApplicationsController {
 | 
			
		||||
 | 
			
		||||
        if (!authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)){ 
 | 
			
		||||
          authorizedApps.add(Applications.UsersList);}
 | 
			
		||||
 | 
			
		||||
        if (!authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin, Role.InscriptionService},token)){
 | 
			
		||||
            authorizedApps.add(Applications.Payments);}
 | 
			
		||||
        return authorizedApps;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -3,15 +3,17 @@ 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.Repositories.CurriculumCourseRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
 | 
			
		||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
 | 
			
		||||
import ovh.herisson.Clyde.Services.CourseService;
 | 
			
		||||
import ovh.herisson.Clyde.Services.ProtectionService;
 | 
			
		||||
import ovh.herisson.Clyde.Services.TeacherCourseService;
 | 
			
		||||
import ovh.herisson.Clyde.Services.*;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Course;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Role;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.UserCurriculum;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@ -24,10 +26,20 @@ public class CourseController {
 | 
			
		||||
 | 
			
		||||
    private final AuthenticatorService authServ;
 | 
			
		||||
 | 
			
		||||
    public CourseController(CourseService courseServ, TeacherCourseService teacherCourseServ, AuthenticatorService authServ) {
 | 
			
		||||
    private final UserService userService;
 | 
			
		||||
 | 
			
		||||
    private final UserCurriculumService userCurriculumService;
 | 
			
		||||
 | 
			
		||||
    private final CurriculumCourseRepository curriculumCourseRepository;
 | 
			
		||||
    private final CurriculumCourseService curriculumCourseService;
 | 
			
		||||
    public CourseController(CourseService courseServ, TeacherCourseService teacherCourseServ, AuthenticatorService authServ, UserService userService, UserCurriculumService userCurriculumService, CurriculumCourseRepository curriculumCourseRepository, CurriculumCourseService curriculumCourseService) {
 | 
			
		||||
        this.courseServ = courseServ;
 | 
			
		||||
        this.teacherCourseServ = teacherCourseServ;
 | 
			
		||||
        this.authServ = authServ;
 | 
			
		||||
        this.userService = userService;
 | 
			
		||||
        this.userCurriculumService = userCurriculumService;
 | 
			
		||||
        this.curriculumCourseRepository = curriculumCourseRepository;
 | 
			
		||||
        this.curriculumCourseService = curriculumCourseService;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/course/{id}")
 | 
			
		||||
@ -136,4 +148,28 @@ public class CourseController {
 | 
			
		||||
        return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    //Get all the courses followed by an user
 | 
			
		||||
    @GetMapping("/usercourses")
 | 
			
		||||
    public ResponseEntity<List<Course>> getAllUserCourses(@RequestHeader("Authorization") String token){
 | 
			
		||||
        User u = authServ.getUserFromToken(token);
 | 
			
		||||
 | 
			
		||||
        //We get all the actual curriculums of the user
 | 
			
		||||
        List<UserCurriculum> userCurricula = userCurriculumService.findByStudentAndActual(u, true);
 | 
			
		||||
        List<Course> toReturn = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
        //We iterate through all the curriculums and we extract the courses
 | 
			
		||||
        for (int i = 0; i < userCurricula.size(); i++){
 | 
			
		||||
            curriculumCourseRepository.findCoursesByCurriculum(userCurricula.get(i).getCurriculum()).forEach((item) -> {
 | 
			
		||||
                //We need this to eliminate clones because a course can belong to several curriculums
 | 
			
		||||
                if(!toReturn.contains(item)){
 | 
			
		||||
                    toReturn.add(item);
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new ResponseEntity<>(toReturn, HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -30,9 +30,16 @@ public class ExternalCurriculumController {
 | 
			
		||||
    //everyone can post some externalcurriculums (the validity of the elements is assured by the inscription service)
 | 
			
		||||
    @PostMapping("/externalcurriculum")
 | 
			
		||||
    public ResponseEntity<ExternalCurriculum> postExternalCurriculum(@RequestBody Map<String, Object> externalCurrInfos){
 | 
			
		||||
        InscriptionRequest ir = inscriptionRepository.findById((Integer) externalCurrInfos.get("inscriptionRequestId"));
 | 
			
		||||
        //An external curriculum can either be linked to an User or to an InscriptionRequest
 | 
			
		||||
        InscriptionRequest ir = null;
 | 
			
		||||
        User user = null;
 | 
			
		||||
        if (externalCurrInfos.get("inscriptionRequestId") != null){
 | 
			
		||||
            ir = inscriptionRepository.findById((Integer) externalCurrInfos.get("inscriptionRequestId"));
 | 
			
		||||
        }else{
 | 
			
		||||
            user = userRepository.findById((Integer) externalCurrInfos.get("userRegNo"));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        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);
 | 
			
		||||
        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"), user);
 | 
			
		||||
 | 
			
		||||
        return new ResponseEntity<>(ecr.save(toSave), HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -29,7 +29,7 @@ public class InscriptionController {
 | 
			
		||||
    @GetMapping("/requests/register")
 | 
			
		||||
    public ResponseEntity<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){
 | 
			
		||||
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token))
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService, Role.Teacher},token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        Iterable<InscriptionRequest> inscriptionRequests = inscriptionServ.getAll();
 | 
			
		||||
@ -41,7 +41,7 @@ public class InscriptionController {
 | 
			
		||||
    @GetMapping("/request/register/{id}")
 | 
			
		||||
    public ResponseEntity<Map<String,Object>> getById(@RequestHeader("Authorization") String token, @PathVariable long id){
 | 
			
		||||
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token))
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService, Role.Teacher},token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        InscriptionRequest foundInscriptionRequest = inscriptionServ.getById(id);
 | 
			
		||||
@ -87,6 +87,12 @@ public class InscriptionController {
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        InscriptionRequest toEdit = inscriptionServ.getById(id);
 | 
			
		||||
 | 
			
		||||
        //If the request is already accepted we just return ok (otherwise we would duplicate the procedure below)
 | 
			
		||||
        if (toEdit.getEquivalenceState() == RequestState.Accepted){
 | 
			
		||||
            return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        toEdit.setEquivalenceState(newstate);
 | 
			
		||||
 | 
			
		||||
        inscriptionServ.save(toEdit);
 | 
			
		||||
 | 
			
		||||
@ -34,4 +34,12 @@ public class PaymentController {
 | 
			
		||||
        return new ResponseEntity<>(toReturn, HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/payment")
 | 
			
		||||
    public ResponseEntity<ArrayList<Payment>> getAllPayments(){
 | 
			
		||||
        ArrayList<Payment> toReturn = new ArrayList<Payment>();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        paymentRepository.findAll().forEach(toReturn::add);
 | 
			
		||||
        return new ResponseEntity<>(toReturn, HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -4,18 +4,24 @@ import org.springframework.http.HttpStatus;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.CurriculumRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.Inscription.ChangeCurriculumRequestRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.Inscription.ExemptionsRequestRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.Inscription.ScholarshipRequestRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.Inscription.UninscriptionRequestRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.Inscription.UnregisterRequestRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.UserCurriculumRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.UserRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
 | 
			
		||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
 | 
			
		||||
import ovh.herisson.Clyde.Services.TokenService;
 | 
			
		||||
import ovh.herisson.Clyde.Services.UserService;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.*;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Inscription.ExemptionsRequest;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Inscription.ScholarshipRequest;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Inscription.UninscriptionRequest;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Inscription.UnregisterRequest;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Calendar;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
@ -23,20 +29,31 @@ import java.util.Map;
 | 
			
		||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
 | 
			
		||||
public class RequestsController {
 | 
			
		||||
 | 
			
		||||
    public final TokenService tokenService;
 | 
			
		||||
    public final ExemptionsRequestRepository err;
 | 
			
		||||
    public final ScholarshipRequestRepository srr;
 | 
			
		||||
    public final UserRepository userRepository;
 | 
			
		||||
    public final AuthenticatorService authServ;
 | 
			
		||||
    public final UninscriptionRequestRepository uninscriptionRequestRepository;
 | 
			
		||||
    public final UnregisterRequestRepository unregisterRequestRepository;
 | 
			
		||||
    public final CourseRepository courseRepository;
 | 
			
		||||
    public final UserService userService;
 | 
			
		||||
    public final UserCurriculumRepository userCurriculumRepository;
 | 
			
		||||
    public final CurriculumRepository curriculumRepository;
 | 
			
		||||
 | 
			
		||||
    public RequestsController(ExemptionsRequestRepository err, ScholarshipRequestRepository srr, UserRepository userRepository, AuthenticatorService authServ, UninscriptionRequestRepository uninscriptionRequestRepository, CourseRepository courseRepository) {
 | 
			
		||||
    public final ChangeCurriculumRequestRepository changeCurriculumRequestRepository;
 | 
			
		||||
 | 
			
		||||
    public RequestsController(TokenService tokenService, ExemptionsRequestRepository err, ScholarshipRequestRepository srr, UserRepository userRepository, AuthenticatorService authServ, UnregisterRequestRepository unregisterRequestRepository, CourseRepository courseRepository, UserService userService, UserCurriculumRepository userCurriculumRepository, CurriculumRepository curriculumRepository, ChangeCurriculumRequestRepository changeCurriculumRequestRepository) {
 | 
			
		||||
        this.tokenService = tokenService;
 | 
			
		||||
        this.err = err;
 | 
			
		||||
        this.srr = srr;
 | 
			
		||||
        this.userRepository = userRepository;
 | 
			
		||||
        this.authServ = authServ;
 | 
			
		||||
        this.uninscriptionRequestRepository = uninscriptionRequestRepository;
 | 
			
		||||
        this.unregisterRequestRepository = unregisterRequestRepository;
 | 
			
		||||
        this.courseRepository = courseRepository;
 | 
			
		||||
        this.userService = userService;
 | 
			
		||||
        this.userCurriculumRepository = userCurriculumRepository;
 | 
			
		||||
        this.curriculumRepository = curriculumRepository;
 | 
			
		||||
        this.changeCurriculumRequestRepository = changeCurriculumRequestRepository;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping(value="/exemptionreq")
 | 
			
		||||
@ -64,7 +81,7 @@ public class RequestsController {
 | 
			
		||||
    //Get all the exemptions Request
 | 
			
		||||
    @GetMapping(value = "/exemptionsreq")
 | 
			
		||||
    public ResponseEntity<ArrayList<ExemptionsRequest>> getAllExemptionsRequests(@RequestHeader("Authorization") String token){
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token))
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService, Role.Teacher},token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        ArrayList<ExemptionsRequest> toReturn = new ArrayList<>();
 | 
			
		||||
@ -74,6 +91,33 @@ public class RequestsController {
 | 
			
		||||
        return new ResponseEntity<>(toReturn, HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping(value = "/exemptionsreq/{id}")
 | 
			
		||||
    public ResponseEntity<ExemptionsRequest> getExemptionRequestbyId(@RequestHeader("Authorization") String token, @PathVariable long id){
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher,Role.InscriptionService},token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        ExemptionsRequest exemptionsRequest = err.findById(id);
 | 
			
		||||
 | 
			
		||||
        return new ResponseEntity<>(exemptionsRequest, HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PatchMapping(value = "/exemptionsreq/{id}/{newstate}")
 | 
			
		||||
    public ResponseEntity<String> changeExemptionReqState(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newstate){
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        ExemptionsRequest exemptionsRequest = err.findById(id);
 | 
			
		||||
 | 
			
		||||
        if (exemptionsRequest.getState() == RequestState.Accepted){
 | 
			
		||||
            return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        exemptionsRequest.setState(newstate);
 | 
			
		||||
        err.save(exemptionsRequest);
 | 
			
		||||
 | 
			
		||||
        return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Get all the scholarships requests
 | 
			
		||||
    @GetMapping(value = "/scholarshipreq")
 | 
			
		||||
    public ResponseEntity<ArrayList<ScholarshipRequest>> getAllScholarshipRequests(@RequestHeader("Authorization") String token){
 | 
			
		||||
@ -87,11 +131,236 @@ public class RequestsController {
 | 
			
		||||
        return new ResponseEntity<>(toReturn, HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping(value = "/uninscriptionreq")
 | 
			
		||||
    @PostMapping(value = "/unregister")
 | 
			
		||||
    public ResponseEntity<String> postUnregReq(@RequestBody Map<String,Object> uninscr){
 | 
			
		||||
        User u = userRepository.findById((int) uninscr.get("userId"));
 | 
			
		||||
        UninscriptionRequest ur = new UninscriptionRequest(RequestState.Pending, (String) uninscr.get("reason"), new Date(), u);
 | 
			
		||||
        uninscriptionRequestRepository.save(ur);
 | 
			
		||||
        Curriculum c;
 | 
			
		||||
 | 
			
		||||
        if (uninscr.get("curriculumId") == null){
 | 
			
		||||
            c = null;
 | 
			
		||||
        }else{
 | 
			
		||||
            c = curriculumRepository.findById((Integer) uninscr.get("curriculumId"));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        UnregisterRequest ur = new UnregisterRequest(RequestState.Pending, (String) uninscr.get("reason"), new Date(), u.getRegNo(), u.getFirstName(), u.getLastName(), u.getEmail(), c);
 | 
			
		||||
        unregisterRequestRepository.save(ur);
 | 
			
		||||
        return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PatchMapping(value = "/scholarshipreq/")
 | 
			
		||||
    public ResponseEntity<String> editScholReq(@RequestHeader("Authorization") String token, @RequestBody Map<String,Object> infos){
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        ScholarshipRequest scholarshipRequest = srr.findById((Integer) infos.get("id"));
 | 
			
		||||
 | 
			
		||||
        //If the request is already accepted we just return ok (otherwise we would duplicate the procedure below)
 | 
			
		||||
        if (scholarshipRequest.getState() == RequestState.Accepted){
 | 
			
		||||
            return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (infos.get("state").equals("Accepted")){
 | 
			
		||||
            scholarshipRequest.setState(RequestState.Accepted);
 | 
			
		||||
            scholarshipRequest.setAmount((int) infos.get("amount"));
 | 
			
		||||
        }else{
 | 
			
		||||
            scholarshipRequest.setState(RequestState.Refused);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        srr.save(scholarshipRequest);
 | 
			
		||||
        return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping(value = "/scholarshipreq/{id}")
 | 
			
		||||
    public ResponseEntity<ScholarshipRequest> getScholReqbyId(@RequestHeader("Authorization") String token, @PathVariable long id){
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin, Role.InscriptionService},token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        ScholarshipRequest toReturn = srr.findById(id);
 | 
			
		||||
        return new ResponseEntity<>(toReturn, HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping(value = "/unregister")
 | 
			
		||||
    public ResponseEntity<ArrayList<UnregisterRequest>> getAllUnregReq(@RequestHeader("Authorization") String token){
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        ArrayList<UnregisterRequest> toReturn = new ArrayList<>();
 | 
			
		||||
        unregisterRequestRepository.findAll().forEach(toReturn::add);
 | 
			
		||||
        return new ResponseEntity<>(toReturn, HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping(value = "/unregister/{id}")
 | 
			
		||||
    public ResponseEntity<UnregisterRequest> getUnregbyId(@RequestHeader("Authorization") String token, @PathVariable long id){
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        UnregisterRequest unregisterRequest = unregisterRequestRepository.findById(id);
 | 
			
		||||
        return new ResponseEntity<>(unregisterRequest, HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PatchMapping(value = "/unregister/{id}/{newstate}")
 | 
			
		||||
    public ResponseEntity<String> pathUnregReq(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newstate){
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        UnregisterRequest unregisterRequest = unregisterRequestRepository.findById(id);
 | 
			
		||||
        User u = userRepository.findById(unregisterRequest.getRegNo());
 | 
			
		||||
 | 
			
		||||
        //If the request is already accepted we just return ok (otherwise we would duplicate the procedure below)
 | 
			
		||||
        if (unregisterRequest.getState() == RequestState.Accepted){
 | 
			
		||||
            return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        unregisterRequest.setState(newstate);
 | 
			
		||||
        unregisterRequestRepository.save(unregisterRequest);
 | 
			
		||||
        if (newstate == RequestState.Accepted){
 | 
			
		||||
            if (unregisterRequest.getCurriculum() == null){
 | 
			
		||||
                ArrayList<UserCurriculum> userCurricula = userCurriculumRepository.findByUserOrderByCurriculum(u);
 | 
			
		||||
                for (int i = 0; i < userCurricula.size(); i++){
 | 
			
		||||
                    userCurricula.get(i).setActual(false);
 | 
			
		||||
                }
 | 
			
		||||
                userCurriculumRepository.saveAll(userCurricula);
 | 
			
		||||
            }else{
 | 
			
		||||
                //This usercurriculum will contain the usercurriculum to set false
 | 
			
		||||
                UserCurriculum userCurriculum = userCurriculumRepository.findByUserAndCurriculumAndActual(u, unregisterRequest.getCurriculum(), true);
 | 
			
		||||
                userCurriculum.setActual(false);
 | 
			
		||||
                userCurriculumRepository.save(userCurriculum);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //We look in the usercursus table if the student has already the previous year of a curriculum
 | 
			
		||||
    public boolean studentHasPrevYear(Curriculum curriculum, User user){
 | 
			
		||||
        ArrayList<UserCurriculum> userCurrList = userCurriculumRepository.findByUserOrderByCurriculum(user);
 | 
			
		||||
        for (int i = 0; i < userCurrList.size(); i++){
 | 
			
		||||
            if (userCurrList.get(i).getCurriculum().getOption().equals(curriculum.getOption()) && userCurrList.get(i).getCurriculum().getYear() == curriculum.getYear()-1){
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    @PostMapping("/changecurriculumreq")
 | 
			
		||||
    public ResponseEntity<String> addChangeCurrReq(@RequestBody Map<String,Object> reqInfos){
 | 
			
		||||
        User user = userRepository.findById((Integer) reqInfos.get("userId"));
 | 
			
		||||
 | 
			
		||||
        Curriculum actualCurriculum;
 | 
			
		||||
 | 
			
		||||
        //If null then it means we are in a supplementary cursus case
 | 
			
		||||
        if (reqInfos.get("actualcursus") == null){
 | 
			
		||||
            actualCurriculum = null;
 | 
			
		||||
        }else{
 | 
			
		||||
            actualCurriculum = curriculumRepository.findById((Integer) reqInfos.get("actualcursus"));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Curriculum destinationCurriculum = curriculumRepository.findById((Integer) reqInfos.get("newcursus"));
 | 
			
		||||
 | 
			
		||||
        ChangeCurriculumRequest changeCurriculumRequest = new ChangeCurriculumRequest(user, actualCurriculum, destinationCurriculum, new Date(), RequestState.Pending, RequestState.Unrequired);
 | 
			
		||||
 | 
			
		||||
        //Si l'année du cursus est plus grande que 1 et que l'étudiant n'a pas dans sa liste de cursus l'année d'en dessous alors on demande l'accord du prof
 | 
			
		||||
        if (destinationCurriculum.getYear() > 1 && !studentHasPrevYear(destinationCurriculum, user)){
 | 
			
		||||
            changeCurriculumRequest.setTeacherApprovalState(RequestState.Pending);
 | 
			
		||||
        }
 | 
			
		||||
        changeCurriculumRequestRepository.save(changeCurriculumRequest);
 | 
			
		||||
 | 
			
		||||
        return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/changecurriculumreq")
 | 
			
		||||
    public  ResponseEntity<ArrayList <ChangeCurriculumRequest>> getAllChangeCurrReq(@RequestHeader("Authorization") String token){
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService, Role.Teacher},token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        ArrayList<ChangeCurriculumRequest> toReturn = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
        changeCurriculumRequestRepository.findAll().forEach(toReturn::add);
 | 
			
		||||
 | 
			
		||||
        return new ResponseEntity<>(toReturn, HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/changecurriculumreq/{id}")
 | 
			
		||||
    public ResponseEntity<ChangeCurriculumRequest> getCCrbyId(@RequestHeader("Authorization") String token, @PathVariable long id){
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher,Role.InscriptionService},token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        ChangeCurriculumRequest toReturn = changeCurriculumRequestRepository.findById(id);
 | 
			
		||||
        return new ResponseEntity<>(toReturn, HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PatchMapping("/changecurriculumreq/{id}/{newState}")
 | 
			
		||||
    public ResponseEntity<String> editCCReq(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newState){
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        ChangeCurriculumRequest toEdit = changeCurriculumRequestRepository.findById(id);
 | 
			
		||||
 | 
			
		||||
        //If the request is already accepted we just return ok (otherwise we would duplicate the procedure below)
 | 
			
		||||
        if (toEdit.getState() == RequestState.Accepted){
 | 
			
		||||
            return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        toEdit.setState(newState);
 | 
			
		||||
        changeCurriculumRequestRepository.save(toEdit);
 | 
			
		||||
        if (newState == RequestState.Accepted && (toEdit.getTeacherApprovalState() == RequestState.Accepted || toEdit.getTeacherApprovalState() == RequestState.Unrequired)){
 | 
			
		||||
            //If actual curriculum is not null then we need to set that the user doesn't follow it anymore
 | 
			
		||||
            acceptProcedure(toEdit);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PatchMapping("/changecurriculumreqteacher/{id}/{newteacherstate}")
 | 
			
		||||
    public ResponseEntity<String> editCCReqTeacherState(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newteacherstate){
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        ChangeCurriculumRequest toEdit = changeCurriculumRequestRepository.findById(id);
 | 
			
		||||
 | 
			
		||||
        //If the request is already accepted we just return ok (otherwise we would duplicate the procedure below)
 | 
			
		||||
        if (toEdit.getTeacherApprovalState() == RequestState.Accepted){
 | 
			
		||||
            return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        toEdit.setState(newteacherstate);
 | 
			
		||||
        changeCurriculumRequestRepository.save(toEdit);
 | 
			
		||||
 | 
			
		||||
        if (newteacherstate == RequestState.Accepted && toEdit.getState() == RequestState.Accepted){
 | 
			
		||||
            //If actual curriculum is not null then we need to set that the user doesn't follow it anymore
 | 
			
		||||
            acceptProcedure(toEdit);
 | 
			
		||||
        }
 | 
			
		||||
        return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void acceptProcedure(ChangeCurriculumRequest toEdit) {
 | 
			
		||||
        User u = toEdit.getUser();
 | 
			
		||||
        if (toEdit.getActualCurriculum() != null){
 | 
			
		||||
            ArrayList<UserCurriculum> listcurr = userCurriculumRepository.findByUserOrderByCurriculum(u);
 | 
			
		||||
 | 
			
		||||
            for (int i = 0; i < listcurr.size(); i++){
 | 
			
		||||
                if (listcurr.get(i).getCurriculum() == toEdit.getActualCurriculum()){
 | 
			
		||||
                    listcurr.get(i).setActual(false);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            userCurriculumRepository.saveAll(listcurr);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Calendar c = Calendar.getInstance();
 | 
			
		||||
        UserCurriculum userCurriculum = new UserCurriculum(u, toEdit.getDestinationCurriculum(), c.get(Calendar.YEAR), true);
 | 
			
		||||
        userCurriculumRepository.save(userCurriculum);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/exemptionreq/{userId}")
 | 
			
		||||
    public ResponseEntity<ArrayList<ExemptionsRequest>> getExReqByuser(@RequestHeader("Authorization") String token, @PathVariable long userId){
 | 
			
		||||
        User currentUser = tokenService.getUserFromToken(token);
 | 
			
		||||
 | 
			
		||||
        //Only admin, teacher, secretary and the student himself can access a student's data here
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher, Role.Secretary},token) && currentUser.getRegNo() != userId)
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        User u = userRepository.findById(userId);
 | 
			
		||||
 | 
			
		||||
        ArrayList<ExemptionsRequest> exList = err.findByUser(u);
 | 
			
		||||
        return new ResponseEntity<>(exList, HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -6,13 +6,11 @@ import ovh.herisson.Clyde.Repositories.*;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.Inscription.ExternalCurriculumRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.Inscription.MinervalRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.Inscription.ScholarshipRequestRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.Inscription.UnregisterRequestRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Services.*;
 | 
			
		||||
import ovh.herisson.Clyde.Services.Inscription.InscriptionService;
 | 
			
		||||
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 ovh.herisson.Clyde.Tables.Inscription.ScholarshipRequest;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Inscription.*;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
@ -23,7 +21,7 @@ import java.util.Date;
 | 
			
		||||
 | 
			
		||||
public class MockController {
 | 
			
		||||
    private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
 | 
			
		||||
 | 
			
		||||
    public final UserService userService;
 | 
			
		||||
    public final UserRepository userRepo;
 | 
			
		||||
    public final TokenRepository tokenRepo;
 | 
			
		||||
    public final TokenService tokenService;
 | 
			
		||||
@ -40,7 +38,9 @@ public class MockController {
 | 
			
		||||
 | 
			
		||||
    public final ScholarshipRequestRepository scholarshipRequestRepository;
 | 
			
		||||
 | 
			
		||||
    public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, ExternalCurriculumRepository externalCurriculumRepository, InscriptionService inscriptionService, UserCurriculumRepository ucr, MinervalRepository minervalRepository, ScholarshipRequestRepository scholarshipRequestRepository){
 | 
			
		||||
    public final UnregisterRequestRepository uninscriptionRequestRepository;
 | 
			
		||||
    public MockController(UserService userService, UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, ExternalCurriculumRepository externalCurriculumRepository, InscriptionService inscriptionService, UserCurriculumRepository ucr, MinervalRepository minervalRepository, ScholarshipRequestRepository scholarshipRequestRepository, UnregisterRequestRepository unregisterRequestRepository){
 | 
			
		||||
        this.userService = userService;
 | 
			
		||||
        this.tokenRepo = tokenRepo;
 | 
			
		||||
        this.userRepo = userRepo;
 | 
			
		||||
        this.tokenService = tokenService;
 | 
			
		||||
@ -52,6 +52,7 @@ public class MockController {
 | 
			
		||||
        this.ucr = ucr;
 | 
			
		||||
        this.minervalRepository = minervalRepository;
 | 
			
		||||
        this.scholarshipRequestRepository = scholarshipRequestRepository;
 | 
			
		||||
        this.uninscriptionRequestRepository = unregisterRequestRepository;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** Saves an example of each user type by :
 | 
			
		||||
@ -73,18 +74,23 @@ public class MockController {
 | 
			
		||||
        User popo = new User("Smith", "Paul", "paulsmith@gmail.com", "306 rue du poulet", "belgique", new Date(0), null, Role.Student, passwordEncoder.encode("jesuispaulleroi"));
 | 
			
		||||
        mockUsers = new ArrayList<>(Arrays.asList(herobrine,joe,meh,joke,lena,jojo, popo));
 | 
			
		||||
 | 
			
		||||
        userRepo.saveAll(mockUsers);
 | 
			
		||||
        userService.saveAll(mockUsers);
 | 
			
		||||
 | 
			
		||||
        ExternalCurriculum externalCurriculum = new ExternalCurriculum(null, "HEH", "Bachelier en ingénieur", "completed", 2015, 2017, null, joe);
 | 
			
		||||
        externalCurriculumRepository.save(externalCurriculum);
 | 
			
		||||
 | 
			
		||||
        Minerval minerval = new Minerval(joe.getRegNo(), 0, 852, 2023);
 | 
			
		||||
        minervalRepository.save(minerval);
 | 
			
		||||
        // Course / Curriculum part
 | 
			
		||||
 | 
			
		||||
        Curriculum infoBab1 = new Curriculum(1,"info");
 | 
			
		||||
        Curriculum chemistryBab1 = new Curriculum(1,"chemistry");
 | 
			
		||||
        Curriculum psychologyBab1 = new Curriculum(1,"psychology");
 | 
			
		||||
        Curriculum infoBab2 = new Curriculum(2,"info");
 | 
			
		||||
        Curriculum masterinfo1 = new Curriculum(4, "info");
 | 
			
		||||
        Curriculum masterinfo2 = new Curriculum(5, "info");
 | 
			
		||||
        Curriculum infoBab1 = new Curriculum(1,"info", false);
 | 
			
		||||
        Curriculum chemistryBab1 = new Curriculum(1,"chemistry", false);
 | 
			
		||||
        Curriculum psychologyBab1 = new Curriculum(1,"psychology", false);
 | 
			
		||||
        Curriculum infoBab2 = new Curriculum(2,"info", false);
 | 
			
		||||
        Curriculum masterinfo1 = new Curriculum(4, "info", false);
 | 
			
		||||
        Curriculum masterinfo2 = new Curriculum(5, "info", false);
 | 
			
		||||
        Curriculum chemistryBab2 = new Curriculum(2, "chemistry", false);
 | 
			
		||||
        Curriculum ingebab1 = new Curriculum(1, "ingénieur", true);
 | 
			
		||||
 | 
			
		||||
        curriculumService.save(infoBab1);
 | 
			
		||||
        curriculumService.save(chemistryBab1);
 | 
			
		||||
@ -92,16 +98,18 @@ public class MockController {
 | 
			
		||||
        curriculumService.save(infoBab2);
 | 
			
		||||
        curriculumService.save(masterinfo1);
 | 
			
		||||
        curriculumService.save(masterinfo2);
 | 
			
		||||
        curriculumService.save(chemistryBab2);
 | 
			
		||||
        curriculumService.save(ingebab1);
 | 
			
		||||
 | 
			
		||||
        ucr.save(new UserCurriculum(joe, infoBab1, 2022));
 | 
			
		||||
        ucr.save(new UserCurriculum(joe, chemistryBab1, 2023));
 | 
			
		||||
        ucr.save(new UserCurriculum(joe, infoBab1, 2023));
 | 
			
		||||
        ucr.save(new UserCurriculum(joe, psychologyBab1, 2020));
 | 
			
		||||
        ucr.save(new UserCurriculum(popo, infoBab1, 2022));
 | 
			
		||||
        ucr.save(new UserCurriculum(popo, infoBab2, 2023));
 | 
			
		||||
        ucr.save(new UserCurriculum(joe, infoBab1, 2022, false));
 | 
			
		||||
        ucr.save(new UserCurriculum(joe, chemistryBab1, 2023, true));
 | 
			
		||||
        ucr.save(new UserCurriculum(joe, infoBab1, 2023, true));
 | 
			
		||||
        ucr.save(new UserCurriculum(joe, psychologyBab1, 2020, false));
 | 
			
		||||
        ucr.save(new UserCurriculum(popo, infoBab1, 2022, false));
 | 
			
		||||
        ucr.save(new UserCurriculum(popo, infoBab2, 2023, true));
 | 
			
		||||
 | 
			
		||||
        Course progra1 = new Course(5,"Programmation et algorithmique 1",joke);
 | 
			
		||||
        Course chemistry1 = new Course(12, "Thermochimie",joke);
 | 
			
		||||
        Course chemistry1 = new Course(12, "Thermochimie",jojo);
 | 
			
		||||
        Course psycho1 = new Course(21, "Neuroreaction of isolated brain cells",joke);
 | 
			
		||||
        Course commun = new Course(2, "cours commun",joke);
 | 
			
		||||
 | 
			
		||||
@ -118,17 +126,19 @@ public class MockController {
 | 
			
		||||
        CurriculumCourseService.save(new CurriculumCourse(infoBab1, psycho1));
 | 
			
		||||
        CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,psycho1));
 | 
			
		||||
        CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,commun));
 | 
			
		||||
 | 
			
		||||
        CurriculumCourseService.save(new CurriculumCourse(chemistryBab1, chemistry1));
 | 
			
		||||
 | 
			
		||||
        CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,commun));
 | 
			
		||||
        CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,chemistry1));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        InscriptionRequest inscriptionRequest = new InscriptionRequest("helen","prenom","non","helen@gmail.com","america",new Date(),(long) 4,RequestState.Pending,"yes.png","password", null, new Date(), RequestState.Pending);
 | 
			
		||||
        InscriptionRequest inscriptionRequest = new InscriptionRequest("helen","prenom","non","helen@gmail.com","america",new Date(),(long) 4,RequestState.Pending,"yes.png","password", null, new Date(), RequestState.Pending, null);
 | 
			
		||||
 | 
			
		||||
        inscriptionService.save(inscriptionRequest);
 | 
			
		||||
 | 
			
		||||
        ExternalCurriculum externalCurriculum = new ExternalCurriculum(inscriptionRequest, "HEH", "Bachelier en informatique", "Completed", 2015, 2018, null, null);
 | 
			
		||||
        UnregisterRequest unregisterRequest = new UnregisterRequest(RequestState.Pending, "je veux partir", new Date(), joe.getRegNo(), joe.getFirstName(), joe.getLastName(), joe.getEmail(), null);
 | 
			
		||||
        uninscriptionRequestRepository.save(unregisterRequest);
 | 
			
		||||
 | 
			
		||||
        externalCurriculum = new ExternalCurriculum(inscriptionRequest, "HEH", "Bachelier en informatique", "Completed", 2015, 2018, null, null);
 | 
			
		||||
        externalCurriculumRepository.save(externalCurriculum);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,113 @@
 | 
			
		||||
package ovh.herisson.Clyde.EndPoints.Msg;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.http.HttpStatus;
 | 
			
		||||
import org.springframework.http.HttpStatusCode;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
import org.springframework.web.bind.annotation.CrossOrigin;
 | 
			
		||||
import org.springframework.web.bind.annotation.GetMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.PathVariable;
 | 
			
		||||
import org.springframework.web.bind.annotation.PostMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestBody;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestHeader;
 | 
			
		||||
import org.springframework.web.bind.annotation.RestController;
 | 
			
		||||
 | 
			
		||||
import jakarta.websocket.server.PathParam;
 | 
			
		||||
import lombok.AllArgsConstructor;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.Msg.AnswerRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.Msg.ForumRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.Msg.TopicRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
 | 
			
		||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
 | 
			
		||||
import ovh.herisson.Clyde.Services.CourseService;
 | 
			
		||||
import ovh.herisson.Clyde.Services.Msg.ForumService;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Course;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Role;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Token;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Msg.Answer;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Msg.Forum;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Msg.Topic;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
 | 
			
		||||
@AllArgsConstructor
 | 
			
		||||
public class ForumController {
 | 
			
		||||
 | 
			
		||||
	private CourseRepository courseRepo;
 | 
			
		||||
	private AuthenticatorService authServ;
 | 
			
		||||
	private ForumService forumServ;
 | 
			
		||||
	private ForumRepository forumRepo;
 | 
			
		||||
	private TopicRepository topicRepo;
 | 
			
		||||
 | 
			
		||||
	//// Endpoints to get and create new forums
 | 
			
		||||
 | 
			
		||||
	@GetMapping("/forums/{id}")
 | 
			
		||||
	public ResponseEntity<List<Forum>> getForumFromCourseId(@RequestHeader("Authorization") String token, @PathVariable long id){
 | 
			
		||||
		User u = authServ.getUserFromToken(token);
 | 
			
		||||
		if(u == null){
 | 
			
		||||
			return new UnauthorizedResponse<>(null);
 | 
			
		||||
		}
 | 
			
		||||
		return new ResponseEntity<>(courseRepo.findById(id).getForums(), HttpStatus.OK);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@PostMapping("/forums/{id}")
 | 
			
		||||
	public ResponseEntity<Forum> createForumOfCourse(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Forum data){
 | 
			
		||||
		User u = authServ.getUserFromToken(token);
 | 
			
		||||
		Course c = courseRepo.findById(id);
 | 
			
		||||
		if(!(c.getOwner().equals(u) || u.getRole() == Role.Admin)){
 | 
			
		||||
			return new UnauthorizedResponse<>(null);
 | 
			
		||||
		}
 | 
			
		||||
		forumServ.createForum(c, data);
 | 
			
		||||
		return new ResponseEntity<>(HttpStatus.ACCEPTED);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	//// Endpoints to get and create forum's topic
 | 
			
		||||
 | 
			
		||||
	@GetMapping("/forum/{id}")
 | 
			
		||||
	public ResponseEntity<List<Topic>> getTopicsFromForumId(@RequestHeader("Authorization") String token, @PathVariable long id){
 | 
			
		||||
		User u = authServ.getUserFromToken(token);
 | 
			
		||||
		if(u == null){
 | 
			
		||||
			return new UnauthorizedResponse<>(null);
 | 
			
		||||
		}
 | 
			
		||||
		return new ResponseEntity<>(forumRepo.findById(id).orElse(null).getTopics(), HttpStatus.OK);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@PostMapping("/forum/{id}")
 | 
			
		||||
	public ResponseEntity<Topic> postTopicToForum(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Topic data){
 | 
			
		||||
		User u = authServ.getUserFromToken(token);
 | 
			
		||||
		Forum f = forumRepo.findById(id).orElse(null);
 | 
			
		||||
		if(!(f.getWriters().contains(u) || u.getRole() == Role.Admin)){
 | 
			
		||||
			return new UnauthorizedResponse<>(null);
 | 
			
		||||
		}
 | 
			
		||||
		forumServ.createTopic(f, data);
 | 
			
		||||
		return new ResponseEntity<>(HttpStatus.ACCEPTED);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	//// Endpoints related to topics and messages
 | 
			
		||||
	
 | 
			
		||||
	@GetMapping("/forum/post/{id}")
 | 
			
		||||
	public ResponseEntity<Topic> getPost(@RequestHeader("Authorization") String token, @PathVariable long id){
 | 
			
		||||
		User u = authServ.getUserFromToken(token);
 | 
			
		||||
		if(u == null){
 | 
			
		||||
			return new UnauthorizedResponse<>(null);
 | 
			
		||||
		}
 | 
			
		||||
		Topic t = topicRepo.findById(id).orElse(null);
 | 
			
		||||
		return new ResponseEntity<>(t, HttpStatus.OK);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@PostMapping("/forum/post/{id}")
 | 
			
		||||
	public ResponseEntity<Topic> postTopicToForum(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Answer data){
 | 
			
		||||
		User u = authServ.getUserFromToken(token);
 | 
			
		||||
		Topic t = topicRepo.findById(id).orElse(null);
 | 
			
		||||
		if(t.isLocked() && u.getRole() != Role.Admin){
 | 
			
		||||
			return new UnauthorizedResponse<>(null);
 | 
			
		||||
		}
 | 
			
		||||
		System.out.println(data);
 | 
			
		||||
		forumServ.answerTopic(t, data, u);
 | 
			
		||||
		return new ResponseEntity<>(HttpStatus.ACCEPTED);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,9 @@
 | 
			
		||||
package ovh.herisson.Clyde.Repositories.Inscription;
 | 
			
		||||
 | 
			
		||||
import org.springframework.data.repository.CrudRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.ChangeCurriculumRequest;
 | 
			
		||||
 | 
			
		||||
public interface ChangeCurriculumRequestRepository extends CrudRepository<ChangeCurriculumRequest, Long> {
 | 
			
		||||
    ChangeCurriculumRequest findById(long id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -2,7 +2,12 @@ package ovh.herisson.Clyde.Repositories.Inscription;
 | 
			
		||||
 | 
			
		||||
import org.springframework.data.repository.CrudRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Inscription.ExemptionsRequest;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
public interface ExemptionsRequestRepository extends CrudRepository<ExemptionsRequest, Long> {
 | 
			
		||||
    ExemptionsRequest findById(long id);
 | 
			
		||||
 | 
			
		||||
    ArrayList<ExemptionsRequest> findByUser(User user);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -4,5 +4,5 @@ import org.springframework.data.repository.CrudRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Inscription.ScholarshipRequest;
 | 
			
		||||
 | 
			
		||||
public interface ScholarshipRequestRepository extends CrudRepository<ScholarshipRequest, Long> {
 | 
			
		||||
 | 
			
		||||
    public ScholarshipRequest findById(long id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,7 +0,0 @@
 | 
			
		||||
package ovh.herisson.Clyde.Repositories.Inscription;
 | 
			
		||||
 | 
			
		||||
import org.springframework.data.repository.CrudRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Inscription.UninscriptionRequest;
 | 
			
		||||
 | 
			
		||||
public interface UninscriptionRequestRepository extends CrudRepository<UninscriptionRequest, Long> {
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,8 @@
 | 
			
		||||
package ovh.herisson.Clyde.Repositories.Inscription;
 | 
			
		||||
 | 
			
		||||
import org.springframework.data.repository.CrudRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Inscription.UnregisterRequest;
 | 
			
		||||
 | 
			
		||||
public interface UnregisterRequestRepository extends CrudRepository<UnregisterRequest, Long> {
 | 
			
		||||
    public UnregisterRequest findById(long l);
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,10 @@
 | 
			
		||||
package ovh.herisson.Clyde.Repositories.Msg;
 | 
			
		||||
 | 
			
		||||
import org.springframework.data.repository.CrudRepository;
 | 
			
		||||
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Msg.Answer;
 | 
			
		||||
 | 
			
		||||
public interface AnswerRepository extends CrudRepository<Answer, Long> {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,9 @@
 | 
			
		||||
package ovh.herisson.Clyde.Repositories.Msg;
 | 
			
		||||
 | 
			
		||||
import org.springframework.data.repository.CrudRepository;
 | 
			
		||||
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Msg.Forum;
 | 
			
		||||
 | 
			
		||||
public interface ForumRepository extends CrudRepository<Forum, Long> {
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,10 @@
 | 
			
		||||
package ovh.herisson.Clyde.Repositories.Msg;
 | 
			
		||||
 | 
			
		||||
import org.springframework.data.repository.CrudRepository;
 | 
			
		||||
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Msg.Topic;
 | 
			
		||||
 | 
			
		||||
public interface TopicRepository extends CrudRepository<Topic, Long> {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -14,4 +14,8 @@ public interface UserCurriculumRepository extends CrudRepository<UserCurriculum,
 | 
			
		||||
    Curriculum findByUser(User student);
 | 
			
		||||
 | 
			
		||||
    ArrayList<UserCurriculum> findByUserOrderByCurriculum(User student);
 | 
			
		||||
    UserCurriculum findByUserAndCurriculumAndActual(User user, Curriculum curriculum, boolean actual);
 | 
			
		||||
 | 
			
		||||
    ArrayList<UserCurriculum> findByUserAndActual(User user, boolean actual);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -46,7 +46,7 @@ public class CurriculumCourseService {
 | 
			
		||||
        toReturn.put("curriculumId", curriculum.getCurriculumId());
 | 
			
		||||
        toReturn.put("year", curriculum.getYear());
 | 
			
		||||
        toReturn.put("option", curriculum.getOption());
 | 
			
		||||
 | 
			
		||||
        toReturn.put("requireCertificate", curriculum.isRequireCertificate());
 | 
			
		||||
 | 
			
		||||
        return  toReturn;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -6,12 +6,14 @@ 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.Services.UserService;
 | 
			
		||||
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;
 | 
			
		||||
import java.util.Calendar;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
public class InscriptionService {
 | 
			
		||||
@ -27,14 +29,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, ExternalCurriculumRepository externalCurriculumRepository){
 | 
			
		||||
    private final UserService userService;
 | 
			
		||||
    public InscriptionService(InscriptionRepository inscriptionRepo, UserRepository userRepo, UserCurriculumRepository userCurriculumRepo, CurriculumRepository curriculumRepo, MinervalRepository minervalRepository, ExternalCurriculumRepository externalCurriculumRepository, UserService userService){
 | 
			
		||||
        this.inscriptionRepo = inscriptionRepo;
 | 
			
		||||
        this.userRepo = userRepo;
 | 
			
		||||
        this.userCurriculumRepo = userCurriculumRepo;
 | 
			
		||||
        this.curriculumRepo = curriculumRepo;
 | 
			
		||||
        this.minervalRepository = minervalRepository;
 | 
			
		||||
        this.externalCurriculumRepository = externalCurriculumRepository;
 | 
			
		||||
        this.userService = userService;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public InscriptionRequest save(InscriptionRequest inscriptionRequest){
 | 
			
		||||
@ -56,6 +59,11 @@ public class InscriptionService {
 | 
			
		||||
        if (inscrRequest == null)
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        //If the request is already accepted we just return ok (otherwise we would duplicate the procedure below)
 | 
			
		||||
        if (inscrRequest.getState() == RequestState.Accepted){
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        inscrRequest.setState(requestState);
 | 
			
		||||
        save(inscrRequest);
 | 
			
		||||
 | 
			
		||||
@ -84,8 +92,9 @@ public class InscriptionService {
 | 
			
		||||
                inscrRequest.getPassword()
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        userRepo.save(userFromRequest);
 | 
			
		||||
        userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId()),0));
 | 
			
		||||
        userService.save(userFromRequest);
 | 
			
		||||
        Calendar c = Calendar.getInstance();
 | 
			
		||||
        userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId()),c.get(Calendar.YEAR), true));
 | 
			
		||||
 | 
			
		||||
        //Create a minerval for the new student
 | 
			
		||||
        Minerval minerval = new Minerval(userFromRequest.getRegNo(), 0, 852, 2023);
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,38 @@
 | 
			
		||||
package ovh.herisson.Clyde.Services.Msg;
 | 
			
		||||
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
import lombok.AllArgsConstructor;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.Msg.ForumRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.Msg.TopicRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Course;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Msg.Answer;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Msg.Forum;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Msg.Topic;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
@AllArgsConstructor
 | 
			
		||||
public class ForumService {
 | 
			
		||||
 | 
			
		||||
	private CourseRepository courseRepo;
 | 
			
		||||
	private ForumRepository forumRepo;
 | 
			
		||||
	private TopicRepository topicRepo;
 | 
			
		||||
 | 
			
		||||
	public void createForum(Course c, Forum f){
 | 
			
		||||
		c.addForum(f);
 | 
			
		||||
		courseRepo.save(c);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    public void createTopic(Forum f, Topic data) {
 | 
			
		||||
		f.addTopic(data);
 | 
			
		||||
		forumRepo.save(f);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void answerTopic(Topic t, Answer data, User	u) {
 | 
			
		||||
		data.setAuthor(u);
 | 
			
		||||
		t.addAnswer(data);
 | 
			
		||||
		topicRepo.save(t);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -51,7 +51,7 @@ public class ProtectionService {
 | 
			
		||||
 | 
			
		||||
        HashMap<String ,Object> toReturn = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
        toReturn.put("courseId",course.getCourseID());
 | 
			
		||||
        toReturn.put("courseID",course.getCourseID());
 | 
			
		||||
        toReturn.put("credits",course.getCredits());
 | 
			
		||||
        toReturn.put("title", course.getTitle());
 | 
			
		||||
        toReturn.put("owner", userWithoutPassword(course.getOwner()));
 | 
			
		||||
 | 
			
		||||
@ -35,11 +35,12 @@ public class UserCurriculumService {
 | 
			
		||||
            HashMap<String, Object> element = new HashMap<>();
 | 
			
		||||
            Curriculum c = list.get(i).getCurriculum();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            element.put("curriculumId", c.getCurriculumId());
 | 
			
		||||
            element.put("year", c.getYear());
 | 
			
		||||
            element.put("option", c.getOption());
 | 
			
		||||
            element.put("dateyear", list.get(i).getYear());
 | 
			
		||||
            element.put("actual", list.get(i).isActual());
 | 
			
		||||
 | 
			
		||||
            curriculumlist.add(element);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -48,5 +49,7 @@ public class UserCurriculumService {
 | 
			
		||||
        return toReturn;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public ArrayList<UserCurriculum> findByStudentAndActual(User u, boolean actual){
 | 
			
		||||
        return userCurriculumRepository.findByUserAndActual(u, actual);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,7 @@ package ovh.herisson.Clyde.Services;
 | 
			
		||||
 | 
			
		||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.RegNoGenerator;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.UserRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Notification;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Role;
 | 
			
		||||
@ -107,10 +108,17 @@ public class UserService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public User save(User  user){
 | 
			
		||||
        RegNoGenerator.resetCount();
 | 
			
		||||
        user.setPassword(passwordEncoder.encode(user.getPassword()));
 | 
			
		||||
        return userRepo.save(user);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void saveAll(ArrayList<User> list){
 | 
			
		||||
        //S'assure que le compteur est bien a 0
 | 
			
		||||
        RegNoGenerator.resetCount();
 | 
			
		||||
        userRepo.saveAll(list);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Iterable<User> getAll(){
 | 
			
		||||
        return userRepo.findAll();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -19,5 +19,6 @@ public enum Applications {
 | 
			
		||||
 | 
			
		||||
    // InscriptionService authorization
 | 
			
		||||
    Requests,
 | 
			
		||||
    StudentsList
 | 
			
		||||
    StudentsList,
 | 
			
		||||
    Payments
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,95 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class ChangeCurriculumRequest {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private int id;
 | 
			
		||||
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name="Users")
 | 
			
		||||
    private User user;
 | 
			
		||||
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name = "ActualCurriculum")
 | 
			
		||||
    private Curriculum actualCurriculum;
 | 
			
		||||
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name = "DestCurriculum")
 | 
			
		||||
    private Curriculum destinationCurriculum;
 | 
			
		||||
 | 
			
		||||
    private Date date;
 | 
			
		||||
 | 
			
		||||
    private RequestState state;
 | 
			
		||||
 | 
			
		||||
    private RequestState teacherApprovalState;
 | 
			
		||||
    public ChangeCurriculumRequest(){}
 | 
			
		||||
 | 
			
		||||
    public ChangeCurriculumRequest(User user, Curriculum actualCurriculum, Curriculum destinationCurriculum, Date date, RequestState state, RequestState teacherApprovalState){
 | 
			
		||||
        this.user = user;
 | 
			
		||||
        this.actualCurriculum = actualCurriculum;
 | 
			
		||||
        this.destinationCurriculum = destinationCurriculum;
 | 
			
		||||
        this.date = date;
 | 
			
		||||
        this.state = state;
 | 
			
		||||
        this.teacherApprovalState = teacherApprovalState;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public User getUser() {
 | 
			
		||||
        return user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setUser(User user) {
 | 
			
		||||
        this.user = user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public Curriculum getActualCurriculum() {
 | 
			
		||||
        return actualCurriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setActualCurriculum(Curriculum actualCurriculum) {
 | 
			
		||||
        this.actualCurriculum = actualCurriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Curriculum getDestinationCurriculum() {
 | 
			
		||||
        return destinationCurriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setDestinationCurriculum(Curriculum destinationCurriculum) {
 | 
			
		||||
        this.destinationCurriculum = destinationCurriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setDate(Date date) {
 | 
			
		||||
        this.date = date;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Date getDate() {
 | 
			
		||||
        return date;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public RequestState getState() {
 | 
			
		||||
        return state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setState(RequestState state) {
 | 
			
		||||
        this.state = state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getId() {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public RequestState getTeacherApprovalState() {
 | 
			
		||||
        return teacherApprovalState;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setTeacherApprovalState(RequestState teacherApprovalState) {
 | 
			
		||||
        this.teacherApprovalState = teacherApprovalState;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,10 +1,20 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
import lombok.AllArgsConstructor;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import lombok.NoArgsConstructor;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Msg.Forum;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import org.hibernate.annotations.OnDelete;
 | 
			
		||||
import org.hibernate.annotations.OnDeleteAction;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
@Data
 | 
			
		||||
@NoArgsConstructor
 | 
			
		||||
@AllArgsConstructor
 | 
			
		||||
public class Course {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
@ -17,39 +27,18 @@ public class Course {
 | 
			
		||||
    @JoinColumn(name = "Users")
 | 
			
		||||
    private User owner;
 | 
			
		||||
 | 
			
		||||
	//// Extension Messagerie /////
 | 
			
		||||
	@OneToMany(cascade = CascadeType.ALL)
 | 
			
		||||
	private List<Forum> forums;
 | 
			
		||||
 | 
			
		||||
	public void addForum(Forum f){
 | 
			
		||||
		forums.add(f);
 | 
			
		||||
	}
 | 
			
		||||
	///////////////////////////////
 | 
			
		||||
 | 
			
		||||
    public Course(int credits, String title, User owner){
 | 
			
		||||
        this.credits = credits;
 | 
			
		||||
        this.title = title;
 | 
			
		||||
        this.owner = owner;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Course() {}
 | 
			
		||||
 | 
			
		||||
    public int getCourseID() {
 | 
			
		||||
        return courseID;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getCredits() {
 | 
			
		||||
        return credits;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCredits(int credits){
 | 
			
		||||
        this.credits = credits;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getTitle() {
 | 
			
		||||
        return title;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setTitle(String title){
 | 
			
		||||
        this.title = title;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public User getOwner() {
 | 
			
		||||
        return owner;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setOwner(User owner) {
 | 
			
		||||
        this.owner = owner;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -12,9 +12,13 @@ public class Curriculum {
 | 
			
		||||
    private int curriculumId;
 | 
			
		||||
    private int year;
 | 
			
		||||
    private String option;
 | 
			
		||||
    public Curriculum(int year, String option){
 | 
			
		||||
 | 
			
		||||
    //True if the curriculum need an entry exam
 | 
			
		||||
    private boolean requireCertificate;
 | 
			
		||||
    public Curriculum(int year, String option, boolean requireCertificate){
 | 
			
		||||
        this.year = year;
 | 
			
		||||
        this.option = option;
 | 
			
		||||
        this.requireCertificate = requireCertificate;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Curriculum() {}
 | 
			
		||||
@ -39,4 +43,11 @@ public class Curriculum {
 | 
			
		||||
        this.option = option;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setRequireCertificate(boolean requireCertificate) {
 | 
			
		||||
        this.requireCertificate = requireCertificate;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isRequireCertificate() {
 | 
			
		||||
        return requireCertificate;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -3,5 +3,6 @@ package ovh.herisson.Clyde.Tables;
 | 
			
		||||
public enum FileType {
 | 
			
		||||
    ProfilePicture,
 | 
			
		||||
    EducationCertificate,
 | 
			
		||||
    JustificationDocument
 | 
			
		||||
    JustificationDocument,
 | 
			
		||||
    IdentityCard,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -80,4 +80,8 @@ public class ExemptionsRequest {
 | 
			
		||||
    public void setDate(Date date) {
 | 
			
		||||
        this.date = date;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getId() {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -22,11 +22,12 @@ public class InscriptionRequest {
 | 
			
		||||
    private String profilePicture;
 | 
			
		||||
    private String password;
 | 
			
		||||
    private String identityCard;
 | 
			
		||||
    private String admissionDocUrl;
 | 
			
		||||
    private Date submissionDate;
 | 
			
		||||
    private RequestState equivalenceState;
 | 
			
		||||
    public InscriptionRequest(){}
 | 
			
		||||
 | 
			
		||||
    public InscriptionRequest(String lastName, String firstName, String address, String email, String country, Date birthDate,Long curriculumId, RequestState state, String profilePicture, String password, String identityCard, Date submissionDate, RequestState equivalenceState){
 | 
			
		||||
    public InscriptionRequest(String lastName, String firstName, String address, String email, String country, Date birthDate,Long curriculumId, RequestState state, String profilePicture, String password, String identityCard, Date submissionDate, RequestState equivalenceState, String admissionDocUrl){
 | 
			
		||||
        this.lastName = lastName;
 | 
			
		||||
        this.firstName = firstName;
 | 
			
		||||
        this.address = address;
 | 
			
		||||
@ -40,6 +41,7 @@ public class InscriptionRequest {
 | 
			
		||||
        this.identityCard = identityCard;
 | 
			
		||||
        this.submissionDate = submissionDate;
 | 
			
		||||
        this.equivalenceState = equivalenceState;
 | 
			
		||||
        this.admissionDocUrl = admissionDocUrl;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getId() {
 | 
			
		||||
@ -149,4 +151,12 @@ public class InscriptionRequest {
 | 
			
		||||
    public void setEquivalenceState(RequestState equivalenceState) {
 | 
			
		||||
        this.equivalenceState = equivalenceState;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getAdmissionDocUrl() {
 | 
			
		||||
        return admissionDocUrl;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAdmissionDocUrl(String admissionDocUrl) {
 | 
			
		||||
        this.admissionDocUrl = admissionDocUrl;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -12,7 +12,6 @@ public class Payment {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private long id;
 | 
			
		||||
 | 
			
		||||
    private long studentRegNo;
 | 
			
		||||
    private String card;
 | 
			
		||||
    private String client;
 | 
			
		||||
 | 
			
		||||
@ -1,81 +0,0 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables.Inscription;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
import org.hibernate.annotations.OnDelete;
 | 
			
		||||
import org.hibernate.annotations.OnDeleteAction;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Curriculum;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.RequestState;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class ReInscriptionRequest {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private int id;
 | 
			
		||||
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name = "Users")
 | 
			
		||||
    @OnDelete(action = OnDeleteAction.CASCADE)
 | 
			
		||||
    private User user;
 | 
			
		||||
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name = "Curriculum")
 | 
			
		||||
    @OnDelete(action = OnDeleteAction.CASCADE)
 | 
			
		||||
    private Curriculum newCurriculum;
 | 
			
		||||
    private RequestState state;
 | 
			
		||||
 | 
			
		||||
    //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
 | 
			
		||||
    private boolean type = false;
 | 
			
		||||
 | 
			
		||||
    public ReInscriptionRequest(){}
 | 
			
		||||
 | 
			
		||||
    public ReInscriptionRequest(User user, Curriculum newCurriculum, RequestState state, boolean type){
 | 
			
		||||
        this.user = user;
 | 
			
		||||
        this.newCurriculum = newCurriculum;
 | 
			
		||||
        this.state = state;
 | 
			
		||||
        this.type = type;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ReInscriptionRequest(User user, Curriculum newCurriculum, RequestState state){
 | 
			
		||||
        this.user = user;
 | 
			
		||||
        this.newCurriculum = newCurriculum;
 | 
			
		||||
        this.state = state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getId() {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public User getUser() {
 | 
			
		||||
        return user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setUser(User user) {
 | 
			
		||||
        this.user = user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Curriculum getNewCurriculum() {
 | 
			
		||||
        return newCurriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setNewCurriculum(Curriculum newCurriculum) {
 | 
			
		||||
        this.newCurriculum = newCurriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public RequestState getState() {
 | 
			
		||||
        return state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setState(RequestState state) {
 | 
			
		||||
        this.state = state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isType() {
 | 
			
		||||
        return type;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setType(boolean type) {
 | 
			
		||||
        this.type = type;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -7,15 +7,16 @@ import ovh.herisson.Clyde.Tables.RequestState;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class ScholarshipRequest {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private long id;
 | 
			
		||||
 | 
			
		||||
    @JoinColumn(name="Users")
 | 
			
		||||
    @ManyToOne(fetch = FetchType.EAGER)
 | 
			
		||||
    @OnDelete(action = OnDeleteAction.CASCADE)
 | 
			
		||||
    private User user;
 | 
			
		||||
    private RequestState state;
 | 
			
		||||
    private Date date;
 | 
			
		||||
 | 
			
		||||
@ -1,67 +0,0 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables.Inscription;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.RequestState;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class UninscriptionRequest {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private long id;
 | 
			
		||||
    private RequestState state;
 | 
			
		||||
    private String reason;
 | 
			
		||||
    private Date date;
 | 
			
		||||
 | 
			
		||||
    @JoinColumn(name = "Users")
 | 
			
		||||
    @ManyToOne(fetch = FetchType.EAGER)
 | 
			
		||||
    private User user;
 | 
			
		||||
 | 
			
		||||
    public UninscriptionRequest(RequestState state,String reason, Date date, User user){
 | 
			
		||||
        this.state = state;
 | 
			
		||||
        this.reason = reason;
 | 
			
		||||
        this.date = date;
 | 
			
		||||
        this.user = user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public UninscriptionRequest(){}
 | 
			
		||||
 | 
			
		||||
    public RequestState getState() {
 | 
			
		||||
        return state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setState(RequestState state) {
 | 
			
		||||
        this.state = state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getReason() {
 | 
			
		||||
        return reason;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setReason(String reason) {
 | 
			
		||||
        this.reason = reason;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public long getId() {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public User getUser() {
 | 
			
		||||
        return user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setUser(User user) {
 | 
			
		||||
        this.user = user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setDate(Date date) {
 | 
			
		||||
        this.date = date;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Date getDate() {
 | 
			
		||||
        return date;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,115 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables.Inscription;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Curriculum;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.RequestState;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class UnregisterRequest {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private long id;
 | 
			
		||||
    private RequestState state;
 | 
			
		||||
    private String reason;
 | 
			
		||||
    private Date date;
 | 
			
		||||
 | 
			
		||||
    //We store these informations again so if the user is deleted we still have the informations for history
 | 
			
		||||
    private long regNo;
 | 
			
		||||
 | 
			
		||||
    private String firstName;
 | 
			
		||||
 | 
			
		||||
    private String lastName;
 | 
			
		||||
 | 
			
		||||
    private String email;
 | 
			
		||||
 | 
			
		||||
    //Null if the user unregister for the academic year, contains a curriculum if the user wants to unregister from a specific curriculum
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name = "Curriculum")
 | 
			
		||||
    private Curriculum curriculum;
 | 
			
		||||
 | 
			
		||||
    public UnregisterRequest(RequestState state, String reason, Date date, long regNo, String firstName, String lastName, String email, Curriculum curriculum){
 | 
			
		||||
        this.state = state;
 | 
			
		||||
        this.reason = reason;
 | 
			
		||||
        this.date = date;
 | 
			
		||||
        this.regNo = regNo;
 | 
			
		||||
        this.firstName = firstName;
 | 
			
		||||
        this.lastName = lastName;
 | 
			
		||||
        this.email = email;
 | 
			
		||||
        this.curriculum = curriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public UnregisterRequest(){}
 | 
			
		||||
 | 
			
		||||
    public RequestState getState() {
 | 
			
		||||
        return state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setState(RequestState state) {
 | 
			
		||||
        this.state = state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getReason() {
 | 
			
		||||
        return reason;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setReason(String reason) {
 | 
			
		||||
        this.reason = reason;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public long getId() {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setDate(Date date) {
 | 
			
		||||
        this.date = date;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Date getDate() {
 | 
			
		||||
        return date;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getEmail() {
 | 
			
		||||
        return email;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getLastName() {
 | 
			
		||||
        return lastName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getFirstName() {
 | 
			
		||||
        return firstName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setEmail(String email) {
 | 
			
		||||
        this.email = email;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setLastName(String lastName) {
 | 
			
		||||
        this.lastName = lastName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setFirstName(String firstName) {
 | 
			
		||||
        this.firstName = firstName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setRegNo(long regNo) {
 | 
			
		||||
        this.regNo = regNo;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public long getRegNo() {
 | 
			
		||||
        return regNo;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCurriculum(Curriculum curriculum) {
 | 
			
		||||
        this.curriculum = curriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Curriculum getCurriculum() {
 | 
			
		||||
        return curriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,29 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables.Msg;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
 | 
			
		||||
import org.hibernate.annotations.CreationTimestamp;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
@Data
 | 
			
		||||
public class Answer {
 | 
			
		||||
	@Id
 | 
			
		||||
	@GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
	private int id;
 | 
			
		||||
 | 
			
		||||
	@CreationTimestamp
 | 
			
		||||
	private Date creation;
 | 
			
		||||
 | 
			
		||||
	private String content;
 | 
			
		||||
 | 
			
		||||
	@ManyToOne(cascade=CascadeType.ALL)
 | 
			
		||||
	private User author;
 | 
			
		||||
 | 
			
		||||
	private boolean anonymous;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,35 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables.Msg;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Course;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
@Data
 | 
			
		||||
public class Forum {
 | 
			
		||||
 | 
			
		||||
	@Id
 | 
			
		||||
	@GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
	private int id;
 | 
			
		||||
 | 
			
		||||
	@ManyToOne
 | 
			
		||||
	private Course course;
 | 
			
		||||
 | 
			
		||||
	private String name;
 | 
			
		||||
 | 
			
		||||
	@OneToMany(cascade = CascadeType.ALL)
 | 
			
		||||
	private List<Topic> topics;
 | 
			
		||||
 | 
			
		||||
    public void addTopic(Topic t) {
 | 
			
		||||
		topics.add(t);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @OneToMany
 | 
			
		||||
	private List<User> writers; // User who are authorized to create a post
 | 
			
		||||
 | 
			
		||||
	@OneToMany
 | 
			
		||||
	private List<User> register;
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,31 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables.Msg;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
@Data
 | 
			
		||||
public class Topic {
 | 
			
		||||
 | 
			
		||||
	@Id
 | 
			
		||||
	@GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
	private int id;
 | 
			
		||||
 | 
			
		||||
	private String subject, content;
 | 
			
		||||
 | 
			
		||||
	@ManyToOne
 | 
			
		||||
	private User author;
 | 
			
		||||
	
 | 
			
		||||
	@OneToMany(cascade = CascadeType.ALL)
 | 
			
		||||
	private List<Answer> answers;
 | 
			
		||||
 | 
			
		||||
	public void addAnswer(Answer a){
 | 
			
		||||
		answers.add(a);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private boolean locked; // true if new messages can be posted
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,46 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
 | 
			
		||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
 | 
			
		||||
import org.hibernate.id.IdentifierGenerator;
 | 
			
		||||
 | 
			
		||||
import java.sql.*;
 | 
			
		||||
import java.util.Calendar;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.GregorianCalendar;
 | 
			
		||||
 | 
			
		||||
public class RegNoGenerator implements IdentifierGenerator {
 | 
			
		||||
    private static int count = 0;
 | 
			
		||||
    @Override
 | 
			
		||||
    public Object generate(SharedSessionContractImplementor session, Object object) {
 | 
			
		||||
        try{
 | 
			
		||||
            JdbcConnectionAccess jdbccon = session.getJdbcConnectionAccess();
 | 
			
		||||
            Connection conn = jdbccon.obtainConnection();
 | 
			
		||||
 | 
			
		||||
            Statement statement = conn.createStatement();
 | 
			
		||||
 | 
			
		||||
            Calendar c = new GregorianCalendar();
 | 
			
		||||
            int y = c.get(Calendar.YEAR);
 | 
			
		||||
            String query = "select count(reg_no) + "+count+" from Users where reg_no/10000 = " + y%1000;
 | 
			
		||||
 | 
			
		||||
            ResultSet set = statement.executeQuery(query);
 | 
			
		||||
            long resp = 0;
 | 
			
		||||
            if(set.next()){
 | 
			
		||||
                resp = set.getLong(1)+((y%1000)*10000);
 | 
			
		||||
                count += 1;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            conn.close();
 | 
			
		||||
            statement.close();
 | 
			
		||||
 | 
			
		||||
            return resp;
 | 
			
		||||
 | 
			
		||||
        } catch (SQLException e) {
 | 
			
		||||
            throw new RuntimeException(e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void resetCount(){
 | 
			
		||||
        count = 0;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,8 +1,12 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonIgnore;
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import lombok.NoArgsConstructor;
 | 
			
		||||
import org.hibernate.annotations.OnDelete;
 | 
			
		||||
import org.hibernate.annotations.OnDeleteAction;
 | 
			
		||||
import org.hibernate.annotations.GenericGenerator;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Msg.Discussion;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Msg.Message;
 | 
			
		||||
 | 
			
		||||
@ -11,14 +15,14 @@ import java.util.List;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonIgnore;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
@Table(name = "Users")
 | 
			
		||||
@NoArgsConstructor
 | 
			
		||||
@Data
 | 
			
		||||
public class User {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    @GenericGenerator(name = "userGen", type = ovh.herisson.Clyde.Tables.RegNoGenerator.class)
 | 
			
		||||
    @GeneratedValue(generator = "userGen")
 | 
			
		||||
    private Long regNo;
 | 
			
		||||
    private String lastName;
 | 
			
		||||
    private String firstName;
 | 
			
		||||
 | 
			
		||||
@ -1,10 +1,17 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
import lombok.AllArgsConstructor;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import lombok.NoArgsConstructor;
 | 
			
		||||
 | 
			
		||||
import org.hibernate.annotations.OnDelete;
 | 
			
		||||
import org.hibernate.annotations.OnDeleteAction;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
@Data
 | 
			
		||||
@AllArgsConstructor
 | 
			
		||||
@NoArgsConstructor
 | 
			
		||||
public class UserCurriculum {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
@ -23,39 +30,13 @@ public class UserCurriculum {
 | 
			
		||||
 | 
			
		||||
    private int year;
 | 
			
		||||
 | 
			
		||||
    public UserCurriculum(User user, Curriculum curriculum, int year){
 | 
			
		||||
        this.user = user;
 | 
			
		||||
        this.curriculum = curriculum;
 | 
			
		||||
        this.year = year;
 | 
			
		||||
    }
 | 
			
		||||
    //True if the user has that curriculum at the moment false if not
 | 
			
		||||
    private boolean actual;
 | 
			
		||||
 | 
			
		||||
    public UserCurriculum() {}
 | 
			
		||||
 | 
			
		||||
    public int getId() {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public User getUser() {
 | 
			
		||||
        return user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setUser(User user) {
 | 
			
		||||
        this.user = user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Curriculum getCurriculum() {
 | 
			
		||||
        return curriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCurriculum(Curriculum curriculum) {
 | 
			
		||||
        this.curriculum = curriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getYear() {
 | 
			
		||||
        return year;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setYear(int year) {
 | 
			
		||||
        this.year = year;
 | 
			
		||||
    }
 | 
			
		||||
	public UserCurriculum(User u, Curriculum cu, int year, boolean actual){
 | 
			
		||||
		this.user = u;
 | 
			
		||||
		this.curriculum = cu;
 | 
			
		||||
		this.year = year;
 | 
			
		||||
		this.actual = actual;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user