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 83c5050..77a713e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java @@ -70,7 +70,8 @@ public class ApplicationsController { authorizedApps.add(Applications.StudentsList);} if (!authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)){ - authorizedApps.add(Applications.UsersList);} + authorizedApps.add(Applications.UsersList); + authorizedApps.add(Applications.ManageSchedules);} 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 81be68a..63d7e24 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonController.java @@ -44,9 +44,8 @@ public class LessonController { @GetMapping("/lessons/owned") public ResponseEntity>> getOwnedLessons(@RequestHeader("Authorization") String token){ - System.out.println(authServ); + System.out.println(authServ); if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token)){ - System.out.println("problem ici"); return new UnauthorizedResponse<>(null);} return new ResponseEntity<>(ProtectionService.lessonsWithoutPassword(lessonServ.findAllOwnedLesson(authServ.getUserFromToken(token))),HttpStatus.OK); } @@ -58,7 +57,6 @@ public class LessonController { if(authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)) return new UnauthorizedResponse<>(null); Lesson createdLesson = lessonServ.save(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/ScheduleController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScheduleController.java index 5ee22cc..6cfaa01 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScheduleController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScheduleController.java @@ -12,6 +12,8 @@ import ovh.herisson.Clyde.Services.CurriculumService; import ovh.herisson.Clyde.Tables.Curriculum; import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.Schedule; +import ovh.herisson.Clyde.Tables.ScheduleLesson; +import ovh.herisson.Clyde.Services.LessonService; import java.util.Map; @@ -20,6 +22,7 @@ import java.util.Map; public class ScheduleController { private final ScheduleService scheduleServ; + private final LessonService lessonServ; private final UserCurriculumService userCurriculumService; @@ -28,12 +31,13 @@ public class ScheduleController { private final ScheduleLessonService scheduleLessonServ; - public ScheduleController(ScheduleService scheduleServ, UserCurriculumService userCurriculumService, AuthenticatorService authServ, ScheduleLessonService scheduleLessonServ, CurriculumService curriculumServ) { + public ScheduleController(ScheduleService scheduleServ, UserCurriculumService userCurriculumService, AuthenticatorService authServ, ScheduleLessonService scheduleLessonServ, CurriculumService curriculumServ,LessonService lessonServ) { this.scheduleServ = scheduleServ; this.userCurriculumService = userCurriculumService; this.authServ = authServ; this.scheduleLessonServ = scheduleLessonServ; this.curriculumServ = curriculumServ; + this.lessonServ = lessonServ; } @GetMapping("/schedule/{id}") @@ -76,4 +80,18 @@ public class ScheduleController { return new UnauthorizedResponse<>(null); return new ResponseEntity<>(scheduleServ.save(schedule),HttpStatus.OK); } + @PostMapping("/schedule/{id}") + public ResponseEntity postLessonToSchedule(@RequestHeader("Authorization") String token, + @RequestBody Long lessonId, + @PathVariable long id) + { + + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token)) + return new UnauthorizedResponse<>(null); + + if (!scheduleLessonServ.save(new ScheduleLesson( scheduleServ.findById(id), lessonServ.findById(lessonId)))) + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + + return new ResponseEntity<>(HttpStatus.OK); + } } 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 328dcb6..05d5eb7 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleLessonService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleLessonService.java @@ -23,8 +23,11 @@ public class ScheduleLessonService { this.scheduleRepo = scheduleRepo; } - public void save(ScheduleLesson scheduleLesson){ + public boolean save(ScheduleLesson scheduleLesson){ + if(scheduleLesson == null) + return false; scheduleLessonRepo.save(scheduleLesson); + return true; } public Schedule getScheduleByCurriculum(Curriculum curriculum){ 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 684441a..77e24ca 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java @@ -17,6 +17,9 @@ public enum Applications { // teachers and Secretary authorization ManageCourses, UsersList, + + //Secretary authorization + ManageSchedules, // InscriptionService authorization Inscription, diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Lesson.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Lesson.java index 8370324..67465a8 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Lesson.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Lesson.java @@ -9,7 +9,7 @@ public class Lesson { @GeneratedValue(strategy = GenerationType.AUTO) private int lessonID; - @ManyToOne + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name= "Course") private Course course; diff --git a/frontend/public/i18n/EN.txt b/frontend/public/i18n/EN.txt index e79a8a1..775b412 100644 --- a/frontend/public/i18n/EN.txt +++ b/frontend/public/i18n/EN.txt @@ -22,6 +22,7 @@ app.settings=Settings app.messages=Messages app.forum=Forum app.schedules=Schedules +app.manageSchedules=Manage Schedules app.inscription.requests=Inscription Requests app.manage.courses=Manage Courses app.language=Language diff --git a/frontend/public/i18n/FR.txt b/frontend/public/i18n/FR.txt index c5f3ebf..cf1d5ca 100644 --- a/frontend/public/i18n/FR.txt +++ b/frontend/public/i18n/FR.txt @@ -22,6 +22,7 @@ app.settings=Options app.messages=Messages app.forum=Forum app.schedules=Horaires +app.manageSchedules=Gérer les horaires app.inscription.requests=Demandes d'Inscription app.manage.courses=Gérer les cours app.language=Langue diff --git a/frontend/src/Apps/ManageCourses.vue b/frontend/src/Apps/ManageCourses.vue index 96bd35b..a9f1f66 100644 --- a/frontend/src/Apps/ManageCourses.vue +++ b/frontend/src/Apps/ManageCourses.vue @@ -35,7 +35,6 @@ let isnull= false; for(const [key, value] of Object.entries(toAdd)){ - console.log(toAdd.owner); if(value === null){ isnull=true; } @@ -64,9 +63,6 @@ async function patchCourse(course){ for (let element in toModify){ - console.log(toModify,1) - console.log(toModify[element],2) - if (element =="owner" && (toModify[element].regNo != course.owner.regNo)){ await alterCourse(course.courseId,{owner:toModify[element].regNo}); } diff --git a/frontend/src/Apps/ManageSchedule.vue b/frontend/src/Apps/ManageSchedule.vue new file mode 100644 index 0000000..905e6d7 --- /dev/null +++ b/frontend/src/Apps/ManageSchedule.vue @@ -0,0 +1,398 @@ + + + diff --git a/frontend/src/Apps/Schedule.vue b/frontend/src/Apps/Schedule.vue index 8d14c15..7c38cf4 100644 --- a/frontend/src/Apps/Schedule.vue +++ b/frontend/src/Apps/Schedule.vue @@ -22,6 +22,8 @@ const ownSchedule = ref(); const filter = ref("null"); const subFilter = ref("null"); + const focus = ref(); + const focusLessons = ref(); let user; if(log){ @@ -102,6 +104,18 @@ } + function lessonFocus(element){ + focus.value = element; + var lessonsList = []; + for (let element in schedule.value){ + if (schedule.value[element].course.courseId == focus.value.course.courseId){ + lessonsList.push(schedule.value[element]); + } + } + focusLessons.value = lessonsList; + } + + function dateOfMonth(i){ return new Date(currentDate.value.getFullYear(),currentDate.value.getMonth(),i); @@ -109,7 +123,6 @@ function sortSchedule(){ schedule.value =trueSchedule.value.lessons; - console.log(filter.value) if(filter.value =="Teacher"){ schedule.value = sortByTeacher(schedule.value,subFilter.value); scheduleByWeek.value = sundayToTheEnd(matrixFromList(schedule.value,mondayOfWeek.value)); @@ -136,6 +149,10 @@ value = 1; counter=0; } + + if(focus.value != null){ + lessonFocus(focus.value) + } } function sortByType(lessons,type){ @@ -161,7 +178,7 @@ } const matrix = []; for (let element in lessons){ - if(lessons[element].course.title == course.title){ + if(lessons[element].course.courseId == course.courseId){ matrix.push(lessons[element]) } } @@ -185,7 +202,7 @@ async function changeSchedule(){ schedule.value =trueSchedule.value.lessons; curriculum.value = trueSchedule.value.curriculum; - + scheduleByWeek.value = sundayToTheEnd(matrixFromList(schedule.value,mondayOfWeek.value)); month.value = monthFromList(schedule.value,currentDate.value.getMonth()); value = 1; @@ -193,6 +210,8 @@ courses.value = (await getcurriculum(curriculum.value.curriculumId)).courses; filter.value = "null"; subFilter.value = "null" + focus.value = null; + focusLessons.value = null; } function changeWeek(i){ @@ -271,13 +290,14 @@