diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java new file mode 100644 index 0000000..77b2f3e --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java @@ -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> getAuthorizedApps(@RequestHeader("Authorization") String token){ + + return new ResponseEntity<>(getAuthorizedApplications(token), HttpStatus.OK); + } + + @GetMapping("/apps/{identifier}") + public ResponseEntity 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 getAuthorizedApplications(String token){ + ArrayList 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; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java new file mode 100644 index 0000000..011689f --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java @@ -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 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 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 patchCourse(@RequestHeader("Authorization") String token, + @RequestBody Map 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 postTeachers(@RequestHeader("Authorization") String token, + @RequestBody Iterable 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); + + } + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CurriculumController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CurriculumController.java new file mode 100644 index 0000000..1892d6c --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CurriculumController.java @@ -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 findById(@PathVariable long id){ + return new ResponseEntity<>(curriculumServ.findById(id), HttpStatus.OK); + } + + @GetMapping("/curriculums") + public ResponseEntity>> findAllindDepth(){ + return new ResponseEntity<>(curriculumCourseServ.getAllDepthCurriculum(),HttpStatus.OK); + } + + @GetMapping("/curriculum") + public ResponseEntity> findAll(){ + return new ResponseEntity<>(curriculumCourseServ.findAll(),HttpStatus.OK); + } + + /**@PostMapping("/curriculum") //todo now + public ResponseEntity 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); + }**/ + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java new file mode 100644 index 0000000..36946b5 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java @@ -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>> getAllRequests(@RequestHeader("Authorization") String token){ + + if (authServ.isNotSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);} + + Iterable inscriptionRequests = inscriptionServ.getAll(); + ArrayList> toReturn = new ArrayList<>(); + + for (InscriptionRequest i:inscriptionRequests){ + toReturn.add(requestWithoutPassword(i)); + } + + return new ResponseEntity<>(toReturn, HttpStatus.OK); + } + + + @GetMapping("/request/register/{id}") + public ResponseEntity> 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 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 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 requestWithoutPassword(InscriptionRequest inscriptionRequest) { + Map 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; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java index e43f0a1..2be125d 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java @@ -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 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 register(@RequestBody InscriptionRequest inscriptionRequest){ + authServ.register(inscriptionRequest); + return new ResponseEntity<>("Is OK", HttpStatus.CREATED); + } } - - diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java index 136cecd..1750889 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -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 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(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") diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java index 844e82e..8437b81 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java @@ -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 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>> getAllUsers(@RequestHeader("Authorization") String authorization){ - if (!isSecretaryOrAdmin(authorization)) + if (authServ.isNotSecretaryOrAdmin(authorization)) return new UnauthorizedResponse<>(null); Iterable users = userService.getAll(); @@ -78,6 +75,21 @@ public class UserController { return new ResponseEntity<>("data modified", HttpStatus.OK); } + @GetMapping("/teachers") + public ResponseEntity>> getAllTeachers(@RequestHeader("Authorization") String token){ + if (authServ.getUserFromToken(token) == null) + return new UnauthorizedResponse<>(null); + Iterable teachers = userService.getAllTeachers(); + ArrayList> 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 userWithoutPassword(User user){ HashMap 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; - } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CourseRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CourseRepository.java new file mode 100644 index 0000000..671a995 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CourseRepository.java @@ -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 findById(long id); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumCourseRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumCourseRepository.java new file mode 100644 index 0000000..c99f50b --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumCourseRepository.java @@ -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 { + + @Query("select distinct cc.course from CurriculumCourse cc where cc.curriculum = ?1") + Iterable findCoursesByCurriculum(Curriculum curriculum); + + + @Query("select distinct cc.curriculum from CurriculumCourse cc") + Iterable findDistinctCurriculums(); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumRepository.java new file mode 100644 index 0000000..441422f --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumRepository.java @@ -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 findById(long id); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/InscriptionRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/InscriptionRepository.java new file mode 100644 index 0000000..0d83e6b --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/InscriptionRepository.java @@ -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 findById(long aLong); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/TeacherCourseRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/TeacherCourseRepository.java new file mode 100644 index 0000000..ffe654a --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/TeacherCourseRepository.java @@ -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 { +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserRepository.java index af2bd08..b2643e0 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserRepository.java @@ -15,4 +15,8 @@ public interface UserRepository extends CrudRepository { /** @Query(value = "select a.* from Users a ",nativeQuery = true) Iterable findAllUsers();**/ + + @Query("select u from User u where u.role = ovh.herisson.Clyde.Tables.Role.Teacher") + Iterable findAllTeachers(); + } \ No newline at end of file diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java index 4cd1939..63ef3c1 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java @@ -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; + } } + diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/CourseService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/CourseService.java new file mode 100644 index 0000000..8278bbe --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/CourseService.java @@ -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 updates, Role role) { + Course target = courseRepo.findById(id); + + if (role == Role.Teacher){ + for (Map.Entry entry : updates.entrySet()){ + if (entry.getKey().equals("title")){ + target.setTitle((String) entry.getValue()); + return courseRepo.save(target); + } + } + } + + for (Map.Entry 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); + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/CurriculumCourseService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/CurriculumCourseService.java new file mode 100644 index 0000000..ccf1226 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/CurriculumCourseService.java @@ -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 findAll(){ + return curriculumCourseRepo.findAll(); + } + + + public Map getDepthCurriculum(Curriculum curriculum){ + + HashMap toReturn = new HashMap<>(); + ArrayList 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> getAllDepthCurriculum(){ + + ArrayList> toReturn = new ArrayList<>(); + + for (Curriculum curriculum : curriculumCourseRepo.findDistinctCurriculums()){ + toReturn.add(getDepthCurriculum(curriculum)); + } + return toReturn; + } + + + + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/CurriculumService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/CurriculumService.java new file mode 100644 index 0000000..6f6d89b --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/CurriculumService.java @@ -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 findAll(){ + return curriculumRepo.findAll(); + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java new file mode 100644 index 0000000..6130fe8 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java @@ -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 getAll(){ + return inscriptionRepo.findAll(); + } + + public void modifyState(long id, RequestState requestState) { + InscriptionRequest inscriptionRequest = getById(id); + inscriptionRequest.setState(requestState); + save(inscriptionRequest); + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/StorageService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/StorageService.java index 14a41d9..24e53c0 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/StorageService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/StorageService.java @@ -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; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/TeacherCourseService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/TeacherCourseService.java new file mode 100644 index 0000000..0996adf --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/TeacherCourseService.java @@ -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 teacherIds, Course course){ + + ArrayList 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; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java index 50ddcbf..2f746ce 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java @@ -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); } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/UserService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/UserService.java index 097dbaa..c2d5fb4 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/UserService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/UserService.java @@ -102,4 +102,8 @@ public class UserService { public Iterable getAll(){ return userRepo.findAll(); } + + + + public Iterable getAllTeachers (){return userRepo.findAllTeachers();} } \ No newline at end of file diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java new file mode 100644 index 0000000..6ad6567 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java @@ -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 +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java index 54e167a..e338d7d 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java @@ -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; + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Curriculum.java similarity index 76% rename from backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java rename to backend/src/main/java/ovh/herisson/Clyde/Tables/Curriculum.java index 5167197..67075d1 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Curriculum.java @@ -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(){ diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/CurriculumCourse.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/CurriculumCourse.java new file mode 100644 index 0000000..8202e8d --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/CurriculumCourse.java @@ -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; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java deleted file mode 100644 index ecdd857..0000000 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java +++ /dev/null @@ -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; - } -} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java index fa853b1..dfbf7ed 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java @@ -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() { diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java index c7c5569..57ad53c 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java @@ -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() { diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/RequestState.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/RequestState.java index f0345c1..d52f1c9 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/RequestState.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/RequestState.java @@ -3,5 +3,5 @@ package ovh.herisson.Clyde.Tables; public enum RequestState { Accepted, Refused, - Pending; + Pending } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Role.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Role.java index 4e4469b..f6f8967 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Role.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Role.java @@ -5,5 +5,5 @@ public enum Role { Student, Admin, InscriptionService, - Secretary; -} + Secretary +} \ No newline at end of file diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Secretary.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Secretary.java deleted file mode 100644 index cc34841..0000000 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Secretary.java +++ /dev/null @@ -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; - } -} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherGivenCourse.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherCourse.java similarity index 56% rename from backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherGivenCourse.java rename to backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherCourse.java index a1ee138..3392c72 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherGivenCourse.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherCourse.java @@ -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; - } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCurriculum.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCurriculum.java new file mode 100644 index 0000000..2202763 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCurriculum.java @@ -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; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCursus.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCursus.java deleted file mode 100644 index a5c5153..0000000 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCursus.java +++ /dev/null @@ -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; - } -} diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 7b944de..030c38d 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,37 +1,22 @@