From bd1c236635ef47a0a003e865e4818cb856abd615 Mon Sep 17 00:00:00 2001 From: Wawilski Date: Fri, 19 Apr 2024 21:29:45 +0200 Subject: [PATCH] Request and changes --- .../EndPoints/ApplicationsController.java | 5 +- .../Clyde/EndPoints/LessonController.java | 7 +- .../EndPoints/LessonRequestsController.java | 125 ++++++++ .../Clyde/EndPoints/MockController.java | 14 +- .../LessonChangesRequestRepository.java | 14 + .../ScheduleLessonRepository.java | 5 +- .../Repositories/ScheduleRepository.java | 9 +- .../Clyde/Services/LessonRequestService.java | 93 ++++++ .../Clyde/Services/LessonService.java | 6 - .../Clyde/Services/ProtectionService.java | 31 +- .../Clyde/Services/ScheduleLessonService.java | 11 + .../Clyde/Services/ScheduleService.java | 2 +- .../herisson/Clyde/Tables/Applications.java | 4 + .../Clyde/Tables/LessonChangesRequest.java | 130 +++++++++ frontend/public/i18n/EN.txt | 2 + frontend/public/i18n/FR.txt | 2 + frontend/src/Apps/LessonRequests.vue | 220 ++++++++++++++ frontend/src/Apps/ManageCourses.vue | 11 - frontend/src/Apps/ManageOwnLessons.vue | 270 ++++++++++++++++++ frontend/src/Apps/ManageSchedule.vue | 45 +-- frontend/src/rest/LessonRequests.js | 23 ++ frontend/src/rest/apps.js | 6 + 22 files changed, 967 insertions(+), 68 deletions(-) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonRequestsController.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/LessonChangesRequestRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/LessonRequestService.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/LessonChangesRequest.java create mode 100644 frontend/src/Apps/LessonRequests.vue create mode 100644 frontend/src/Apps/ManageOwnLessons.vue create mode 100644 frontend/src/rest/LessonRequests.js diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java index 77a713e..202a1e6 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java @@ -61,6 +61,8 @@ public class ApplicationsController { authorizedApps.add(Applications.Rdv); } + if(!authServ.isNotIn(new Role[]{Role.Teacher,Role.Admin},token)) + authorizedApps.add(Applications.ManageOwnedLessons); //if Teacher or Secretary or Admin add ManageCourses App if (!authServ.isNotIn(new Role[]{Role.Teacher,Role.Secretary,Role.Admin},token)) authorizedApps.add(Applications.ManageCourses); @@ -71,7 +73,8 @@ public class ApplicationsController { if (!authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)){ authorizedApps.add(Applications.UsersList); - authorizedApps.add(Applications.ManageSchedules);} + authorizedApps.add(Applications.ManageSchedules); + authorizedApps.add(Applications.LessonRequests);} return authorizedApps; } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonController.java index 8074abd..080b024 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonController.java @@ -7,6 +7,7 @@ import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Services.AuthenticatorService; import ovh.herisson.Clyde.Services.LessonService; import ovh.herisson.Clyde.Services.ProtectionService; +import ovh.herisson.Clyde.Services.ScheduleLessonService; import ovh.herisson.Clyde.Tables.Lesson; import ovh.herisson.Clyde.Tables.Role; @@ -18,10 +19,12 @@ import java.util.Map; public class LessonController { private final LessonService lessonServ; + private final ScheduleLessonService scheduleLessonServ; private final AuthenticatorService authServ; - public LessonController(LessonService lessonServ, AuthenticatorService authServ) { + public LessonController(LessonService lessonServ, ScheduleLessonService scheduleLessonService, AuthenticatorService authServ) { this.lessonServ = lessonServ; + this.scheduleLessonServ = scheduleLessonService; this.authServ = authServ; } @@ -60,6 +63,8 @@ public class LessonController { Lesson lesson = lessonServ.createLesson(lessonInfos); Lesson createdLesson = lessonServ.save(lesson); + scheduleLessonServ.saveToAllSchedule(lesson); + if(createdLesson==null) return new ResponseEntity<>(null,HttpStatus.BAD_REQUEST); return new ResponseEntity<>(ProtectionService.lessonWithoutPassword(createdLesson), HttpStatus.OK); diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonRequestsController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonRequestsController.java new file mode 100644 index 0000000..2facbc0 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonRequestsController.java @@ -0,0 +1,125 @@ +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.LessonRequestService; +import ovh.herisson.Clyde.Services.LessonService; +import ovh.herisson.Clyde.Services.ProtectionService; +import ovh.herisson.Clyde.Tables.LessonChangesRequest; +import ovh.herisson.Clyde.Tables.RequestState; +import ovh.herisson.Clyde.Tables.Role; +import ovh.herisson.Clyde.Tables.User; + +import java.util.Map; + +@RestController +@CrossOrigin(originPatterns = "*", allowCredentials = "true") +public class LessonRequestsController { + private final LessonRequestService lessonRequestServ; + private final AuthenticatorService authServ; + + private final LessonService lessonServ; + public LessonRequestsController(LessonRequestService lessonRequestServer, AuthenticatorService authServ, LessonService lessonServ) { + this.lessonRequestServ = lessonRequestServer; + this.authServ = authServ; + this.lessonServ = lessonServ; + } + + @GetMapping("/requests/lessonRequest/{id}") + public ResponseEntity> getById(@RequestHeader("Authorization") String token, @PathVariable long id){ + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token)) + return new UnauthorizedResponse<>(null); + + LessonChangesRequest lessonRequest= lessonRequestServ.findById(id); + + return new ResponseEntity<>(ProtectionService.lessonRequestWithoutPassword(lessonRequest), HttpStatus.OK); + } + + @GetMapping("/requests/lessonRequests/owned") + public ResponseEntity>> getOwnedRequests(@RequestHeader("Authorization") String token){ + if(authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token)) + return new UnauthorizedResponse<>(null); + User user = authServ.getUserFromToken(token); + Iterable lessonChangesRequests = lessonRequestServ.findOwnRequests(user); + return new ResponseEntity<>(ProtectionService.lessonRequestsWithoutPassword(lessonChangesRequests),HttpStatus.OK); + + } + + @GetMapping("/requests/lessonRequests") + public ResponseEntity>> getAllRequests(@RequestHeader("Authorization") String token){ + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token)) + return new UnauthorizedResponse<>(null); + + Iterable lessonRequests= lessonRequestServ.getAll(); + + return new ResponseEntity<>(ProtectionService.lessonRequestsWithoutPassword(lessonRequests), HttpStatus.OK); + } + + @PostMapping("/requests/lessonRequest") + public ResponseEntity> makeRequest(@RequestBody LessonChangesRequest lessonRequest){ + System.out.println(lessonRequest.getLesson()); + System.out.println(lessonRequest.getLessonEnd()); + LessonChangesRequest lessonChangesRequest = lessonRequestServ.save(lessonRequest); + return new ResponseEntity<>(ProtectionService.lessonRequestWithoutPassword(lessonChangesRequest),HttpStatus.OK); + } + + @PatchMapping("/requests/lessonRequest/{id}") + public ResponseEntity changeRequestState(@PathVariable long id, + @RequestHeader("Authorization") String token, + @RequestBody Map infos){ + if(authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)) + return new UnauthorizedResponse<>(null); + + LessonChangesRequest lessonRequest = lessonRequestServ.findById(id); + String local = ""; + RequestState state = null; + for (Map.Entry entry : infos.entrySet()) { + switch (entry.getKey()) { + case "local": + local = (String) entry.getValue(); + break; + case "state": + state = RequestState.valueOf((String)entry.getValue()); + } + } + + if (state == null) + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + + if(lessonRequest.getRequestType() == 0 ) { + if (!lessonRequestServ.modifyCreateRequestState(lessonRequest, state, local)) + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + } + + else if(lessonRequest.getRequestType() == 1){ + infos.put("lessonStart", lessonRequest.getLessonStart()); + infos.put("lessonEnd", lessonRequest.getLessonEnd()); + infos.put("lessonType",lessonRequest.getLessonType()); + if(!lessonRequestServ.modifyChangeRequestState(infos,lessonRequest.getLesson(),state)) + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + lessonRequest.setState(state); + } + + else{ + lessonRequestServ.modifyDeleleRequest(lessonRequest, state); + } + lessonRequestServ.save(lessonRequest); + return new ResponseEntity<>(HttpStatus.OK); + + } + + + @DeleteMapping("/requests/lessonRequest/{id}") + public ResponseEntity deleteRequest(@RequestHeader("Authorization") String token, @PathVariable long id){ + if(authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.Teacher},token)) + return new UnauthorizedResponse<>(null); + LessonChangesRequest lessonChangesRequest = lessonRequestServ.findById(id); + if (lessonChangesRequest == null) + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + lessonRequestServ.delete(lessonChangesRequest); + return new ResponseEntity<>(HttpStatus.OK); + } +} 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 5a69a82..23229ce 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -29,10 +29,11 @@ public class MockController { public final ScheduleService scheduleService; public final ScheduleLessonService scheduleLessonService; + public final LessonRequestService lessonRequestService; ArrayList mockUsers; - public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService, LessonService lessonService, ScheduleService scheduleService, ScheduleLessonService scheduleLessonService){ + public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService, LessonService lessonService, ScheduleService scheduleService, ScheduleLessonService scheduleLessonService, LessonRequestService lessonRequestService){ this.tokenRepo = tokenRepo; this.userRepo = userRepo; this.tokenService = tokenService; @@ -43,6 +44,7 @@ public class MockController { this.lessonService = lessonService; this.scheduleService = scheduleService; this.scheduleLessonService = scheduleLessonService; + this.lessonRequestService = lessonRequestService; } /** Saves an example of each user type by : @@ -113,10 +115,16 @@ public class MockController { Lesson lesson_1_progra1 = new Lesson(progra1, "Mon Apr 02 2024 13:30", "Mon Apr 02 2024 15:30","rgb(0,50,100)","A0B2","TP"); Lesson lesson_0_commun = new Lesson(commun, "Mon Apr 01 2024 10:30", "Mon Apr 01 2024 12:30","rgb(0,50,100)","A0B2","Course"); + LessonChangesRequest request1 = new LessonChangesRequest(joke,RequestState.Pending,null,null,null,null,2,null,1); + LessonChangesRequest request2 = new LessonChangesRequest(joke,RequestState.Pending,"Fri Apr 19 2024 10:30 ","Fri Apr 19 2024 12:30 ",null,null,1,null,2); + LessonChangesRequest request3 = new LessonChangesRequest(joke,RequestState.Pending,"Fri Apr 19 2024 13:30 ","Fri Apr 19 2024 15:30 ","Course",progra1,0,"rgb(27,49,100)",4); + + Schedule infoBab1Schedule = new Schedule(infoBab1); Schedule chemistryBab1Schedule = new Schedule(chemistryBab1); Schedule psychoBab1Schedule = new Schedule(psychologyBab1); + scheduleService.save(infoBab1Schedule); scheduleService.save(chemistryBab1Schedule); scheduleService.save(psychoBab1Schedule); @@ -137,6 +145,10 @@ public class MockController { scheduleLessonService.save(new ScheduleLesson(psychoBab1Schedule,lesson_0_psycho1)); scheduleLessonService.save(new ScheduleLesson(psychoBab1Schedule,lesson_0_commun)); + + lessonRequestService.save(request1); + lessonRequestService.save(request2); + lessonRequestService.save(request3); } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/LessonChangesRequestRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/LessonChangesRequestRepository.java new file mode 100644 index 0000000..208591e --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/LessonChangesRequestRepository.java @@ -0,0 +1,14 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.LessonChangesRequest; +import ovh.herisson.Clyde.Tables.User; + +public interface LessonChangesRequestRepository extends CrudRepository { + LessonChangesRequest findById(long id); + + + @Query("select lr from LessonChangesRequest lr where lr.user = ?1") + Iterable findOwnRequests(User user); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleLessonRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleLessonRepository.java index db1b0c2..68cd593 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleLessonRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleLessonRepository.java @@ -21,7 +21,10 @@ public interface ScheduleLessonRepository extends CrudRepository findLessonBySchedule(Schedule schedule); + Iterable findLessonsBySchedule(Schedule schedule); + + + @Modifying @Transactional diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleRepository.java index 192fb05..7159da9 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleRepository.java @@ -1,9 +1,16 @@ 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.Lesson; import ovh.herisson.Clyde.Tables.Schedule; public interface ScheduleRepository extends CrudRepository { - Schedule findById(long id); + Schedule getById(long id); + + + @Query("select distinct sl from Schedule sl where EXISTS (select c.curriculum from CurriculumCourse c where (sl.curriculum = c.curriculum) AND (c.course = ?1))") + Iterable findAllLessonSchedule(Course course); } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/LessonRequestService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/LessonRequestService.java new file mode 100644 index 0000000..24c0a7c --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/LessonRequestService.java @@ -0,0 +1,93 @@ +package ovh.herisson.Clyde.Services; + +import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.Repositories.*; +import ovh.herisson.Clyde.Tables.*; + +import java.sql.SQLOutput; +import java.util.Map; + +@Service +public class LessonRequestService { + private final LessonChangesRequestRepository lessonChangesRepo; + + private final UserRepository userRepo; + + private final LessonRepository lessonRepo; + + private final LessonService lessonServ; + + private final ScheduleLessonRepository scheduleLessonRepo; + + private final ScheduleRepository scheduleRepository; + + private final ScheduleLessonService scheduleLessonService; + + private final CourseRepository courseRepository; + public LessonRequestService(LessonChangesRequestRepository lessonChangesRepo, + UserRepository userRepo, LessonRepository lessonRepo, + LessonService lessonServ, ScheduleLessonRepository scheduleLessonRepo, ScheduleRepository scheduleRepository, ScheduleLessonService scheduleLessonService, CourseRepository courseRepository) { + this.lessonChangesRepo = lessonChangesRepo; + this.userRepo = userRepo; + this.lessonRepo = lessonRepo; + this.lessonServ = lessonServ; + this.scheduleLessonRepo = scheduleLessonRepo; + this.scheduleRepository = scheduleRepository; + this.scheduleLessonService = scheduleLessonService; + this.courseRepository = courseRepository; + } + public Iterable findOwnRequests(User user){ + return lessonChangesRepo.findOwnRequests(user); + } + public LessonChangesRequest save(LessonChangesRequest lessonRequest){ + return lessonChangesRepo.save(lessonRequest); + } + public LessonChangesRequest findById(long id){ + return lessonChangesRepo.findById(id); + } + public Iterable getAll(){return lessonChangesRepo.findAll();} + + public boolean modifyCreateRequestState(LessonChangesRequest lessonRequest, RequestState state, String local ){ + if(lessonRequest == null || state == lessonRequest.getState() || state == null){ + return false;} + if (state == RequestState.Accepted){ + Course course = courseRepository.findById(lessonRequest.getCourse().getCourseID()); + if(courseRepository.findById(lessonRequest.getCourse().getCourseID())==null|| local == null){ + return false;} + Lesson lesson = new Lesson( + course, + lessonRequest.getLessonStart(), + lessonRequest.getLessonEnd(), + lessonRequest.getColor(), + local, + lessonRequest.getLessonType()); + lesson = lessonRepo.save(lesson); + scheduleLessonService.saveToAllSchedule(lesson); + } + lessonRequest.setState(state); + save(lessonRequest); + return true; + } + + public boolean modifyChangeRequestState(Map updates, long lessonId,RequestState state){ + if(state == RequestState.Accepted){ + System.out.println(updates.toString()); + + Lesson lesson = lessonServ.findById(lessonId); + return lessonServ.modifyData(lesson.getLessonID(),updates); + } + return true; + } + + public void modifyDeleleRequest(LessonChangesRequest lessonChangesRequest, RequestState state){ + if(state == RequestState.Accepted){ + lessonServ.delete(lessonServ.findById(lessonChangesRequest.getLesson())); + lessonChangesRequest.setState(state);} + } + + + + public void delete (LessonChangesRequest toDelete) { + lessonChangesRepo.delete(toDelete); + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java index e873699..3436e2c 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java @@ -68,17 +68,11 @@ public class LessonService { public boolean modifyData(long id, Map updates){ Lesson target = lessonRepo.findById(id); - System.out.println(target); if(target == null) return false; - - System.out.println("test"); - System.out.println(updates.entrySet()); - for (Map.Entry entry: updates.entrySet()){ - System.out.println(entry); switch (entry.getKey()){ case "lessonStart": target.setLessonStart((String) entry.getValue()); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java index 6c7f06f..3b8bca2 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java @@ -1,9 +1,6 @@ package ovh.herisson.Clyde.Services; -import ovh.herisson.Clyde.Tables.Course; -import ovh.herisson.Clyde.Tables.InscriptionRequest; -import ovh.herisson.Clyde.Tables.Lesson; -import ovh.herisson.Clyde.Tables.User; +import ovh.herisson.Clyde.Tables.*; import java.util.ArrayList; import java.util.HashMap; @@ -119,6 +116,32 @@ public class ProtectionService { return toReturn; } + public static Map lessonRequestWithoutPassword(LessonChangesRequest lessonRequest){ + if (lessonRequest == null) + return null; + Map toReturn = new HashMap<>(); + toReturn.put("id", lessonRequest.getId()); + toReturn.put("lessonStart", lessonRequest.getLessonStart()); + toReturn.put("lessonEnd", lessonRequest.getLessonEnd()); + toReturn.put("lessonType",lessonRequest.getLessonType()); + toReturn.put("course", courseWithoutPassword(lessonRequest.getCourse())); + toReturn.put("user", userWithoutPassword(lessonRequest.getUser())); + toReturn.put("requestType", lessonRequest.getRequestType()); + toReturn.put("state", lessonRequest.getState()); + toReturn.put("lessonId",lessonRequest.getLesson()); + + return toReturn; + } + + public static Iterable> lessonRequestsWithoutPassword(Iterable lessonChangesRequests){ + ArrayList> toReturn = new ArrayList<>(); + + for(LessonChangesRequest lessonChangeRequest: lessonChangesRequests){ + toReturn.add(lessonRequestWithoutPassword(lessonChangeRequest)); + } + return toReturn; + + } public static Iterable> requestsWithoutPasswords(Iterable inscriptionRequests){ ArrayList> toReturn = new ArrayList<>(); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleLessonService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleLessonService.java index 0fde2fe..f43d28f 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleLessonService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleLessonService.java @@ -9,6 +9,7 @@ import ovh.herisson.Clyde.Tables.*; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import java.util.Optional; @Service public class ScheduleLessonService { @@ -30,6 +31,16 @@ public class ScheduleLessonService { return true; } + public boolean saveToAllSchedule(Lesson lesson){ + Iterable schedules = scheduleRepo.findAllLessonSchedule(lesson.getCourse()); + if(schedules == null) + return false; + for (Schedule schedule : schedules){ + save(new ScheduleLesson(schedule, lesson)); + } + return true; + } + public boolean delete(long lessonId){ if(lessonId == 0) return false; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleService.java index 950261c..0d73cfc 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleService.java @@ -14,7 +14,7 @@ public class ScheduleService { return scheduleRepo.save(schedule); } public Schedule findById(long id){ - return scheduleRepo.findById(id); + return scheduleRepo.getById(id); } public void delete(Schedule schedule){ scheduleRepo.delete(schedule); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java index 77e24ca..35d49aa 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java @@ -13,6 +13,9 @@ public enum Applications { Msg, Forum, Rdv, + // teachers authorization + + ManageOwnedLessons, // teachers and Secretary authorization ManageCourses, @@ -20,6 +23,7 @@ public enum Applications { //Secretary authorization ManageSchedules, + LessonRequests, // InscriptionService authorization Inscription, diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/LessonChangesRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/LessonChangesRequest.java new file mode 100644 index 0000000..752421b --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/LessonChangesRequest.java @@ -0,0 +1,130 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +@Entity +public class LessonChangesRequest { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @ManyToOne + @JoinColumn(name = "Users") + @OnDelete(action = OnDeleteAction.CASCADE) + private User user; + + private long lessonId; + + private RequestState state; + + private String lessonStart; + + private String lessonEnd; + + private String color; + @OneToOne + @JoinColumn(name ="Course") + private Course course; + + private String lessonType; + + private int requestType; + + public LessonChangesRequest(User user, RequestState state, String lessonStart, + String lessonEnd, String lessonType, Course course, + int requestType, String color,long lessonId){ + this.user = user; + this.state = state; + this.requestType = requestType; + this.lessonType = lessonType; + this.lessonStart = lessonStart; + this.lessonEnd= lessonEnd; + this.color = color; + this.course = course; + this.lessonId = lessonId; + } + + public LessonChangesRequest() { + + } + + public int getId() { + return id; + } + + + public RequestState getState() { + return state; + } + + public User getUser() { + return user; + } + + public long getLesson(){ + return lessonId; + } + + public String getLessonStart() { + return lessonStart; + } + + public String getLessonEnd() { + return lessonEnd; + } + + + + public int getRequestType() { + return requestType; + } + + public String getLessonType() { + return lessonType; + } + + public String getColor() { + return color; + } + + public Course getCourse() { + return course; + } + + public void setState(RequestState state) { + this.state = state; + } + + public void setUser(User user) { + this.user = user; + } + + public void setLessonStart(String lessonStart) { + this.lessonStart = lessonStart; + } + + public void setLessonType(String lessonType) { + this.lessonType = lessonType; + } + + public void setLessonEnd(String lessonEnd) { + this.lessonEnd = lessonEnd; + } + + public void setColor(String color) { + this.color = color; + } + + public void setRequestType(int requestType) { + this.requestType = requestType; + } + + + + public void setCourse(Course course){ + this.course = course; + } +} diff --git a/frontend/public/i18n/EN.txt b/frontend/public/i18n/EN.txt index 775b412..d5d232f 100644 --- a/frontend/public/i18n/EN.txt +++ b/frontend/public/i18n/EN.txt @@ -29,6 +29,8 @@ app.language=Language app.manage.profile=Manage profile app.studentList=Students List app.users=Users +app.manageOwnLessons=Manage Owned Courses Schedule +app.lessonRequests=Schedule Requests request.moreInfos=More Infos request.accept=Accept request.refuse=Refuse diff --git a/frontend/public/i18n/FR.txt b/frontend/public/i18n/FR.txt index cf1d5ca..bd21ce5 100644 --- a/frontend/public/i18n/FR.txt +++ b/frontend/public/i18n/FR.txt @@ -29,6 +29,8 @@ app.language=Langue app.manage.profile=Gérer le profil app.studentList=Liste des étudiants app.users=Utilisateurs +app.manageOwnLessons=Gérer ses horaires de cours +app.lessonRequests=Requêtes d'horaire request.moreInfos=Plus d'Infos request.accept=Accepter request.refuse=Refuser diff --git a/frontend/src/Apps/LessonRequests.vue b/frontend/src/Apps/LessonRequests.vue new file mode 100644 index 0000000..2a8270d --- /dev/null +++ b/frontend/src/Apps/LessonRequests.vue @@ -0,0 +1,220 @@ + + + + + + + + + diff --git a/frontend/src/Apps/ManageCourses.vue b/frontend/src/Apps/ManageCourses.vue index 44cd187..6645dee 100644 --- a/frontend/src/Apps/ManageCourses.vue +++ b/frontend/src/Apps/ManageCourses.vue @@ -173,17 +173,6 @@ margin-top:3.5%; } -.infosContainer { - min-width:350px; - padding-bottom:50px; - border:2px solid black; - font-size:25px; - color:white; - padding:20px; - background-color:rgb(50,50,50); - border-radius:20px; -} - .containerElement{ justify-content:center; display:grid; diff --git a/frontend/src/Apps/ManageOwnLessons.vue b/frontend/src/Apps/ManageOwnLessons.vue new file mode 100644 index 0000000..16a3ef7 --- /dev/null +++ b/frontend/src/Apps/ManageOwnLessons.vue @@ -0,0 +1,270 @@ + + + + + diff --git a/frontend/src/Apps/ManageSchedule.vue b/frontend/src/Apps/ManageSchedule.vue index dcfa93b..8745a5a 100644 --- a/frontend/src/Apps/ManageSchedule.vue +++ b/frontend/src/Apps/ManageSchedule.vue @@ -14,7 +14,6 @@ import i18n from '@/i18n.js' const allSchedules = ref(await getAllSchedule()); const filter = ref("null"); const subFilter = ref("null"); - const lesson = ref(); const filters = ["Type","Teacher","Course"]; const types = ["TP","TD","Course","Exam"]; const locals = ["A0B1","A1B1","A2B1","A0B2"] @@ -29,9 +28,6 @@ const currentDate = new Date(); const editElementID = ref() -function editItem(id){ - editElementID.value = id; -} function invertedFormatDate(date) { var d = new Date(date), @@ -94,8 +90,8 @@ const toModify = ref(Object.assign({}, pattern)); toModify.value.day = invertedFormatDate(new Date(lesson.lessonStart)); toModify.value.lessonStart = getHoursMinutes(lesson.lessonStart); toModify.value.lessonEnd = getHoursMinutes(lesson.lessonEnd); - toModify.value.local = lesson.local - toModify.value.lessonType = lesson.lessonType + toModify.value.local = lesson.local; + toModify.value.lessonType = lesson.lessonType; } function inFuture(lesson){ @@ -171,15 +167,7 @@ async function setCourses(){ subFilter.value = "null" } - function findCreatedLesson(){ - for(let element in lessonFinder.value){ - if((lessonFinder.value[element].course.courseId ==lessonBuffer.value.course.courseId) && (lessonFinder.value[element].local == lessonBuffer.value.local) ){ - return lessonFinder.value[element]; - } - } - return null; -} - + async function newLesson(){ let isnull = false; if (lessonBuffer.value.lessonType != null){ @@ -205,12 +193,8 @@ async function setCourses(){ await createLesson(lessonCreatorBuffer.value); lessonFinder.value = await getLessons(); - lesson.value = findCreatedLesson(); - - trueSchedule.value = await getCurriculumSchedule(curriculum.value.curriculumId) - await addLessonToSchedule(trueSchedule.value.scheduleId,lesson.value.lessonID) - } + } } lessonBuffer.value = Object.assign({}, pattern); lessonFinder.value = null; @@ -410,18 +394,6 @@ async function patchLesson(lesson){ margin-top:3.5%; } -.infosContainer { - min-width:350px; - width:70%; - padding-bottom:50px; - border:2px solid black; - font-size:25px; - color:white; - padding:20px; - background-color:rgb(50,50,50); - border-radius:20px; -} - .listElement{ min-width:625px; border:2px solid black; @@ -434,15 +406,6 @@ async function patchLesson(lesson){ } -.modify{ - font-size:25px; - padding:10px 10px 10px 10px; - background-color: rgb(239,60,168); - cursor: pointer; - border:none; - border-radius:15px; -} - input, select{ padding:10px 10px 10px 10px; font-size:25px; diff --git a/frontend/src/rest/LessonRequests.js b/frontend/src/rest/LessonRequests.js new file mode 100644 index 0000000..5ad8e89 --- /dev/null +++ b/frontend/src/rest/LessonRequests.js @@ -0,0 +1,23 @@ +import { restGet, restPost, restDelete, restPatch } from './restConsumer.js' + +export async function getLessonRequest(id){ + return restGet('/requests/lessonRequest/' + id); +} + +export async function getAllRequests(){ + return restGet("/requests/lessonRequests"); +} +export async function getOwnedRequests(){ + return restGet("/requests/lessonRequests/owned"); +} +export async function createRequest(request){ + return restPost("/requests/lessonRequest", request); +} + +export async function changeRequestState(id, infos){ + return restPatch("/requests/lessonRequest/" + id, infos); +} + +export async function deleteRequest(id){ + return restDelete("/requests/lessonRequest/"+id); +} \ No newline at end of file diff --git a/frontend/src/rest/apps.js b/frontend/src/rest/apps.js index 0302405..f759516 100644 --- a/frontend/src/rest/apps.js +++ b/frontend/src/rest/apps.js @@ -11,6 +11,8 @@ import Users from "@/Apps/UsersList.vue" import Students from "@/Apps/StudentsList.vue" import Schedule from "@/Apps/Schedule.vue" import ManageSchedule from "@/Apps/ManageSchedule.vue" +import ManageOwnedLessons from "@/Apps/ManageOwnLessons.vue"; +import LessonRequests from "@/Apps/LessonRequests.vue"; const apps = { '/schedule': Schedule, @@ -21,6 +23,8 @@ const apps = { '/manage-courses' : Courses, '/users-list' : Users, '/students-list' : Students, + '/manage-owned-lessons': ManageOwnedLessons, + '/manage-schedule-requests' : LessonRequests, } const appsList = { @@ -33,6 +37,8 @@ const appsList = { 'ManageCourses': { path: '#/manage-courses', icon: 'fa-book', text: i18n("app.manage.courses") }, 'StudentsList':{ path: '#/students-list',icon: 'fa-users',text: i18n("app.studentList")}, 'UsersList':{ path: '#/users-list',icon: 'fa-users',text: i18n("app.users")}, + 'ManageOwnedLessons':{path: '#/manage-owned-lessons',icon:'fa-calendar-days',text: i18n("app.manageOwnLessons")}, + 'LessonRequests':{path: '#/manage-schedule-requests', icon:'fa-book', text: i18n("app.lessonRequests")}, }