Merge branch 'master' into Max/Backend/BackendClean
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.*;
 | 
			
		||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
 | 
			
		||||
import ovh.herisson.Clyde.Services.CurriculumCourseService;
 | 
			
		||||
import ovh.herisson.Clyde.Services.CurriculumService;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Curriculum;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.CurriculumCourse;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Role;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
public class CurriculumController {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private final CurriculumService curriculumServ;
 | 
			
		||||
    private final AuthenticatorService authServ;
 | 
			
		||||
 | 
			
		||||
    private final CurriculumCourseService curriculumCourseServ;
 | 
			
		||||
 | 
			
		||||
    public CurriculumController(CurriculumService curriculumServ, AuthenticatorService authServ, CurriculumCourseService curriculumCourseServ){
 | 
			
		||||
        this.curriculumServ = curriculumServ;
 | 
			
		||||
        this.authServ = authServ;
 | 
			
		||||
        this.curriculumCourseServ = curriculumCourseServ;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/curriculum/{id}")
 | 
			
		||||
    public ResponseEntity<Curriculum> findById(@PathVariable long id){
 | 
			
		||||
        return new ResponseEntity<>(curriculumServ.findById(id), HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/curriculums")
 | 
			
		||||
    public ResponseEntity<Iterable<Map<String, Object>>> findAllindDepth(){
 | 
			
		||||
        return new ResponseEntity<>(curriculumCourseServ.getAllDepthCurriculum(),HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/curriculum")
 | 
			
		||||
    public ResponseEntity<Iterable<CurriculumCourse>> findAll(){
 | 
			
		||||
        return new ResponseEntity<>(curriculumCourseServ.findAll(),HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**@PostMapping("/curriculum")
 | 
			
		||||
    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);
 | 
			
		||||
    }**/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -7,6 +7,7 @@ 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;
 | 
			
		||||
@ -28,10 +29,10 @@ public class InscriptionController {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/inscriptionRequests")
 | 
			
		||||
    @GetMapping("/requests/register")
 | 
			
		||||
    public ResponseEntity<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){
 | 
			
		||||
 | 
			
		||||
        if (authServ.isNotSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);}
 | 
			
		||||
        if (!isSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);}
 | 
			
		||||
 | 
			
		||||
        Iterable<InscriptionRequest> inscriptionRequests = inscriptionServ.getAll();
 | 
			
		||||
        ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
 | 
			
		||||
@ -44,19 +45,31 @@ public class InscriptionController {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/inscriptionRequest/{id}")
 | 
			
		||||
    @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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Map<String,Object> requestWithoutPassword(InscriptionRequest inscriptionRequest) {
 | 
			
		||||
    @PatchMapping("/request/register/{id}")
 | 
			
		||||
    public ResponseEntity<InscriptionRequest> changeRequestState(@PathVariable long id,
 | 
			
		||||
                                                                 @RequestHeader("Authorize") String token,
 | 
			
		||||
                                                                 @RequestBody RequestState requestState)
 | 
			
		||||
    {
 | 
			
		||||
        if (!isSecretaryOrAdmin(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());
 | 
			
		||||
@ -65,9 +78,9 @@ public class InscriptionController {
 | 
			
		||||
        toReturn.put("address", inscriptionRequest.getAddress());
 | 
			
		||||
        toReturn.put("birthDate", inscriptionRequest.getBirthDate());
 | 
			
		||||
        toReturn.put("country", inscriptionRequest.getCountry());
 | 
			
		||||
        toReturn.put("cursus", inscriptionRequest.getCursus());
 | 
			
		||||
        toReturn.put("curriculum", inscriptionRequest.getCurriculum());
 | 
			
		||||
        toReturn.put("profilePictureUrl", inscriptionRequest.getProfilePicture());
 | 
			
		||||
        toReturn.put("state", inscriptionRequest.getState());
 | 
			
		||||
        return toReturn;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,19 +1,14 @@
 | 
			
		||||
package ovh.herisson.Clyde.EndPoints;
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonFormat;
 | 
			
		||||
import jakarta.persistence.Column;
 | 
			
		||||
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.Cursus;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.CursusType;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
 | 
			
		||||
@ -35,6 +30,7 @@ public class LoginController {
 | 
			
		||||
    public LoginController(AuthenticatorService authServ){
 | 
			
		||||
        this.authServ = authServ;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping(value = "/login")
 | 
			
		||||
    public ResponseEntity<String> login(@RequestBody RequestLogin requestLogin){
 | 
			
		||||
 | 
			
		||||
@ -48,12 +44,9 @@ public class LoginController {
 | 
			
		||||
        return ResponseEntity.ok().headers(responseHeaders).build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/register")
 | 
			
		||||
    @PostMapping("/request/register")
 | 
			
		||||
    public ResponseEntity<String> register(@RequestBody InscriptionRequest inscriptionRequest){
 | 
			
		||||
 | 
			
		||||
        authServ.register(inscriptionRequest);
 | 
			
		||||
        return new ResponseEntity<>("Is OK", HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -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,6 +44,9 @@ 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"));
 | 
			
		||||
@ -47,6 +55,42 @@ public class MockController {
 | 
			
		||||
        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","TODO DELETE");
 | 
			
		||||
        Course chemistry1 = new Course(12, "Thermochimie","TODO DELETE");
 | 
			
		||||
        Course psycho1 = new Course(21, "rien faire t'as cru c'est psycho", "TODO DELETE");
 | 
			
		||||
        Course commun = new Course(2, "cours commun","TODO DELETE");
 | 
			
		||||
 | 
			
		||||
        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;
 | 
			
		||||
@ -12,8 +9,6 @@ import ovh.herisson.Clyde.Services.AuthenticatorService;
 | 
			
		||||
import ovh.herisson.Clyde.Services.UserService;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Role;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
@ -77,8 +72,6 @@ public class UserController {
 | 
			
		||||
 | 
			
		||||
        return new ResponseEntity<>("data modified", HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        /** return user's data except password
 | 
			
		||||
         * @param user the user to return
 | 
			
		||||
         * @return all the user data without the password
 | 
			
		||||
 | 
			
		||||
@ -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,23 @@
 | 
			
		||||
package ovh.herisson.Clyde.Services;
 | 
			
		||||
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Course;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
public class CourseService {
 | 
			
		||||
 | 
			
		||||
    private final CourseRepository courseRepo;
 | 
			
		||||
 | 
			
		||||
    public CourseService(CourseRepository courseRepo) {
 | 
			
		||||
        this.courseRepo = courseRepo;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void save(Course course){
 | 
			
		||||
        courseRepo.save(course);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Course findById(long id){
 | 
			
		||||
        return courseRepo.findById(id);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -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();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -3,29 +3,32 @@ 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 {
 | 
			
		||||
 | 
			
		||||
    private final InscriptionRepository inscriptionRepo;
 | 
			
		||||
    public void save(InscriptionRequest inscriptionRequest){
 | 
			
		||||
        inscriptionRepo.save(inscriptionRequest);
 | 
			
		||||
    }
 | 
			
		||||
    InscriptionRepository inscriptionRepo;
 | 
			
		||||
 | 
			
		||||
    public InscriptionService(InscriptionRepository inscriptionRepo){
 | 
			
		||||
        this.inscriptionRepo = inscriptionRepo;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public InscriptionRequest getById(long id){
 | 
			
		||||
        InscriptionRequest inscriptionRequest = inscriptionRepo.findById(id);
 | 
			
		||||
    public void save(InscriptionRequest inscriptionRequest){
 | 
			
		||||
        inscriptionRepo.save(inscriptionRequest);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        if (inscriptionRequest == null){
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
        return 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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -8,6 +8,7 @@ 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;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
@ -28,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);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -6,28 +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 static Cursus infoBab1 = new Cursus(1,"info");
 | 
			
		||||
 | 
			
		||||
    public static Cursus chemistryBab1 = new Cursus(1,"chemistry");
 | 
			
		||||
 | 
			
		||||
    public static Cursus psychologyBab1 = new Cursus(1,"psychology");
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,8 +0,0 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
public enum CursusType {
 | 
			
		||||
 | 
			
		||||
    InfoBab1,
 | 
			
		||||
    ChemistryBab1,
 | 
			
		||||
    PsychologyBab1
 | 
			
		||||
}
 | 
			
		||||
@ -18,8 +18,8 @@ public class InscriptionRequest {
 | 
			
		||||
    private Date birthDate;
 | 
			
		||||
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name="Cursus")
 | 
			
		||||
    private Cursus cursus;
 | 
			
		||||
    @JoinColumn(name="Curriculum")
 | 
			
		||||
    private Curriculum curriculum;
 | 
			
		||||
    private RequestState state;
 | 
			
		||||
    private String profilePicture;
 | 
			
		||||
 | 
			
		||||
@ -89,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,26 +3,26 @@ package ovh.herisson.Clyde.Tables;
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class UserCursus {
 | 
			
		||||
public class UserCurriculum {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private int id;
 | 
			
		||||
 | 
			
		||||
    //Un étudiant peut avoir plusieurs cursus
 | 
			
		||||
    //Un étudiant peut avoir plusieurs curriculums
 | 
			
		||||
    @ManyToOne(fetch = FetchType.EAGER)
 | 
			
		||||
    @JoinColumn(name = "Users")
 | 
			
		||||
    private User user;
 | 
			
		||||
 | 
			
		||||
    @OneToOne(fetch = FetchType.EAGER)
 | 
			
		||||
    @JoinColumn(name = "Cursus")
 | 
			
		||||
    private Cursus cursus;
 | 
			
		||||
    @JoinColumn(name = "Curriculum")
 | 
			
		||||
    private Curriculum curriculum;
 | 
			
		||||
 | 
			
		||||
    public UserCursus(User user, Cursus cursus){
 | 
			
		||||
    public UserCurriculum(User user, Curriculum curriculum){
 | 
			
		||||
        this.user = user;
 | 
			
		||||
        this.cursus = cursus;
 | 
			
		||||
        this.curriculum = curriculum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public UserCursus() {}
 | 
			
		||||
    public UserCurriculum() {}
 | 
			
		||||
 | 
			
		||||
    public int getId() {
 | 
			
		||||
        return id;
 | 
			
		||||
@ -36,11 +36,11 @@ public class UserCursus {
 | 
			
		||||
        this.user = user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user