change schedule Curriculum and own schedule
This commit is contained in:
		@ -44,8 +44,10 @@ public class LessonController {
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/lessons/owned")
 | 
			
		||||
    public ResponseEntity<Iterable<HashMap<String,Object>>> 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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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<Map<String, Object>> 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<Iterable<Map<String , Object>>> findAllSchedule(){
 | 
			
		||||
 | 
			
		||||
@ -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, Long> {
 | 
			
		||||
 | 
			
		||||
    Lesson findById(long id);
 | 
			
		||||
 | 
			
		||||
    @Query("select l from Lesson l where l.course.owner = ?1")
 | 
			
		||||
    Iterable<Lesson> findAllOwnedLesson(User teacher);
 | 
			
		||||
    @Query("select l from Lesson l where l.course = ?1")
 | 
			
		||||
    Iterable<Lesson> findLessonByCourse(Course course);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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<Lesson> findAll(){return lessonRepo.findAll();}
 | 
			
		||||
 | 
			
		||||
    public Iterable<Lesson> findAllOwnedLesson(User teacher){
 | 
			
		||||
        return lessonRepo.findAllOwnedLesson(teacher);
 | 
			
		||||
        ArrayList<Lesson> toReturn = new ArrayList<>();
 | 
			
		||||
        ArrayList<Course> coursesOwned = (ArrayList<Course>) courseRepo.findAllOwnedCoures(teacher);
 | 
			
		||||
        for (Course element : coursesOwned) {
 | 
			
		||||
            for(Lesson lesson : lessonRepo.findLessonByCourse(element))
 | 
			
		||||
            toReturn.add(lesson);
 | 
			
		||||
        }
 | 
			
		||||
        return toReturn;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean modifyData(long id, Map<String ,Object> updates, Role role){
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user