Merge branch 'master' into Leo/Backend/UnitTest
This commit is contained in:
		@ -0,0 +1,70 @@
 | 
			
		||||
package ovh.herisson.Clyde.EndPoints;
 | 
			
		||||
 | 
			
		||||
import org.springframework.http.HttpStatus;
 | 
			
		||||
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.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 ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
 | 
			
		||||
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){
 | 
			
		||||
        ArrayList<Applications> authorizedApps = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
        authorizedApps.add(Applications.Login);
 | 
			
		||||
        authorizedApps.add(Applications.Profile);
 | 
			
		||||
 | 
			
		||||
		User user = authServ.getUserFromToken(token);
 | 
			
		||||
		if(user == null)
 | 
			
		||||
			return authorizedApps;
 | 
			
		||||
 | 
			
		||||
		Role posterRole = user.getRole();
 | 
			
		||||
 | 
			
		||||
        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,80 @@
 | 
			
		||||
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.CourseService;
 | 
			
		||||
import ovh.herisson.Clyde.Services.TeacherCourseService;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Course;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Role;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.TeacherCourse;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
 | 
			
		||||
public class CourseController {
 | 
			
		||||
 | 
			
		||||
    private final CourseService courseServ;
 | 
			
		||||
 | 
			
		||||
    private final TeacherCourseService teacherCourseServ;
 | 
			
		||||
 | 
			
		||||
    private final AuthenticatorService authServ;
 | 
			
		||||
 | 
			
		||||
    public CourseController(CourseService courseServ, TeacherCourseService teacherCourseServ, AuthenticatorService authServ) {
 | 
			
		||||
        this.courseServ = courseServ;
 | 
			
		||||
        this.teacherCourseServ = teacherCourseServ;
 | 
			
		||||
        this.authServ = authServ;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/course/{id}")
 | 
			
		||||
    public ResponseEntity<Course> getCourse(@RequestHeader("Authorization") String token, @PathVariable long id){
 | 
			
		||||
        if (authServ.getUserFromToken(token) == null)
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        return new ResponseEntity<>(courseServ.findById(id), HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/course")
 | 
			
		||||
    public ResponseEntity<Course> postCourse(@RequestHeader("Authorization") String token, @RequestBody Course course){
 | 
			
		||||
        if (authServ.isNotSecretaryOrAdmin(token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        return new ResponseEntity<>(courseServ.save(course), HttpStatus.CREATED);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @PatchMapping("/course/{id}")
 | 
			
		||||
    public ResponseEntity<Course> patchCourse(@RequestHeader("Authorization") String token,
 | 
			
		||||
                                              @RequestBody Map<String,Object> updates,
 | 
			
		||||
                                              @PathVariable long id)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        if (authServ.IsNotIn(new Role[]{Role.Admin,Role.Teacher,Role.Secretary}, token)){
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new ResponseEntity<>(courseServ.modifyData(id, updates, authServ.getUserFromToken(token).getRole()), HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/course/{id}")
 | 
			
		||||
    public ResponseEntity<String> postTeachers(@RequestHeader("Authorization") String token,
 | 
			
		||||
                                               @RequestBody Iterable<Long> teacherIds,
 | 
			
		||||
                                               @PathVariable Long id)
 | 
			
		||||
    {
 | 
			
		||||
        if (authServ.IsNotIn(new Role[]{Role.Admin,Role.Secretary}, token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        teacherCourseServ.saveAll(teacherIds,courseServ.findById(id));
 | 
			
		||||
        return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,60 @@
 | 
			
		||||
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
 | 
			
		||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
 | 
			
		||||
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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**@PostMapping("/curriculum") //todo now
 | 
			
		||||
    public ResponseEntity<String> postCurriculum(@RequestHeader("Authorization") String token,@RequestBody Curriculum curriculum){
 | 
			
		||||
 | 
			
		||||
        if (!isSecretaryOrAdmin(token)){
 | 
			
		||||
            return new UnauthorizedResponse<>("you're not allowed to post a Curriculum");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        CurriculumServ.save(Curriculum);
 | 
			
		||||
 | 
			
		||||
        return new ResponseEntity<>("created !",HttpStatus.CREATED);
 | 
			
		||||
    }**/
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,86 @@
 | 
			
		||||
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.InscriptionService;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.RequestState;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Role;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
 | 
			
		||||
 | 
			
		||||
public class InscriptionController {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private final InscriptionService inscriptionServ;
 | 
			
		||||
    private final AuthenticatorService authServ;
 | 
			
		||||
 | 
			
		||||
    public InscriptionController(InscriptionService inscriptionServ, AuthenticatorService authServ){
 | 
			
		||||
        this.inscriptionServ = inscriptionServ;
 | 
			
		||||
        this.authServ = authServ;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/requests/register")
 | 
			
		||||
    public ResponseEntity<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){
 | 
			
		||||
 | 
			
		||||
        if (authServ.isNotSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);}
 | 
			
		||||
 | 
			
		||||
        Iterable<InscriptionRequest> inscriptionRequests = inscriptionServ.getAll();
 | 
			
		||||
        ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
        for (InscriptionRequest i:inscriptionRequests){
 | 
			
		||||
            toReturn.add(requestWithoutPassword(i));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new ResponseEntity<>(toReturn, HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/request/register/{id}")
 | 
			
		||||
    public ResponseEntity<Map<String,Object>> getById(@PathVariable long id){
 | 
			
		||||
        InscriptionRequest inscriptionRequest = inscriptionServ.getById(id);
 | 
			
		||||
        if (inscriptionRequest == null) {return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);}
 | 
			
		||||
 | 
			
		||||
        return new ResponseEntity<>(requestWithoutPassword(inscriptionRequest), HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("request/user/{id}")
 | 
			
		||||
    public ResponseEntity<InscriptionRequest> getUserInscriptionRequest(@PathVariable long id, @RequestHeader("Authorize") String token){
 | 
			
		||||
        //todo return l'inscriptionRequest ACTUELLE du user (check si le poster est bien le même que id target ou secretariat)
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PatchMapping("/request/register/{id}")
 | 
			
		||||
    public ResponseEntity<InscriptionRequest> changeRequestState(@PathVariable long id,
 | 
			
		||||
                                                                 @RequestHeader("Authorize") String token,
 | 
			
		||||
                                                                 @RequestBody RequestState requestState)
 | 
			
		||||
    {
 | 
			
		||||
        if (authServ.isNotSecretaryOrAdmin(token)) return new UnauthorizedResponse<>(null);
 | 
			
		||||
        inscriptionServ.modifyState(id, requestState);
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Map<String, Object> requestWithoutPassword(InscriptionRequest inscriptionRequest) {
 | 
			
		||||
        Map<String, Object> toReturn = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
        toReturn.put("id", inscriptionRequest.getId());
 | 
			
		||||
        toReturn.put("firstName", inscriptionRequest.getFirstName());
 | 
			
		||||
        toReturn.put("lastName", inscriptionRequest.getLastName());
 | 
			
		||||
        toReturn.put("address", inscriptionRequest.getAddress());
 | 
			
		||||
        toReturn.put("birthDate", inscriptionRequest.getBirthDate());
 | 
			
		||||
        toReturn.put("country", inscriptionRequest.getCountry());
 | 
			
		||||
        toReturn.put("curriculum", inscriptionRequest.getCurriculum());
 | 
			
		||||
        toReturn.put("profilePictureUrl", inscriptionRequest.getProfilePicture());
 | 
			
		||||
        toReturn.put("state", inscriptionRequest.getState());
 | 
			
		||||
        return toReturn;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,10 +1,12 @@
 | 
			
		||||
package ovh.herisson.Clyde.EndPoints;
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonFormat;
 | 
			
		||||
import org.springframework.http.HttpHeaders;
 | 
			
		||||
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.Tables.InscriptionRequest;
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
 | 
			
		||||
@ -28,6 +30,7 @@ public class LoginController {
 | 
			
		||||
    public LoginController(AuthenticatorService authServ){
 | 
			
		||||
        this.authServ = authServ;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping(value = "/login")
 | 
			
		||||
    public ResponseEntity<String> login(@RequestBody RequestLogin requestLogin){
 | 
			
		||||
 | 
			
		||||
@ -40,6 +43,10 @@ public class LoginController {
 | 
			
		||||
        responseHeaders.set("Set-Cookie",String.format("session_token=%s",sessionToken));
 | 
			
		||||
        return ResponseEntity.ok().headers(responseHeaders).build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/request/register")
 | 
			
		||||
    public ResponseEntity<String> register(@RequestBody InscriptionRequest inscriptionRequest){
 | 
			
		||||
        authServ.register(inscriptionRequest);
 | 
			
		||||
        return new ResponseEntity<>("Is OK", HttpStatus.CREATED);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.TokenRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.UserRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Services.TokenService;
 | 
			
		||||
import ovh.herisson.Clyde.Services.*;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.*;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
@ -20,14 +20,19 @@ public class MockController {
 | 
			
		||||
    public final UserRepository userRepo;
 | 
			
		||||
    public final TokenRepository tokenRepo;
 | 
			
		||||
    public final TokenService tokenService;
 | 
			
		||||
 | 
			
		||||
    public final CurriculumCourseService CurriculumCourseService;
 | 
			
		||||
    public final CurriculumService curriculumService;
 | 
			
		||||
    public final CourseService courseService;
 | 
			
		||||
    ArrayList<User> mockUsers;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService){
 | 
			
		||||
    public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService){
 | 
			
		||||
        this.tokenRepo = tokenRepo;
 | 
			
		||||
        this.userRepo = userRepo;
 | 
			
		||||
        this.tokenService = tokenService;
 | 
			
		||||
        this.CurriculumCourseService = CurriculumCourseService;
 | 
			
		||||
        this.curriculumService = curriculumService;
 | 
			
		||||
        this.courseService = courseService;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** Saves an example of each user type by :
 | 
			
		||||
@ -39,13 +44,53 @@ public class MockController {
 | 
			
		||||
    @PostMapping("/mock")
 | 
			
		||||
    public void postMock(){
 | 
			
		||||
 | 
			
		||||
        // user part
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand",new Date(0), null,Role.Admin,passwordEncoder.encode("admin"));
 | 
			
		||||
        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.Teacher,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"));
 | 
			
		||||
        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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        // Course / Curriculum part
 | 
			
		||||
 | 
			
		||||
        Curriculum infoBab1 = new Curriculum(1,"info");
 | 
			
		||||
        Curriculum chemistryBab1 = new Curriculum(1,"chemistry");
 | 
			
		||||
        Curriculum psychologyBab1 = new Curriculum(1,"psychology");
 | 
			
		||||
 | 
			
		||||
        curriculumService.save(infoBab1);
 | 
			
		||||
        curriculumService.save(chemistryBab1);
 | 
			
		||||
        curriculumService.save(psychologyBab1);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        Course progra1 = new Course(5,"Programmation et algorithimque 1",joke);
 | 
			
		||||
        Course chemistry1 = new Course(12, "Thermochimie",joke);
 | 
			
		||||
        Course psycho1 = new Course(21, "rien faire t'as cru c'est psycho",joke);
 | 
			
		||||
        Course commun = new Course(2, "cours commun",joke);
 | 
			
		||||
 | 
			
		||||
        courseService.save(progra1);
 | 
			
		||||
        courseService.save(chemistry1);
 | 
			
		||||
        courseService.save(psycho1);
 | 
			
		||||
        courseService.save(commun);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        CurriculumCourseService.save(new CurriculumCourse(infoBab1,progra1));
 | 
			
		||||
        CurriculumCourseService.save(new CurriculumCourse(infoBab1,commun));
 | 
			
		||||
 | 
			
		||||
        CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,psycho1));
 | 
			
		||||
        CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,commun));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,commun));
 | 
			
		||||
        CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,chemistry1));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @DeleteMapping("/mock")
 | 
			
		||||
 | 
			
		||||
@ -1,10 +1,7 @@
 | 
			
		||||
package ovh.herisson.Clyde.EndPoints;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import jakarta.servlet.http.HttpServletRequest;
 | 
			
		||||
import org.springframework.http.HttpStatus;
 | 
			
		||||
 | 
			
		||||
import org.springframework.http.MediaType;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
 | 
			
		||||
@ -13,7 +10,7 @@ import ovh.herisson.Clyde.Services.UserService;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Role;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.security.Key;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
@ -43,7 +40,7 @@ public class UserController {
 | 
			
		||||
    @PostMapping("/user")
 | 
			
		||||
    public ResponseEntity<String> postUser(@RequestBody User user,@RequestHeader("Authorization") String authorization){
 | 
			
		||||
 | 
			
		||||
        if (!isSecretaryOrAdmin(authorization))
 | 
			
		||||
        if (authServ.isNotSecretaryOrAdmin(authorization))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        userService.save(user);
 | 
			
		||||
@ -53,7 +50,7 @@ public class UserController {
 | 
			
		||||
    @GetMapping("/users")
 | 
			
		||||
    public ResponseEntity<Iterable<HashMap<String,Object>>> getAllUsers(@RequestHeader("Authorization") String authorization){
 | 
			
		||||
 | 
			
		||||
        if (!isSecretaryOrAdmin(authorization))
 | 
			
		||||
        if (authServ.isNotSecretaryOrAdmin(authorization))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        Iterable<User> users = userService.getAll();
 | 
			
		||||
@ -78,6 +75,21 @@ public class UserController {
 | 
			
		||||
        return new ResponseEntity<>("data modified", HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/teachers")
 | 
			
		||||
    public ResponseEntity<Iterable<HashMap<String,Object>>> getAllTeachers(@RequestHeader("Authorization") String token){
 | 
			
		||||
        if (authServ.getUserFromToken(token) == null)
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
        Iterable<User> teachers = userService.getAllTeachers();
 | 
			
		||||
        ArrayList<HashMap<String, Object>> withoutPassword = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
        for (User t: teachers){
 | 
			
		||||
            withoutPassword.add(userWithoutPassword(t));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new ResponseEntity<>(withoutPassword, HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        /** return user's data except password
 | 
			
		||||
         * @param user the user to return
 | 
			
		||||
@ -85,7 +97,6 @@ public class UserController {
 | 
			
		||||
         */
 | 
			
		||||
    private HashMap<String,Object> userWithoutPassword(User user){
 | 
			
		||||
        HashMap<String,Object> toReturn = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
        toReturn.put("regNo",user.getRegNo());
 | 
			
		||||
        toReturn.put("firstName",user.getFirstName());
 | 
			
		||||
        toReturn.put("lastName",user.getLastName());
 | 
			
		||||
@ -93,18 +104,7 @@ public class UserController {
 | 
			
		||||
        toReturn.put("country",user.getCountry());
 | 
			
		||||
        toReturn.put("address",user.getAddress());
 | 
			
		||||
        toReturn.put("role",user.getRole());
 | 
			
		||||
 | 
			
		||||
        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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,8 @@
 | 
			
		||||
package ovh.herisson.Clyde.Repositories;
 | 
			
		||||
 | 
			
		||||
import org.springframework.data.repository.CrudRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Course;
 | 
			
		||||
 | 
			
		||||
public interface CourseRepository extends CrudRepository<Course,Long> {
 | 
			
		||||
    Course findById(long id);
 | 
			
		||||
}
 | 
			
		||||
@ -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);
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,10 @@
 | 
			
		||||
package ovh.herisson.Clyde.Repositories;
 | 
			
		||||
 | 
			
		||||
import org.springframework.data.repository.CrudRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public interface InscriptionRepository extends CrudRepository<InscriptionRequest,Long> {
 | 
			
		||||
 | 
			
		||||
    InscriptionRequest findById(long aLong);
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,8 @@
 | 
			
		||||
package ovh.herisson.Clyde.Repositories;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import org.springframework.data.repository.CrudRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.TeacherCourse;
 | 
			
		||||
 | 
			
		||||
public interface TeacherCourseRepository extends CrudRepository<TeacherCourse, Long> {
 | 
			
		||||
}
 | 
			
		||||
@ -15,4 +15,8 @@ public interface UserRepository extends CrudRepository<User, Long> {
 | 
			
		||||
    /**
 | 
			
		||||
    @Query(value = "select a.* from Users a ",nativeQuery = true)
 | 
			
		||||
    Iterable<User> findAllUsers();**/
 | 
			
		||||
 | 
			
		||||
    @Query("select u from User u where u.role = ovh.herisson.Clyde.Tables.Role.Teacher")
 | 
			
		||||
    Iterable<User> findAllTeachers();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -1,6 +1,8 @@
 | 
			
		||||
package ovh.herisson.Clyde.Services;
 | 
			
		||||
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Role;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Token;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
@ -11,10 +13,12 @@ public class AuthenticatorService {
 | 
			
		||||
 | 
			
		||||
    private final TokenService tokenService;
 | 
			
		||||
    private final UserService userService;
 | 
			
		||||
    private final InscriptionService inscriptionService;
 | 
			
		||||
 | 
			
		||||
    public AuthenticatorService(TokenService tokenService, UserService userService){
 | 
			
		||||
    public AuthenticatorService(TokenService tokenService, UserService userService, InscriptionService inscriptionService){
 | 
			
		||||
        this.tokenService = tokenService;
 | 
			
		||||
        this.userService = userService;
 | 
			
		||||
        this.inscriptionService = inscriptionService;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public User getUserFromToken(String token){
 | 
			
		||||
@ -30,4 +34,34 @@ public class AuthenticatorService {
 | 
			
		||||
        tokenService.saveToken(new Token(user, token,expirationDate));
 | 
			
		||||
        return token;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void register(InscriptionRequest 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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean IsNotIn(Role[] roles, String token){
 | 
			
		||||
        if (token == null)
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        User poster = getUserFromToken(token);
 | 
			
		||||
        if (poster == null) return true;
 | 
			
		||||
 | 
			
		||||
        for (Role r:roles){
 | 
			
		||||
            if (poster.getRole() == r)
 | 
			
		||||
                return false;
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,55 @@
 | 
			
		||||
package ovh.herisson.Clyde.Services;
 | 
			
		||||
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Course;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Role;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
public class CourseService {
 | 
			
		||||
 | 
			
		||||
    private final CourseRepository courseRepo;
 | 
			
		||||
 | 
			
		||||
    public CourseService(CourseRepository courseRepo) {
 | 
			
		||||
        this.courseRepo = courseRepo;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Course save(Course course){
 | 
			
		||||
        return courseRepo.save(course);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Course findById(long id){
 | 
			
		||||
        return courseRepo.findById(id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Course modifyData(long id, Map<String, Object> updates, Role role) {
 | 
			
		||||
        Course target = courseRepo.findById(id);
 | 
			
		||||
 | 
			
		||||
        if (role == Role.Teacher){
 | 
			
		||||
            for (Map.Entry<String, Object> entry : updates.entrySet()){
 | 
			
		||||
                if (entry.getKey().equals("title")){
 | 
			
		||||
                    target.setTitle((String) entry.getValue());
 | 
			
		||||
                    return courseRepo.save(target);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        for (Map.Entry<String ,Object> entry: updates.entrySet()){
 | 
			
		||||
            switch (entry.getKey()){
 | 
			
		||||
                case "title":
 | 
			
		||||
                    target.setTitle((String) entry.getValue());
 | 
			
		||||
                    break;
 | 
			
		||||
                case "credits":
 | 
			
		||||
                    target.setCredits((Integer) entry.getValue());
 | 
			
		||||
                    break;
 | 
			
		||||
                case "owner":
 | 
			
		||||
                    target.setOwner((User) entry.getValue()); //todo check if is a teacher !
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return courseRepo.save(target);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -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();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,34 @@
 | 
			
		||||
package ovh.herisson.Clyde.Services;
 | 
			
		||||
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.InscriptionRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.RequestState;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
public class InscriptionService {
 | 
			
		||||
 | 
			
		||||
    InscriptionRepository inscriptionRepo;
 | 
			
		||||
 | 
			
		||||
    public InscriptionService(InscriptionRepository inscriptionRepo){
 | 
			
		||||
        this.inscriptionRepo = inscriptionRepo;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void save(InscriptionRequest inscriptionRequest){
 | 
			
		||||
        inscriptionRepo.save(inscriptionRequest);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public InscriptionRequest getById(long id){
 | 
			
		||||
        return inscriptionRepo.findById(id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Iterable<InscriptionRequest> getAll(){
 | 
			
		||||
        return inscriptionRepo.findAll();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void modifyState(long id, RequestState requestState) {
 | 
			
		||||
        InscriptionRequest inscriptionRequest = getById(id);
 | 
			
		||||
        inscriptionRequest.setState(requestState);
 | 
			
		||||
        save(inscriptionRequest);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -4,10 +4,8 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.springframework.web.multipart.MultipartFile;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.FileRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.*;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 | 
			
		||||
import java.nio.file.Files;
 | 
			
		||||
import java.nio.file.Path;
 | 
			
		||||
import java.nio.file.Paths;
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,39 @@
 | 
			
		||||
package ovh.herisson.Clyde.Services;
 | 
			
		||||
 | 
			
		||||
import org.springframework.stereotype.Controller;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.TeacherCourseRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.UserRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Course;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.TeacherCourse;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
@Controller
 | 
			
		||||
public class TeacherCourseService {
 | 
			
		||||
    private final TeacherCourseRepository teacherCourseRepo;
 | 
			
		||||
 | 
			
		||||
    private final UserRepository userRepo;
 | 
			
		||||
 | 
			
		||||
    public TeacherCourseService(TeacherCourseRepository teacherCourseRepo, UserRepository userRepo) {
 | 
			
		||||
        this.teacherCourseRepo = teacherCourseRepo;
 | 
			
		||||
        this.userRepo = userRepo;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean saveAll(Iterable<Long> teacherIds, Course course){
 | 
			
		||||
 | 
			
		||||
        ArrayList<Long> addedIds = new ArrayList<>();
 | 
			
		||||
        for (Long teacherId : teacherIds){
 | 
			
		||||
            User teacher = userRepo.findById((long) teacherId);
 | 
			
		||||
            if ( teacher== null){
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            if (!addedIds.contains(teacherId))
 | 
			
		||||
            {
 | 
			
		||||
                teacherCourseRepo.save(new TeacherCourse(teacher,course));
 | 
			
		||||
                addedIds.add(teacherId);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -5,16 +5,15 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.TokenRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Token;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
import java.io.UnsupportedEncodingException;
 | 
			
		||||
import java.security.SecureRandom;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Base64;
 | 
			
		||||
import java.util.Calendar;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
public class TokenService {
 | 
			
		||||
    TokenRepository tokenRepo;
 | 
			
		||||
    private final TokenRepository tokenRepo;
 | 
			
		||||
 | 
			
		||||
    public TokenService(TokenRepository tokenRepo){
 | 
			
		||||
        this.tokenRepo = tokenRepo;
 | 
			
		||||
@ -30,13 +29,10 @@ public class TokenService {
 | 
			
		||||
        new SecureRandom().nextBytes(bytes);
 | 
			
		||||
        for (int i = 0; i < bytes.length; i++) {
 | 
			
		||||
            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
 | 
			
		||||
        try {
 | 
			
		||||
            return new String(bytes,"ISO_8859_1");
 | 
			
		||||
            return new String(Base64.getEncoder().encode(bytes),"ISO_8859_1");
 | 
			
		||||
        } catch (UnsupportedEncodingException e) {
 | 
			
		||||
            throw new RuntimeException(e);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -102,4 +102,8 @@ public class UserService {
 | 
			
		||||
    public Iterable<User> getAll(){
 | 
			
		||||
        return userRepo.findAll();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public Iterable<User> getAllTeachers (){return userRepo.findAllTeachers();}
 | 
			
		||||
}
 | 
			
		||||
@ -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
 | 
			
		||||
}
 | 
			
		||||
@ -1,9 +1,6 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.Entity;
 | 
			
		||||
import jakarta.persistence.GeneratedValue;
 | 
			
		||||
import jakarta.persistence.GenerationType;
 | 
			
		||||
import jakarta.persistence.Id;
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class Course {
 | 
			
		||||
@ -12,12 +9,15 @@ public class Course {
 | 
			
		||||
    private int courseID;
 | 
			
		||||
    private int credits;
 | 
			
		||||
    private String title;
 | 
			
		||||
    private String faculty;
 | 
			
		||||
 | 
			
		||||
    public Course(int credits, String title, String faculty){
 | 
			
		||||
    @ManyToOne(fetch = FetchType.EAGER)
 | 
			
		||||
    @JoinColumn(name = "Users")
 | 
			
		||||
    private User owner;
 | 
			
		||||
 | 
			
		||||
    public Course(int credits, String title, User owner){
 | 
			
		||||
        this.credits = credits;
 | 
			
		||||
        this.title = title;
 | 
			
		||||
        this.faculty = faculty;
 | 
			
		||||
        this.owner = owner;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Course() {}
 | 
			
		||||
@ -34,14 +34,6 @@ public class Course {
 | 
			
		||||
        this.credits = credits;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getFaculty() {
 | 
			
		||||
        return faculty;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setFaculty(String faculty){
 | 
			
		||||
        this.faculty = faculty;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getTitle() {
 | 
			
		||||
        return title;
 | 
			
		||||
    }
 | 
			
		||||
@ -49,4 +41,12 @@ public class Course {
 | 
			
		||||
    public void setTitle(String title){
 | 
			
		||||
        this.title = title;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public User getOwner() {
 | 
			
		||||
        return owner;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setOwner(User owner) {
 | 
			
		||||
        this.owner = owner;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -6,22 +6,21 @@ import jakarta.persistence.GenerationType;
 | 
			
		||||
import jakarta.persistence.Id;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class Cursus {
 | 
			
		||||
public class Curriculum {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private int cursusId;
 | 
			
		||||
    private int curriculumId;
 | 
			
		||||
    private int year;
 | 
			
		||||
    private String option;
 | 
			
		||||
 | 
			
		||||
    public Cursus(int year, String option){
 | 
			
		||||
    public Curriculum(int year, String option){
 | 
			
		||||
        this.year = year;
 | 
			
		||||
        this.option = option;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Cursus() {}
 | 
			
		||||
    public Curriculum() {}
 | 
			
		||||
 | 
			
		||||
    public int getCursusId(){
 | 
			
		||||
        return this.cursusId;
 | 
			
		||||
    public int getCurriculumId(){
 | 
			
		||||
        return this.curriculumId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getYear(){
 | 
			
		||||
@ -0,0 +1,45 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class CurriculumCourse {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private int id;
 | 
			
		||||
 | 
			
		||||
    @ManyToOne(fetch = FetchType.EAGER)
 | 
			
		||||
    @JoinColumn(name = "Curriculum")
 | 
			
		||||
    private Curriculum curriculum;
 | 
			
		||||
 | 
			
		||||
    @ManyToOne(fetch = FetchType.EAGER)
 | 
			
		||||
    @JoinColumn(name = "Course")
 | 
			
		||||
    private Course course;
 | 
			
		||||
 | 
			
		||||
    public CurriculumCourse(Curriculum curriculum, Course course){
 | 
			
		||||
        this.curriculum = curriculum;
 | 
			
		||||
        this.course = course;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public CurriculumCourse() {}
 | 
			
		||||
 | 
			
		||||
    public int getId() {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Course getCourse() {
 | 
			
		||||
        return course;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCourse(Course course){
 | 
			
		||||
        this.course = course;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Curriculum getCurriculum() {
 | 
			
		||||
        return curriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCurriculum(Curriculum curriculum) {
 | 
			
		||||
        this.curriculum = curriculum;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,45 +0,0 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class CursusCourse {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private int id;
 | 
			
		||||
 | 
			
		||||
    @ManyToOne(fetch = FetchType.LAZY)
 | 
			
		||||
    @JoinColumn(name = "Cursus")
 | 
			
		||||
    private Cursus cursus;
 | 
			
		||||
 | 
			
		||||
    @ManyToOne(fetch = FetchType.LAZY)
 | 
			
		||||
    @JoinColumn(name = "Course")
 | 
			
		||||
    private Course course;
 | 
			
		||||
 | 
			
		||||
    public CursusCourse(Cursus cursus, Course course){
 | 
			
		||||
        this.cursus = cursus;
 | 
			
		||||
        this.course = course;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public CursusCourse() {}
 | 
			
		||||
 | 
			
		||||
    public int getId() {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Course getCourse() {
 | 
			
		||||
        return course;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCourse(Course course){
 | 
			
		||||
        this.course = course;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Cursus getCursus() {
 | 
			
		||||
        return cursus;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCursus(Cursus cursus) {
 | 
			
		||||
        this.cursus = cursus;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -12,25 +12,29 @@ public class InscriptionRequest {
 | 
			
		||||
    private int id;
 | 
			
		||||
    private String firstName;
 | 
			
		||||
    private String lastName;
 | 
			
		||||
    private String adress;
 | 
			
		||||
    private String address;
 | 
			
		||||
    private String email;
 | 
			
		||||
    private String country;
 | 
			
		||||
    private Date birthDate;
 | 
			
		||||
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name="Cursus")
 | 
			
		||||
    private Cursus cursus;
 | 
			
		||||
    @JoinColumn(name="Curriculum")
 | 
			
		||||
    private Curriculum curriculum;
 | 
			
		||||
    private RequestState state;
 | 
			
		||||
    private String profilePicture;
 | 
			
		||||
 | 
			
		||||
    private String password;
 | 
			
		||||
    public InscriptionRequest(){}
 | 
			
		||||
    public InscriptionRequest(String lastName, String firstName, String adress, String email, String country, Date birthDate, RequestState state, String profilePicture){
 | 
			
		||||
    public InscriptionRequest(String lastName, String firstName, String address, String email, String country, Date birthDate, RequestState state, String profilePicture, String password){
 | 
			
		||||
        this.lastName = lastName;
 | 
			
		||||
        this.firstName = firstName;
 | 
			
		||||
        this.adress = adress;
 | 
			
		||||
        this.address = address;
 | 
			
		||||
        this.email = email;
 | 
			
		||||
        this.country = country;
 | 
			
		||||
        this.birthDate = birthDate;
 | 
			
		||||
        this.state = state;
 | 
			
		||||
        this.profilePicture = profilePicture;
 | 
			
		||||
        this.password = password;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getId() {
 | 
			
		||||
@ -53,12 +57,12 @@ public class InscriptionRequest {
 | 
			
		||||
        this.lastName = lastName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getAdress() {
 | 
			
		||||
        return adress;
 | 
			
		||||
    public String getAddress() {
 | 
			
		||||
        return address;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAdress(String adress) {
 | 
			
		||||
        this.adress = adress;
 | 
			
		||||
    public void setAddress(String address) {
 | 
			
		||||
        this.address = address;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getEmail() {
 | 
			
		||||
@ -85,12 +89,12 @@ public class InscriptionRequest {
 | 
			
		||||
        this.birthDate = birthDate;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Cursus getCursus() {
 | 
			
		||||
        return cursus;
 | 
			
		||||
    public Curriculum getCurriculum() {
 | 
			
		||||
        return curriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCursus(Cursus cursus) {
 | 
			
		||||
        this.cursus = cursus;
 | 
			
		||||
    public void setCurriculum(Curriculum curriculum) {
 | 
			
		||||
        this.curriculum = curriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public RequestState getState() {
 | 
			
		||||
 | 
			
		||||
@ -1,39 +1,38 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.GeneratedValue;
 | 
			
		||||
import jakarta.persistence.GenerationType;
 | 
			
		||||
import jakarta.persistence.JoinColumn;
 | 
			
		||||
import jakarta.persistence.ManyToOne;
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class ReinscriptionRequest {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private int id;
 | 
			
		||||
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name = "User")
 | 
			
		||||
    @JoinColumn(name = "Users")
 | 
			
		||||
    private User user;
 | 
			
		||||
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name = "Cursus")
 | 
			
		||||
    private Cursus newCursus;
 | 
			
		||||
    @JoinColumn(name = "Curriculum")
 | 
			
		||||
    private Curriculum newCurriculum;
 | 
			
		||||
    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
 | 
			
		||||
    private boolean type = false;
 | 
			
		||||
 | 
			
		||||
    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.newCursus = newCursus;
 | 
			
		||||
        this.newCurriculum = newCurriculum;
 | 
			
		||||
        this.state = state;
 | 
			
		||||
        this.type = type;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ReinscriptionRequest(User user, Cursus newCursus, RequestState state){
 | 
			
		||||
    public ReinscriptionRequest(User user, Curriculum newCurriculum, RequestState state){
 | 
			
		||||
        this.user = user;
 | 
			
		||||
        this.newCursus = newCursus;
 | 
			
		||||
        this.newCurriculum = newCurriculum;
 | 
			
		||||
        this.state = state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -49,12 +48,12 @@ public class ReinscriptionRequest {
 | 
			
		||||
        this.user = user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Cursus getNewCursus() {
 | 
			
		||||
        return newCursus;
 | 
			
		||||
    public Curriculum getNewCurriculum() {
 | 
			
		||||
        return newCurriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setNewCursus(Cursus newCursus) {
 | 
			
		||||
        this.newCursus = newCursus;
 | 
			
		||||
    public void setNewCurriculum(Curriculum newCurriculum) {
 | 
			
		||||
        this.newCurriculum = newCurriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public RequestState getState() {
 | 
			
		||||
 | 
			
		||||
@ -3,5 +3,5 @@ package ovh.herisson.Clyde.Tables;
 | 
			
		||||
public enum RequestState {
 | 
			
		||||
    Accepted,
 | 
			
		||||
    Refused,
 | 
			
		||||
    Pending;
 | 
			
		||||
    Pending
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -5,5 +5,5 @@ public enum Role {
 | 
			
		||||
    Student,
 | 
			
		||||
    Admin,
 | 
			
		||||
    InscriptionService,
 | 
			
		||||
    Secretary;
 | 
			
		||||
}
 | 
			
		||||
    Secretary
 | 
			
		||||
}
 | 
			
		||||
@ -1,42 +0,0 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class Secretary {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private int id;
 | 
			
		||||
 | 
			
		||||
    @OneToOne(fetch = FetchType.LAZY)
 | 
			
		||||
    @JoinColumn(name = "Users")
 | 
			
		||||
    private User user;
 | 
			
		||||
    private String faculty;
 | 
			
		||||
 | 
			
		||||
    public Secretary(User user, String faculty){
 | 
			
		||||
        this.user = user;
 | 
			
		||||
        this.faculty = faculty;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Secretary() {}
 | 
			
		||||
 | 
			
		||||
    public int getId() {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public User getUser() {
 | 
			
		||||
        return user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setUser(User user) {
 | 
			
		||||
        this.user = user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getFaculty() {
 | 
			
		||||
        return faculty;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setFaculty(String faculty) {
 | 
			
		||||
        this.faculty = faculty;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -3,30 +3,26 @@ package ovh.herisson.Clyde.Tables;
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class TeacherGivenCourse {
 | 
			
		||||
public class TeacherCourse {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private int id;
 | 
			
		||||
 | 
			
		||||
    @ManyToOne(fetch = FetchType.LAZY)
 | 
			
		||||
    @ManyToOne(fetch = FetchType.EAGER)
 | 
			
		||||
    @JoinColumn(name = "Users")
 | 
			
		||||
    private User user;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @ManyToOne(fetch = FetchType.LAZY)
 | 
			
		||||
    @ManyToOne(fetch = FetchType.EAGER)
 | 
			
		||||
    @JoinColumn(name = "Course")
 | 
			
		||||
    private Course course;
 | 
			
		||||
 | 
			
		||||
    //This flag helps make the difference between an assistant or a Teacher (who owns the course)
 | 
			
		||||
    private boolean owned;
 | 
			
		||||
 | 
			
		||||
    public TeacherGivenCourse(User user, Course course, boolean owned){
 | 
			
		||||
    public TeacherCourse(User user, Course course){
 | 
			
		||||
        this.user = user;
 | 
			
		||||
        this.course = course;
 | 
			
		||||
        this.owned = owned;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TeacherGivenCourse() {}
 | 
			
		||||
    public TeacherCourse() {}
 | 
			
		||||
 | 
			
		||||
    public int getId() {
 | 
			
		||||
        return id;
 | 
			
		||||
@ -48,11 +44,4 @@ public class TeacherGivenCourse {
 | 
			
		||||
        this.course = course;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isOwned() {
 | 
			
		||||
        return owned;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setOwned(boolean owned) {
 | 
			
		||||
        this.owned = owned;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,46 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class UserCurriculum {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private int id;
 | 
			
		||||
 | 
			
		||||
    //Un étudiant peut avoir plusieurs curriculums
 | 
			
		||||
    @ManyToOne(fetch = FetchType.EAGER)
 | 
			
		||||
    @JoinColumn(name = "Users")
 | 
			
		||||
    private User user;
 | 
			
		||||
 | 
			
		||||
    @OneToOne(fetch = FetchType.EAGER)
 | 
			
		||||
    @JoinColumn(name = "Curriculum")
 | 
			
		||||
    private Curriculum curriculum;
 | 
			
		||||
 | 
			
		||||
    public UserCurriculum(User user, Curriculum curriculum){
 | 
			
		||||
        this.user = user;
 | 
			
		||||
        this.curriculum = curriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,46 +0,0 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class UserCursus {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private int id;
 | 
			
		||||
 | 
			
		||||
    //Un étudiant peut avoir plusieurs cursus
 | 
			
		||||
    @ManyToOne(fetch = FetchType.LAZY)
 | 
			
		||||
    @JoinColumn(name = "Users")
 | 
			
		||||
    private User user;
 | 
			
		||||
 | 
			
		||||
    @OneToOne(fetch = FetchType.LAZY)
 | 
			
		||||
    @JoinColumn(name = "Cursus")
 | 
			
		||||
    private Cursus cursus;
 | 
			
		||||
 | 
			
		||||
    public UserCursus(User user, Cursus cursus){
 | 
			
		||||
        this.user = user;
 | 
			
		||||
        this.cursus = cursus;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public UserCursus() {}
 | 
			
		||||
 | 
			
		||||
    public int getId() {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public User getUser() {
 | 
			
		||||
        return user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setUser(User user) {
 | 
			
		||||
        this.user = user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Cursus getCursus() {
 | 
			
		||||
        return cursus;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCursus(Cursus cursus) {
 | 
			
		||||
        this.cursus = cursus;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user