1
0
forked from PGL/Clyde

Requests Functionnal

This commit is contained in:
2024-04-19 23:59:30 +02:00
parent bd1c236635
commit 0ffc8077db
8 changed files with 85 additions and 29 deletions

View File

@ -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) {

View File

@ -60,6 +60,7 @@ public class LessonService {
break;
case "courseId":
target.setCourse(courseRepo.findById((int) entry.getValue()));
break;
}
}

View File

@ -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;
}