Requests Functionnal
This commit is contained in:
		@ -59,10 +59,13 @@ public class LessonRequestsController {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/requests/lessonRequest")
 | 
			
		||||
    public ResponseEntity<Map<String, Object>> makeRequest(@RequestBody LessonChangesRequest lessonRequest){
 | 
			
		||||
        System.out.println(lessonRequest.getLesson());
 | 
			
		||||
        System.out.println(lessonRequest.getLessonEnd());
 | 
			
		||||
        LessonChangesRequest lessonChangesRequest = lessonRequestServ.save(lessonRequest);
 | 
			
		||||
    public ResponseEntity<Map<String, Object>> makeRequest(@RequestHeader("Authorization") String token, @RequestBody Map<String,Object> lessonRequestInfos){
 | 
			
		||||
        if(authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
        LessonChangesRequest lessonChangesRequest = lessonRequestServ.createLessonRequest(lessonRequestInfos);
 | 
			
		||||
        LessonChangesRequest createdRequest = lessonRequestServ.save(lessonChangesRequest);
 | 
			
		||||
        if(createdRequest == null)
 | 
			
		||||
            return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
 | 
			
		||||
        return new ResponseEntity<>(ProtectionService.lessonRequestWithoutPassword(lessonChangesRequest),HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -98,13 +101,13 @@ public class LessonRequestsController {
 | 
			
		||||
            infos.put("lessonStart", lessonRequest.getLessonStart());
 | 
			
		||||
            infos.put("lessonEnd", lessonRequest.getLessonEnd());
 | 
			
		||||
            infos.put("lessonType",lessonRequest.getLessonType());
 | 
			
		||||
            if(!lessonRequestServ.modifyChangeRequestState(infos,lessonRequest.getLesson(),state))
 | 
			
		||||
            if(!lessonRequestServ.modifyChangeRequestState(infos,lessonRequest.getLessonId(),state))
 | 
			
		||||
                return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
 | 
			
		||||
            lessonRequest.setState(state);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else{
 | 
			
		||||
            lessonRequestServ.modifyDeleleRequest(lessonRequest, state);
 | 
			
		||||
            lessonRequestServ.modifyDeleteRequest(lessonRequest, state);
 | 
			
		||||
        }
 | 
			
		||||
        lessonRequestServ.save(lessonRequest);
 | 
			
		||||
        return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,6 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.*;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.*;
 | 
			
		||||
 | 
			
		||||
import java.sql.SQLOutput;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
@ -23,10 +22,14 @@ public class LessonRequestService {
 | 
			
		||||
 | 
			
		||||
    private final ScheduleLessonService scheduleLessonService;
 | 
			
		||||
 | 
			
		||||
    private final UserService userServ;
 | 
			
		||||
 | 
			
		||||
    private final CourseRepository courseRepository;
 | 
			
		||||
    public LessonRequestService(LessonChangesRequestRepository lessonChangesRepo,
 | 
			
		||||
                                UserRepository userRepo, LessonRepository lessonRepo,
 | 
			
		||||
                                LessonService lessonServ, ScheduleLessonRepository scheduleLessonRepo, ScheduleRepository scheduleRepository, ScheduleLessonService scheduleLessonService, CourseRepository courseRepository) {
 | 
			
		||||
                                LessonService lessonServ, ScheduleLessonRepository scheduleLessonRepo,
 | 
			
		||||
                                ScheduleRepository scheduleRepository, ScheduleLessonService scheduleLessonService,
 | 
			
		||||
                                UserService userServ, CourseRepository courseRepository) {
 | 
			
		||||
        this.lessonChangesRepo = lessonChangesRepo;
 | 
			
		||||
        this.userRepo = userRepo;
 | 
			
		||||
        this.lessonRepo = lessonRepo;
 | 
			
		||||
@ -34,6 +37,7 @@ public class LessonRequestService {
 | 
			
		||||
        this.scheduleLessonRepo = scheduleLessonRepo;
 | 
			
		||||
        this.scheduleRepository = scheduleRepository;
 | 
			
		||||
        this.scheduleLessonService = scheduleLessonService;
 | 
			
		||||
        this.userServ = userServ;
 | 
			
		||||
        this.courseRepository = courseRepository;
 | 
			
		||||
    }
 | 
			
		||||
    public Iterable<LessonChangesRequest> findOwnRequests(User user){
 | 
			
		||||
@ -54,13 +58,14 @@ public class LessonRequestService {
 | 
			
		||||
            Course course = courseRepository.findById(lessonRequest.getCourse().getCourseID());
 | 
			
		||||
            if(courseRepository.findById(lessonRequest.getCourse().getCourseID())==null|| local == null){
 | 
			
		||||
                return false;}
 | 
			
		||||
            Lesson lesson = new Lesson(
 | 
			
		||||
                    course,
 | 
			
		||||
                    lessonRequest.getLessonStart(),
 | 
			
		||||
                    lessonRequest.getLessonEnd(),
 | 
			
		||||
                    lessonRequest.getColor(),
 | 
			
		||||
                    local,
 | 
			
		||||
                    lessonRequest.getLessonType());
 | 
			
		||||
            Lesson lesson = new Lesson();
 | 
			
		||||
            lesson.setCourse(course);
 | 
			
		||||
            lesson.setLessonStart(lessonRequest.getLessonStart());
 | 
			
		||||
            lesson.setLessonEnd(lessonRequest.getLessonEnd());
 | 
			
		||||
            lesson.setColor(lessonRequest.getColor());
 | 
			
		||||
            lesson.setLocal(local);
 | 
			
		||||
            lesson.setLessonType(lessonRequest.getLessonType());
 | 
			
		||||
 | 
			
		||||
            lesson = lessonRepo.save(lesson);
 | 
			
		||||
            scheduleLessonService.saveToAllSchedule(lesson);
 | 
			
		||||
            }
 | 
			
		||||
@ -71,7 +76,7 @@ public class LessonRequestService {
 | 
			
		||||
 | 
			
		||||
    public boolean modifyChangeRequestState(Map<String, Object> updates, long lessonId,RequestState state){
 | 
			
		||||
        if(state == RequestState.Accepted){
 | 
			
		||||
            System.out.println(updates.toString());
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            Lesson lesson = lessonServ.findById(lessonId);
 | 
			
		||||
            return lessonServ.modifyData(lesson.getLessonID(),updates);
 | 
			
		||||
@ -79,12 +84,52 @@ public class LessonRequestService {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void modifyDeleleRequest(LessonChangesRequest lessonChangesRequest, RequestState state){
 | 
			
		||||
    public void modifyDeleteRequest(LessonChangesRequest lessonChangesRequest, RequestState state){
 | 
			
		||||
        if(state == RequestState.Accepted){
 | 
			
		||||
            lessonServ.delete(lessonServ.findById(lessonChangesRequest.getLesson()));
 | 
			
		||||
            lessonServ.delete(lessonServ.findById(lessonChangesRequest.getLessonId()));
 | 
			
		||||
            lessonChangesRequest.setState(state);}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public LessonChangesRequest createLessonRequest(Map<String,Object> lessonInfos) {
 | 
			
		||||
        LessonChangesRequest target = new LessonChangesRequest();
 | 
			
		||||
 | 
			
		||||
        for (Map.Entry<String, Object> entry : lessonInfos.entrySet()) {
 | 
			
		||||
            System.out.println(entry.toString());
 | 
			
		||||
            if(entry.getValue() != null){
 | 
			
		||||
                switch (entry.getKey()) {
 | 
			
		||||
                    case "requestType":
 | 
			
		||||
                    target.setRequestType((int) entry.getValue());
 | 
			
		||||
                    break;
 | 
			
		||||
                    case "lessonStart":
 | 
			
		||||
                        target.setLessonStart((String) entry.getValue());
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "lessonEnd":
 | 
			
		||||
                        target.setLessonEnd((String) entry.getValue());
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "color":
 | 
			
		||||
                        target.setColor((String) entry.getValue());
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "user":
 | 
			
		||||
                        target.setUser(userServ.getUserById((int) entry.getValue()));
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "lessonType":
 | 
			
		||||
                        target.setLessonType((String) entry.getValue());
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "course":
 | 
			
		||||
                        target.setCourse(courseRepository.findById((int) entry.getValue()));
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "lessonId":
 | 
			
		||||
                        target.setLessonId((int) entry.getValue());
 | 
			
		||||
                        break;
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        target.setState(RequestState.Pending);
 | 
			
		||||
        return target;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public void delete (LessonChangesRequest toDelete) {
 | 
			
		||||
 | 
			
		||||
@ -60,6 +60,7 @@ public class LessonService {
 | 
			
		||||
                    break;
 | 
			
		||||
                case "courseId":
 | 
			
		||||
                    target.setCourse(courseRepo.findById((int) entry.getValue()));
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -128,7 +128,7 @@ public class ProtectionService {
 | 
			
		||||
        toReturn.put("user", userWithoutPassword(lessonRequest.getUser()));
 | 
			
		||||
        toReturn.put("requestType", lessonRequest.getRequestType());
 | 
			
		||||
        toReturn.put("state", lessonRequest.getState());
 | 
			
		||||
        toReturn.put("lessonId",lessonRequest.getLesson());
 | 
			
		||||
        toReturn.put("lessonId",lessonRequest.getLessonId());
 | 
			
		||||
 | 
			
		||||
        return toReturn;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -25,7 +25,7 @@ public class LessonChangesRequest {
 | 
			
		||||
    private String lessonEnd;
 | 
			
		||||
 | 
			
		||||
    private String color;
 | 
			
		||||
    @OneToOne
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name ="Course")
 | 
			
		||||
    private Course course;
 | 
			
		||||
 | 
			
		||||
@ -64,7 +64,7 @@ public class LessonChangesRequest {
 | 
			
		||||
        return user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public long getLesson(){
 | 
			
		||||
    public long getLessonId(){
 | 
			
		||||
        return lessonId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -123,6 +123,9 @@ public class LessonChangesRequest {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public void setLessonId(long lessonId) {
 | 
			
		||||
        this.lessonId = lessonId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCourse(Course course){
 | 
			
		||||
        this.course = course;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user