From aa3e1cb8684716c8413f38c39f8163802a61661d Mon Sep 17 00:00:00 2001 From: Wawilski Date: Sun, 7 Apr 2024 14:33:51 +0200 Subject: [PATCH] backend Schedule --- .../Clyde/EndPoints/CourseController.java | 2 - .../Clyde/EndPoints/LessonController.java | 75 ++++++++++++++++++ .../Clyde/EndPoints/MockController.java | 45 ++++++++++- .../Clyde/EndPoints/ScheduleController.java | 66 ++++++++++++++++ .../Clyde/Repositories/LessonRepository.java | 14 ++++ .../ScheduleLessonRepository.java | 23 ++++++ .../Repositories/ScheduleRepository.java | 9 +++ .../Clyde/Services/LessonService.java | 59 ++++++++++++++ .../Clyde/Services/ProtectionService.java | 26 +++++++ .../Clyde/Services/ScheduleLessonService.java | 75 ++++++++++++++++++ .../Clyde/Services/ScheduleService.java | 24 ++++++ .../ovh/herisson/Clyde/Tables/Lesson.java | 77 +++++++++++++++++++ .../ovh/herisson/Clyde/Tables/Schedule.java | 33 ++++++++ .../herisson/Clyde/Tables/ScheduleLesson.java | 53 +++++++++++++ frontend/src/Apps/Schedule.vue | 9 ++- frontend/src/rest/courses.js | 2 - frontend/src/rest/lessonSchedule.js | 65 ++++++++++++++++ frontend/src/rest/scheduleRest.js | 13 ++++ .../src/{schedule.js => scheduleFunctions.js} | 0 19 files changed, 662 insertions(+), 8 deletions(-) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonController.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScheduleController.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/LessonRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleLessonRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleLessonService.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleService.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/Lesson.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/Schedule.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/ScheduleLesson.java create mode 100644 frontend/src/rest/lessonSchedule.js create mode 100644 frontend/src/rest/scheduleRest.js rename frontend/src/{schedule.js => scheduleFunctions.js} (100%) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java index d5e87a8..40b1e0f 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java @@ -74,8 +74,6 @@ public class CourseController { public ResponseEntity> postCourse(@RequestHeader("Authorization") String token, @RequestBody Course course) { - System.out.println(course); - System.out.println(token); if (authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)) return new UnauthorizedResponse<>(null); diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonController.java new file mode 100644 index 0000000..bd8bfb5 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LessonController.java @@ -0,0 +1,75 @@ +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.LessonService; +import ovh.herisson.Clyde.Services.ProtectionService; +import ovh.herisson.Clyde.Tables.Lesson; +import ovh.herisson.Clyde.Tables.Role; + +import java.util.HashMap; +import java.util.Map; + +@RestController +@CrossOrigin(originPatterns = "*", allowCredentials = "true") +public class LessonController { + private final LessonService lessonServ; + + private final AuthenticatorService authServ; + + public LessonController(LessonService lessonServ, AuthenticatorService authServ) { + this.lessonServ = lessonServ; + this.authServ = authServ; + } + + @GetMapping("/lesson/{id}") + public ResponseEntity> getLesson(@PathVariable long id){ + Lesson lesson = lessonServ.findById(id); + + if(lesson == null) + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + + return new ResponseEntity<>(ProtectionService.lessonWithoutPassword(lesson),HttpStatus.OK); + } + + @GetMapping("/lessons") + public ResponseEntity>> getAllLessons(@RequestHeader("Authorization") String token){ + if(authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token)) + return new UnauthorizedResponse<>(null); + return new ResponseEntity<>(ProtectionService.lessonsWithoutPassword(lessonServ.findAll()),HttpStatus.OK); + } + + @GetMapping("/lessons/owned") + public ResponseEntity>> getOwnedLessons(@RequestHeader("Authorization") String token){ + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token)) + return new UnauthorizedResponse<>(null); + return new ResponseEntity<>(ProtectionService.lessonsWithoutPassword(lessonServ.findAllOwnedLesson(authServ.getUserFromToken(token))),HttpStatus.OK); + } + + + @PostMapping("/lesson") + public ResponseEntity> postLesson(@RequestHeader("Authorization")String token, + @RequestBody Lesson lesson){ + 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); + } + + @PatchMapping("/lesson/{id}") + public ResponseEntity patchLesson(@RequestHeader("Authorization") String token, + @RequestBody Map updates, + @PathVariable long id){ + if(authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token)) + return new UnauthorizedResponse<>(null); + if(!lessonServ.modifyData(id, updates, authServ.getUserFromToken(token).getRole())) + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + 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 0b7a1b4..779a1f0 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -24,10 +24,15 @@ public class MockController { public final CourseService courseService; public final InscriptionService inscriptionService; + + public final LessonService lessonService; + public final ScheduleService scheduleService; + public final ScheduleLessonService scheduleLessonService; + ArrayList mockUsers; - public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService){ + public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService, LessonService lessonService, ScheduleService scheduleService, ScheduleLessonService scheduleLessonService){ this.tokenRepo = tokenRepo; this.userRepo = userRepo; this.tokenService = tokenService; @@ -35,6 +40,9 @@ public class MockController { this.curriculumService = curriculumService; this.courseService = courseService; this.inscriptionService = inscriptionService; + this.lessonService = lessonService; + this.scheduleService = scheduleService; + this.scheduleLessonService = scheduleLessonService; } /** Saves an example of each user type by : @@ -95,7 +103,40 @@ public class MockController { InscriptionRequest inscriptionRequest = new InscriptionRequest("helen","prenom","non","helen@gmail.com","america",new Date(),(long) 1,RequestState.Pending,"yes.png","password"); inscriptionService.save(inscriptionRequest); - + + + //Schedule part + + Lesson lesson_0_progra1 = new Lesson(progra1, "Mon Apr 01 2024 08:15", "Mon Apr 01 2024 10:15","rgb(0,50,100)","A0B2"); + Lesson lesson_0_chemistry1 = new Lesson(chemistry1, "Wed Mar 27 2024 08:15", "Wed Mar 27 2024 09:15","rgb(100,50,0)","A0B2"); + Lesson lesson_0_psycho1 = new Lesson(psycho1, "Sun Mar 24 2024 10:30 ","Sun Mar 24 2024 12:30 ","rgb(100,50,100)", "A0B2"); + Lesson lesson_1_progra1 = new Lesson(progra1, "Mon Apr 02 2024 13:30", "Mon Apr 02 2024 15:30","rgb(0,50,100)","A0B2"); + Lesson lesson_0_commun = new Lesson(commun, "Mon Apr 01 2024 10:30", "Mon Apr 01 2024 12:30","rgb(0,50,100)","A0B2"); + + Schedule infoBab1Schedule = new Schedule(infoBab1); + Schedule chemistryBab1Schedule = new Schedule(chemistryBab1); + Schedule psychoBab1Schedule = new Schedule(psychologyBab1); + + scheduleService.save(infoBab1Schedule); + scheduleService.save(chemistryBab1Schedule); + scheduleService.save(psychoBab1Schedule); + + lessonService.save(lesson_0_progra1); + lessonService.save(lesson_0_chemistry1); + lessonService.save(lesson_0_commun); + lessonService.save(lesson_0_psycho1); + lessonService.save(lesson_1_progra1); + + scheduleLessonService.save(new ScheduleLesson(infoBab1Schedule,lesson_0_progra1)); + scheduleLessonService.save(new ScheduleLesson(infoBab1Schedule,lesson_1_progra1)); + scheduleLessonService.save(new ScheduleLesson(infoBab1Schedule,lesson_0_commun)); + + scheduleLessonService.save(new ScheduleLesson(chemistryBab1Schedule,lesson_0_chemistry1)); + scheduleLessonService.save(new ScheduleLesson(chemistryBab1Schedule,lesson_0_commun)); + + scheduleLessonService.save(new ScheduleLesson(psychoBab1Schedule,lesson_0_psycho1)); + scheduleLessonService.save(new ScheduleLesson(psychoBab1Schedule,lesson_0_commun)); + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScheduleController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScheduleController.java new file mode 100644 index 0000000..51cbcc1 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScheduleController.java @@ -0,0 +1,66 @@ +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.ScheduleLessonService; +import ovh.herisson.Clyde.Services.ScheduleService; +import ovh.herisson.Clyde.Services.UserCurriculumService; +import ovh.herisson.Clyde.Tables.Role; +import ovh.herisson.Clyde.Tables.Schedule; + +import java.util.Map; + +@RestController +@CrossOrigin(originPatterns = "*", allowCredentials = "true") +public class ScheduleController { + + private final ScheduleService scheduleServ; + + private final UserCurriculumService userCurriculumService; + private final AuthenticatorService authServ; + + private final ScheduleLessonService scheduleLessonServ; + + public ScheduleController(ScheduleService scheduleServ, UserCurriculumService userCurriculumService, AuthenticatorService authServ, ScheduleLessonService scheduleLessonServ) { + this.scheduleServ = scheduleServ; + this.userCurriculumService = userCurriculumService; + this.authServ = authServ; + this.scheduleLessonServ = scheduleLessonServ; + } + + @GetMapping("/schedule/{id}") + public ResponseEntity> findById(@PathVariable long id){ + Schedule schedule = scheduleServ.findById(id); + + if(schedule == null) + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + return new ResponseEntity<>(scheduleLessonServ.getDepthScheduleBySchedule(schedule),HttpStatus.OK); + } + + + @GetMapping("/schedule") + public ResponseEntity> findSelfSchedule(@RequestHeader("Authorization") String token){ + if(authServ.getUserFromToken(token) == null) + return new UnauthorizedResponse<>(null); + Schedule schedule = scheduleLessonServ.getScheduleByCurriculum(userCurriculumService.findByUser(authServ.getUserFromToken(token))); + if(schedule == null) + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + return new ResponseEntity<>(scheduleLessonServ.getDepthScheduleBySchedule(schedule),HttpStatus.OK); + } + + @GetMapping("/schedules") + public ResponseEntity>> findAllSchedule(){ + return new ResponseEntity<>(scheduleLessonServ.getAllSchedule(),HttpStatus.OK); + } + + @PostMapping("/schedule") + public ResponseEntity postSchedule(@RequestHeader("Authorization") String token, + @RequestBody Schedule schedule){ + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token)) + return new UnauthorizedResponse<>(null); + return new ResponseEntity<>(scheduleServ.save(schedule),HttpStatus.OK); + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/LessonRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/LessonRepository.java new file mode 100644 index 0000000..eae64da --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/LessonRepository.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.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); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleLessonRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleLessonRepository.java new file mode 100644 index 0000000..81fec17 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleLessonRepository.java @@ -0,0 +1,23 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.Curriculum; +import ovh.herisson.Clyde.Tables.Lesson; +import ovh.herisson.Clyde.Tables.Schedule; +import ovh.herisson.Clyde.Tables.ScheduleLesson; + +public interface ScheduleLessonRepository extends CrudRepository { + + @Query("select distinct sl.lesson from ScheduleLesson sl where sl.schedule.curriculum = ?1") + Iterable findLessonByCurriculum(Curriculum curriculum); + + @Query("select distinct sl.schedule from ScheduleLesson sl") + Iterable findDistinctSchedule(); + + @Query("select distinct sl.schedule from ScheduleLesson sl where sl.schedule.curriculum = ?1") + Schedule findScheduleByCurriculum(Curriculum curriculum); + + @Query("select distinct sl.lesson from ScheduleLesson sl where sl.schedule = ?1") + Iterable findLessonBySchedule(Schedule schedule); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleRepository.java new file mode 100644 index 0000000..192fb05 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScheduleRepository.java @@ -0,0 +1,9 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.Schedule; + +public interface ScheduleRepository extends CrudRepository { + + Schedule findById(long id); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java new file mode 100644 index 0000000..5b3c13d --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/LessonService.java @@ -0,0 +1,59 @@ +package ovh.herisson.Clyde.Services; + +import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.Repositories.LessonRepository; +import ovh.herisson.Clyde.Tables.Lesson; +import ovh.herisson.Clyde.Tables.Role; +import ovh.herisson.Clyde.Tables.User; +import java.util.Map; + +@Service +public class LessonService { + private final LessonRepository lessonRepo; + public LessonService(LessonRepository lessonRepo){ + this.lessonRepo = lessonRepo; + } + + public Lesson save(Lesson lesson){ + return lessonRepo.save(lesson); + } + public Lesson findById(long id){ + return lessonRepo.findById(id); + } + public Iterable findAll(){return lessonRepo.findAll();} + + public Iterable findAllOwnedLesson(User teacher){ + return lessonRepo.findAllOwnedLesson(teacher); + } + + public boolean modifyData(long id, Map updates, Role role){ + Lesson target = lessonRepo.findById(id); + + if(target == null || role != Role.Secretary) + return false; + + + for (Map.Entry entry: updates.entrySet()){ + switch (entry.getKey()){ + case "lessonStart": + target.setLessonStart((String) entry.getValue()); + break; + case "lessonEnd": + target.setLessonEnd((String) entry.getValue()); + case "color": + target.setColor((String) entry.getValue()); + break; + case "local": + target.setLocal((String) entry.getValue()); + } + } + lessonRepo.save(target); + return true; + } + + public void delete(Lesson lesson){ + lessonRepo.delete(lesson); + } + + +} 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 44e53a7..1f25dfe 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java @@ -2,6 +2,7 @@ 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 java.util.ArrayList; @@ -69,6 +70,31 @@ public class ProtectionService { } + public static HashMap lessonWithoutPassword(Lesson lesson){ + if(lesson == null) + return null; + + HashMap toReturn = new HashMap<>(); + + toReturn.put("lessonID", lesson.getLessonID()); + toReturn.put("lessonStart", lesson.getLessonStart()); + toReturn.put("lessonEnd", lesson.getLessonEnd()); + toReturn.put("course",courseWithoutPassword(lesson.getCourse())); + toReturn.put("local",lesson.getLocal()); + return toReturn; + } + + public static Iterable> lessonsWithoutPassword(Iterable lessons){ + ArrayList> toReturn = new ArrayList<>(); + + for (Lesson l: lessons){ + toReturn.add(ProtectionService.lessonWithoutPassword(l)); + } + + return toReturn; + + } + public static Map requestWithoutPassword(InscriptionRequest inscriptionRequest) { diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleLessonService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleLessonService.java new file mode 100644 index 0000000..53e15ba --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleLessonService.java @@ -0,0 +1,75 @@ +package ovh.herisson.Clyde.Services; + +import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.Repositories.LessonRepository; +import ovh.herisson.Clyde.Repositories.ScheduleLessonRepository; +import ovh.herisson.Clyde.Repositories.ScheduleRepository; +import ovh.herisson.Clyde.Tables.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +@Service +public class ScheduleLessonService { + + private final ScheduleLessonRepository scheduleLessonRepo; + + private final LessonRepository lessonRepo; + private final ScheduleRepository scheduleRepo; + public ScheduleLessonService(ScheduleLessonRepository scheduleLessonRepo, LessonRepository lessonRepo, ScheduleRepository scheduleRepo) { + this.scheduleLessonRepo = scheduleLessonRepo; + this.lessonRepo = lessonRepo; + this.scheduleRepo = scheduleRepo; + } + + public void save(ScheduleLesson scheduleLesson){ + scheduleLessonRepo.save(scheduleLesson); + } + + public Schedule getScheduleByCurriculum(Curriculum curriculum){ + return scheduleLessonRepo.findScheduleByCurriculum(curriculum); + } + + public Map getDepthScheduleByCurriculum(Curriculum curriculum){ + if(curriculum == null) + return null; + + HashMap toReturn = new HashMap<>(); + ArrayList> lessons = new ArrayList<>(); + Iterable foundLessons = scheduleLessonRepo.findLessonByCurriculum(curriculum); + + for (Lesson l: foundLessons){ + lessons.add(ProtectionService.lessonWithoutPassword(l)); + } + toReturn.put("lessons",lessons); + toReturn.put("scheduleId" , scheduleLessonRepo.findScheduleByCurriculum(curriculum).getScheduleID()); + return toReturn; + } + + public Map getDepthScheduleBySchedule(Schedule schedule){ + if(schedule == null) + return null; + + HashMap toReturn = new HashMap<>(); + ArrayList> lessons = new ArrayList<>(); + Iterable foundLessons = scheduleLessonRepo.findLessonByCurriculum(schedule.getCurriculum()); + + for (Lesson l: foundLessons){ + lessons.add(ProtectionService.lessonWithoutPassword(l)); + } + toReturn.put("lessons",lessons); + toReturn.put("scheduleId" , schedule.getScheduleID()); + return toReturn; + } + + public Iterable> getAllSchedule(){ + ArrayList> toReturn = new ArrayList<>(); + + for (Schedule schedule: scheduleRepo.findAll()){ + toReturn.add(getDepthScheduleBySchedule(schedule)); + } + return toReturn; + } + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleService.java new file mode 100644 index 0000000..950261c --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/ScheduleService.java @@ -0,0 +1,24 @@ +package ovh.herisson.Clyde.Services; + +import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.Repositories.ScheduleRepository; +import ovh.herisson.Clyde.Tables.Schedule; + +@Service +public class ScheduleService { + private final ScheduleRepository scheduleRepo; + public ScheduleService(ScheduleRepository scheduleRepo) { + this.scheduleRepo = scheduleRepo; + } + public Schedule save(Schedule schedule){ + return scheduleRepo.save(schedule); + } + public Schedule findById(long id){ + return scheduleRepo.findById(id); + } + public void delete(Schedule schedule){ + scheduleRepo.delete(schedule); + } + +} + diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Lesson.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Lesson.java new file mode 100644 index 0000000..00a693c --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Lesson.java @@ -0,0 +1,77 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + + +@Entity +public class Lesson { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int lessonID; + + @ManyToOne + @JoinColumn(name= "Course") + private Course course; + + private String lessonStart; + + private String lessonEnd; + private String color; + + private String local; + + public Lesson(Course course,String start, String end ,String color,String local){ + this.lessonEnd = end; + this.course = course; + this.lessonStart = start; + this.color = color; + this.local = local; + } + + public Lesson() { + } + + public int getLessonID(){ + return lessonID; + } + + public void setCourse(Course course) { + this.course = course; + } + + public Course getCourse(){ + return course; + } + + public String getLessonStart(){ + return lessonStart; + } + + public String getLessonEnd() { + return lessonEnd; + } + + public String getColor(){ + return color; + } + + public String getLocal() { + return local; + } + + public void setLessonStart(String start){ + this.lessonStart = start; + } + + public void setLessonEnd(String lessonEnd) { + this.lessonEnd = lessonEnd; + } + + public void setColor(String color){ + this.color = color; + } + + public void setLocal(String local){ + this.local = local; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Schedule.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Schedule.java new file mode 100644 index 0000000..993c38c --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Schedule.java @@ -0,0 +1,33 @@ + +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +@Entity +public class Schedule { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int scheduleID; + + @OneToOne + @JoinColumn(name = "Curriculum") + private Curriculum curriculum; + + public Schedule(Curriculum curriculum){ + this.curriculum = curriculum; + } + + public Schedule() {} + + + public int getScheduleID(){ + return scheduleID; +} + + public Curriculum getCurriculum(){ + return curriculum; +} + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/ScheduleLesson.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/ScheduleLesson.java new file mode 100644 index 0000000..3b7b6a4 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/ScheduleLesson.java @@ -0,0 +1,53 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + + + +@Entity +public class ScheduleLesson{ + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "Schedule") + private Schedule schedule; + + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "Lesson") + private Lesson lesson; + + public ScheduleLesson(Schedule schedule,Lesson lesson){ + this.schedule = schedule; + this.lesson = lesson; + } + + public ScheduleLesson() { + } + + public int getID(){ + return id; + } + + public Lesson getLesson(){ + return lesson; + } + + public Schedule getSchedule(){ + return schedule; + } + + public void setLesson(Lesson lesson){ + this.lesson = lesson; + } + + public void setSchedule(Schedule schedule){ + this.schedule = schedule; + } + + +} diff --git a/frontend/src/Apps/Schedule.vue b/frontend/src/Apps/Schedule.vue index 0c3f640..0722d91 100644 --- a/frontend/src/Apps/Schedule.vue +++ b/frontend/src/Apps/Schedule.vue @@ -1,7 +1,12 @@