From 95ef4023d6f23fbf8914d3127c4154d549b940c2 Mon Sep 17 00:00:00 2001 From: Wawilski Date: Wed, 10 Apr 2024 20:22:07 +0200 Subject: [PATCH] change schedule Curriculum and own schedule --- .../Clyde/EndPoints/LessonController.java | 6 +- .../Clyde/EndPoints/ScheduleController.java | 15 +- .../Clyde/Repositories/LessonRepository.java | 6 +- .../Clyde/Services/LessonService.java | 16 ++- frontend/src/Apps/Schedule.vue | 128 +++++++++++++----- frontend/src/rest/lessonSchedule.js | 9 +- frontend/src/rest/scheduleRest.js | 4 + frontend/src/scheduleFunctions.js | 3 +- 8 files changed, 142 insertions(+), 45 deletions(-) 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 bd8bfb5..81be68a 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonController.java @@ -44,8 +44,10 @@ public class LessonController { @GetMapping("/lessons/owned") public ResponseEntity>> getOwnedLessons(@RequestHeader("Authorization") String token){ - if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token)) - return new UnauthorizedResponse<>(null); + 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); } 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 51cbcc1..5ee22cc 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScheduleController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScheduleController.java @@ -8,6 +8,8 @@ import ovh.herisson.Clyde.Services.AuthenticatorService; import ovh.herisson.Clyde.Services.ScheduleLessonService; import ovh.herisson.Clyde.Services.ScheduleService; import ovh.herisson.Clyde.Services.UserCurriculumService; +import ovh.herisson.Clyde.Services.CurriculumService; +import ovh.herisson.Clyde.Tables.Curriculum; import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.Schedule; @@ -20,15 +22,18 @@ public class ScheduleController { private final ScheduleService scheduleServ; private final UserCurriculumService userCurriculumService; + + private final CurriculumService curriculumServ; private final AuthenticatorService authServ; private final ScheduleLessonService scheduleLessonServ; - public ScheduleController(ScheduleService scheduleServ, UserCurriculumService userCurriculumService, AuthenticatorService authServ, ScheduleLessonService scheduleLessonServ) { + public ScheduleController(ScheduleService scheduleServ, UserCurriculumService userCurriculumService, AuthenticatorService authServ, ScheduleLessonService scheduleLessonServ, CurriculumService curriculumServ) { this.scheduleServ = scheduleServ; this.userCurriculumService = userCurriculumService; this.authServ = authServ; this.scheduleLessonServ = scheduleLessonServ; + this.curriculumServ = curriculumServ; } @GetMapping("/schedule/{id}") @@ -50,6 +55,14 @@ public class ScheduleController { return new ResponseEntity<>(HttpStatus.BAD_REQUEST); return new ResponseEntity<>(scheduleLessonServ.getDepthScheduleBySchedule(schedule),HttpStatus.OK); } + + @GetMapping("/schedule/curriculum/{id}") + public ResponseEntity> findCurriculumSchedule(@PathVariable Long id){ + Schedule schedule = scheduleLessonServ.getScheduleByCurriculum(curriculumServ.findById(id)); + if(schedule == null) + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + return new ResponseEntity<>(scheduleLessonServ.getDepthScheduleBySchedule(schedule),HttpStatus.OK); + } @GetMapping("/schedules") public ResponseEntity>> findAllSchedule(){ diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/LessonRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/LessonRepository.java index eae64da..4638085 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/LessonRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/LessonRepository.java @@ -2,13 +2,13 @@ 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.User; public interface LessonRepository extends CrudRepository { Lesson findById(long id); - @Query("select l from Lesson l where l.course.owner = ?1") - Iterable findAllOwnedLesson(User teacher); + @Query("select l from Lesson l where l.course = ?1") + Iterable findLessonByCourse(Course course); } 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 5b3c13d..0eceb43 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java @@ -1,17 +1,23 @@ package ovh.herisson.Clyde.Services; import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.Repositories.CourseRepository; import ovh.herisson.Clyde.Repositories.LessonRepository; +import ovh.herisson.Clyde.Tables.Course; import ovh.herisson.Clyde.Tables.Lesson; import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.User; + +import java.util.ArrayList; import java.util.Map; @Service public class LessonService { private final LessonRepository lessonRepo; - public LessonService(LessonRepository lessonRepo){ + private final CourseRepository courseRepo; + public LessonService(LessonRepository lessonRepo, CourseRepository courseRepo){ this.lessonRepo = lessonRepo; + this.courseRepo = courseRepo; } public Lesson save(Lesson lesson){ @@ -23,7 +29,13 @@ public class LessonService { public Iterable findAll(){return lessonRepo.findAll();} public Iterable findAllOwnedLesson(User teacher){ - return lessonRepo.findAllOwnedLesson(teacher); + ArrayList toReturn = new ArrayList<>(); + ArrayList coursesOwned = (ArrayList) courseRepo.findAllOwnedCoures(teacher); + for (Course element : coursesOwned) { + for(Lesson lesson : lessonRepo.findLessonByCourse(element)) + toReturn.add(lesson); + } + return toReturn; } public boolean modifyData(long id, Map updates, Role role){ diff --git a/frontend/src/Apps/Schedule.vue b/frontend/src/Apps/Schedule.vue index 8168320..6b788e8 100644 --- a/frontend/src/Apps/Schedule.vue +++ b/frontend/src/Apps/Schedule.vue @@ -1,12 +1,49 @@ diff --git a/frontend/src/rest/lessonSchedule.js b/frontend/src/rest/lessonSchedule.js index ec6cb56..154b0df 100644 --- a/frontend/src/rest/lessonSchedule.js +++ b/frontend/src/rest/lessonSchedule.js @@ -39,13 +39,14 @@ export async function getLesson(id){ * - teacher * - Assistants */ -export async function getLessons(role){ - if(role==="Teacher"){ - return restGet("/lessons/owned") - } +export async function getLessons(){ return restGet("/lessons") } +export async function getOwnedLessons(){ + return restGet("/lessons/owned") + +} /** * Change the options of a course diff --git a/frontend/src/rest/scheduleRest.js b/frontend/src/rest/scheduleRest.js index c3783d0..d7abca8 100644 --- a/frontend/src/rest/scheduleRest.js +++ b/frontend/src/rest/scheduleRest.js @@ -11,3 +11,7 @@ export async function getOwnSchedule(){ export async function createSchedule(curriculum) { return restPost('/schedule',{curriculum : curriculum}) } + +export async function getCurriculumSchedule(id){ + return restGet('/schedule/curriculum/' + id) +} diff --git a/frontend/src/scheduleFunctions.js b/frontend/src/scheduleFunctions.js index 02c9539..0db5e75 100644 --- a/frontend/src/scheduleFunctions.js +++ b/frontend/src/scheduleFunctions.js @@ -67,11 +67,12 @@ } export function monthFromList(list,month){ + console.log(month) + console.log(list) const beginning = getFirstDay(month); const matrix = new Array(lastDateOfMonth(month)) for (let i = 0; i < matrix.length; i++) { matrix[i] = []; - } for(let key in list){ const temp = list[key];