1
0
forked from PGL/Clyde

Requests Functionnal

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

View File

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

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

View File

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

View File

@ -83,7 +83,7 @@ async function setMoreInfos(item){
</select>
<button @click="AcceptMod = !AcceptMod;upPage(item.id,{local: chosenLocal, state:'Accepted'})"></button>
</div>
<template v-if="moreInfosMod" v-for="key,value in moreInfos">
<template v-if="moreInfosMod" v-for="(key,value) in moreInfos">
<div class="container" v-if="key != null" style="align-self:center;">
<div style="margin:0 auto 0 auto">

View File

@ -64,15 +64,15 @@ const pattern = {
const patternRequest ={
"user": user,
"user": user.regNo,
"state": "Pending",
"requestType": null,
"requestType": 0,
"lessonId":null,
"lessonType":null,
"lessonStart":null,
"lessonEnd":null,
"color":null,
"course":null,}
"course":0,}
const toModify = ref(Object.assign({}, pattern));
const requestBuffer = ref(Object.assign({},patternRequest));
@ -90,6 +90,7 @@ async function createLessonRequest(){
//modify
requestBuffer.value.color = colors[toModify.value.lessonType] ;
requestBuffer.value.requestType = requestType.value;
requestBuffer.value.course = toModify.value.course;
let start = createLessonEvent(toModify.value.day,toModify.value.lessonStart)
let end = createLessonEvent(toModify.value.day,toModify.value.lessonEnd)
for (let element in toModify.value){
@ -103,8 +104,9 @@ async function createLessonRequest(){
requestBuffer.value.lessonEnd = end;
}
}
}
else if(requestType.value === 2) {
else if(requestType.value === 2 || requestType.value === 1) {
//delete
requestBuffer.value.lessonId = editElementID;
requestBuffer.value.requestType = requestType.value;
@ -136,7 +138,7 @@ async function askChanges(i){
<div style="margin-bottom:20px;">
Lesson :
<select v-if="curriculum != null" v-model="toModify.course">
<option v-for="item in courses" :value='item'>{{item.title}}</option>
<option v-for="item in courses" :value='item.courseId'>{{item.title}}</option>
</select>
</div>
<div style="margin-bottom:20px;">
@ -160,7 +162,7 @@ async function askChanges(i){
<button class="create" @click="createMod=!createMod; askChanges(1);"> {{i18n("courses.confirm")}} </button>
<button class="create" @click="createMod=!createMod; askChanges(0);"> {{i18n("courses.confirm")}} </button>
<button style="float:right;" @click="createMod=!createMod">{{i18n("courses.back")}}</button>
</form>
</div>
@ -174,7 +176,7 @@ async function askChanges(i){
</button>
</div>
<div v-else>
<button @click="askChanges(0);"> {{i18n("courses.confirm")}} </button>
<button @click="askChanges(1);"> {{i18n("courses.confirm")}} </button>
<button @click="editElementID= '';"> {{i18n("courses.back")}} </button>
</div>
<div class="listElement">

View File

@ -15,6 +15,8 @@ export async function createRequest(request){
}
export async function changeRequestState(id, infos){
console.log(infos)
console.log(await getLessonRequest(id))
return restPatch("/requests/lessonRequest/" + id, infos);
}