Schedule management
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -44,9 +44,8 @@ public class LessonController {
|
||||
|
||||
@GetMapping("/lessons/owned")
|
||||
public ResponseEntity<Iterable<HashMap<String,Object>>> 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);
|
||||
|
@ -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<String> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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){
|
||||
|
@ -17,6 +17,9 @@ public enum Applications {
|
||||
// teachers and Secretary authorization
|
||||
ManageCourses,
|
||||
UsersList,
|
||||
|
||||
//Secretary authorization
|
||||
ManageSchedules,
|
||||
|
||||
// InscriptionService authorization
|
||||
Inscription,
|
||||
|
@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user