Requests Functionnal
This commit is contained in:
parent
bd1c236635
commit
0ffc8077db
@ -59,10 +59,13 @@ public class LessonRequestsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/requests/lessonRequest")
|
@PostMapping("/requests/lessonRequest")
|
||||||
public ResponseEntity<Map<String, Object>> makeRequest(@RequestBody LessonChangesRequest lessonRequest){
|
public ResponseEntity<Map<String, Object>> makeRequest(@RequestHeader("Authorization") String token, @RequestBody Map<String,Object> lessonRequestInfos){
|
||||||
System.out.println(lessonRequest.getLesson());
|
if(authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token))
|
||||||
System.out.println(lessonRequest.getLessonEnd());
|
return new UnauthorizedResponse<>(null);
|
||||||
LessonChangesRequest lessonChangesRequest = lessonRequestServ.save(lessonRequest);
|
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);
|
return new ResponseEntity<>(ProtectionService.lessonRequestWithoutPassword(lessonChangesRequest),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,13 +101,13 @@ public class LessonRequestsController {
|
|||||||
infos.put("lessonStart", lessonRequest.getLessonStart());
|
infos.put("lessonStart", lessonRequest.getLessonStart());
|
||||||
infos.put("lessonEnd", lessonRequest.getLessonEnd());
|
infos.put("lessonEnd", lessonRequest.getLessonEnd());
|
||||||
infos.put("lessonType",lessonRequest.getLessonType());
|
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);
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
lessonRequest.setState(state);
|
lessonRequest.setState(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
else{
|
else{
|
||||||
lessonRequestServ.modifyDeleleRequest(lessonRequest, state);
|
lessonRequestServ.modifyDeleteRequest(lessonRequest, state);
|
||||||
}
|
}
|
||||||
lessonRequestServ.save(lessonRequest);
|
lessonRequestServ.save(lessonRequest);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
@ -4,7 +4,6 @@ import org.springframework.stereotype.Service;
|
|||||||
import ovh.herisson.Clyde.Repositories.*;
|
import ovh.herisson.Clyde.Repositories.*;
|
||||||
import ovh.herisson.Clyde.Tables.*;
|
import ovh.herisson.Clyde.Tables.*;
|
||||||
|
|
||||||
import java.sql.SQLOutput;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -23,10 +22,14 @@ public class LessonRequestService {
|
|||||||
|
|
||||||
private final ScheduleLessonService scheduleLessonService;
|
private final ScheduleLessonService scheduleLessonService;
|
||||||
|
|
||||||
|
private final UserService userServ;
|
||||||
|
|
||||||
private final CourseRepository courseRepository;
|
private final CourseRepository courseRepository;
|
||||||
public LessonRequestService(LessonChangesRequestRepository lessonChangesRepo,
|
public LessonRequestService(LessonChangesRequestRepository lessonChangesRepo,
|
||||||
UserRepository userRepo, LessonRepository lessonRepo,
|
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.lessonChangesRepo = lessonChangesRepo;
|
||||||
this.userRepo = userRepo;
|
this.userRepo = userRepo;
|
||||||
this.lessonRepo = lessonRepo;
|
this.lessonRepo = lessonRepo;
|
||||||
@ -34,6 +37,7 @@ public class LessonRequestService {
|
|||||||
this.scheduleLessonRepo = scheduleLessonRepo;
|
this.scheduleLessonRepo = scheduleLessonRepo;
|
||||||
this.scheduleRepository = scheduleRepository;
|
this.scheduleRepository = scheduleRepository;
|
||||||
this.scheduleLessonService = scheduleLessonService;
|
this.scheduleLessonService = scheduleLessonService;
|
||||||
|
this.userServ = userServ;
|
||||||
this.courseRepository = courseRepository;
|
this.courseRepository = courseRepository;
|
||||||
}
|
}
|
||||||
public Iterable<LessonChangesRequest> findOwnRequests(User user){
|
public Iterable<LessonChangesRequest> findOwnRequests(User user){
|
||||||
@ -54,13 +58,14 @@ public class LessonRequestService {
|
|||||||
Course course = courseRepository.findById(lessonRequest.getCourse().getCourseID());
|
Course course = courseRepository.findById(lessonRequest.getCourse().getCourseID());
|
||||||
if(courseRepository.findById(lessonRequest.getCourse().getCourseID())==null|| local == null){
|
if(courseRepository.findById(lessonRequest.getCourse().getCourseID())==null|| local == null){
|
||||||
return false;}
|
return false;}
|
||||||
Lesson lesson = new Lesson(
|
Lesson lesson = new Lesson();
|
||||||
course,
|
lesson.setCourse(course);
|
||||||
lessonRequest.getLessonStart(),
|
lesson.setLessonStart(lessonRequest.getLessonStart());
|
||||||
lessonRequest.getLessonEnd(),
|
lesson.setLessonEnd(lessonRequest.getLessonEnd());
|
||||||
lessonRequest.getColor(),
|
lesson.setColor(lessonRequest.getColor());
|
||||||
local,
|
lesson.setLocal(local);
|
||||||
lessonRequest.getLessonType());
|
lesson.setLessonType(lessonRequest.getLessonType());
|
||||||
|
|
||||||
lesson = lessonRepo.save(lesson);
|
lesson = lessonRepo.save(lesson);
|
||||||
scheduleLessonService.saveToAllSchedule(lesson);
|
scheduleLessonService.saveToAllSchedule(lesson);
|
||||||
}
|
}
|
||||||
@ -71,7 +76,7 @@ public class LessonRequestService {
|
|||||||
|
|
||||||
public boolean modifyChangeRequestState(Map<String, Object> updates, long lessonId,RequestState state){
|
public boolean modifyChangeRequestState(Map<String, Object> updates, long lessonId,RequestState state){
|
||||||
if(state == RequestState.Accepted){
|
if(state == RequestState.Accepted){
|
||||||
System.out.println(updates.toString());
|
|
||||||
|
|
||||||
Lesson lesson = lessonServ.findById(lessonId);
|
Lesson lesson = lessonServ.findById(lessonId);
|
||||||
return lessonServ.modifyData(lesson.getLessonID(),updates);
|
return lessonServ.modifyData(lesson.getLessonID(),updates);
|
||||||
@ -79,12 +84,52 @@ public class LessonRequestService {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void modifyDeleleRequest(LessonChangesRequest lessonChangesRequest, RequestState state){
|
public void modifyDeleteRequest(LessonChangesRequest lessonChangesRequest, RequestState state){
|
||||||
if(state == RequestState.Accepted){
|
if(state == RequestState.Accepted){
|
||||||
lessonServ.delete(lessonServ.findById(lessonChangesRequest.getLesson()));
|
lessonServ.delete(lessonServ.findById(lessonChangesRequest.getLessonId()));
|
||||||
lessonChangesRequest.setState(state);}
|
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) {
|
public void delete (LessonChangesRequest toDelete) {
|
||||||
|
@ -60,6 +60,7 @@ public class LessonService {
|
|||||||
break;
|
break;
|
||||||
case "courseId":
|
case "courseId":
|
||||||
target.setCourse(courseRepo.findById((int) entry.getValue()));
|
target.setCourse(courseRepo.findById((int) entry.getValue()));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ public class ProtectionService {
|
|||||||
toReturn.put("user", userWithoutPassword(lessonRequest.getUser()));
|
toReturn.put("user", userWithoutPassword(lessonRequest.getUser()));
|
||||||
toReturn.put("requestType", lessonRequest.getRequestType());
|
toReturn.put("requestType", lessonRequest.getRequestType());
|
||||||
toReturn.put("state", lessonRequest.getState());
|
toReturn.put("state", lessonRequest.getState());
|
||||||
toReturn.put("lessonId",lessonRequest.getLesson());
|
toReturn.put("lessonId",lessonRequest.getLessonId());
|
||||||
|
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class LessonChangesRequest {
|
|||||||
private String lessonEnd;
|
private String lessonEnd;
|
||||||
|
|
||||||
private String color;
|
private String color;
|
||||||
@OneToOne
|
@ManyToOne
|
||||||
@JoinColumn(name ="Course")
|
@JoinColumn(name ="Course")
|
||||||
private Course course;
|
private Course course;
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ public class LessonChangesRequest {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLesson(){
|
public long getLessonId(){
|
||||||
return lessonId;
|
return lessonId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,6 +123,9 @@ public class LessonChangesRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setLessonId(long lessonId) {
|
||||||
|
this.lessonId = lessonId;
|
||||||
|
}
|
||||||
|
|
||||||
public void setCourse(Course course){
|
public void setCourse(Course course){
|
||||||
this.course = course;
|
this.course = course;
|
||||||
|
@ -83,7 +83,7 @@ async function setMoreInfos(item){
|
|||||||
</select>
|
</select>
|
||||||
<button @click="AcceptMod = !AcceptMod;upPage(item.id,{local: chosenLocal, state:'Accepted'})"></button>
|
<button @click="AcceptMod = !AcceptMod;upPage(item.id,{local: chosenLocal, state:'Accepted'})"></button>
|
||||||
</div>
|
</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 class="container" v-if="key != null" style="align-self:center;">
|
||||||
<div style="margin:0 auto 0 auto">
|
<div style="margin:0 auto 0 auto">
|
||||||
|
@ -64,15 +64,15 @@ const pattern = {
|
|||||||
|
|
||||||
|
|
||||||
const patternRequest ={
|
const patternRequest ={
|
||||||
"user": user,
|
"user": user.regNo,
|
||||||
"state": "Pending",
|
"state": "Pending",
|
||||||
"requestType": null,
|
"requestType": 0,
|
||||||
"lessonId":null,
|
"lessonId":null,
|
||||||
"lessonType":null,
|
"lessonType":null,
|
||||||
"lessonStart":null,
|
"lessonStart":null,
|
||||||
"lessonEnd":null,
|
"lessonEnd":null,
|
||||||
"color":null,
|
"color":null,
|
||||||
"course":null,}
|
"course":0,}
|
||||||
|
|
||||||
const toModify = ref(Object.assign({}, pattern));
|
const toModify = ref(Object.assign({}, pattern));
|
||||||
const requestBuffer = ref(Object.assign({},patternRequest));
|
const requestBuffer = ref(Object.assign({},patternRequest));
|
||||||
@ -90,6 +90,7 @@ async function createLessonRequest(){
|
|||||||
//modify
|
//modify
|
||||||
requestBuffer.value.color = colors[toModify.value.lessonType] ;
|
requestBuffer.value.color = colors[toModify.value.lessonType] ;
|
||||||
requestBuffer.value.requestType = requestType.value;
|
requestBuffer.value.requestType = requestType.value;
|
||||||
|
requestBuffer.value.course = toModify.value.course;
|
||||||
let start = createLessonEvent(toModify.value.day,toModify.value.lessonStart)
|
let start = createLessonEvent(toModify.value.day,toModify.value.lessonStart)
|
||||||
let end = createLessonEvent(toModify.value.day,toModify.value.lessonEnd)
|
let end = createLessonEvent(toModify.value.day,toModify.value.lessonEnd)
|
||||||
for (let element in toModify.value){
|
for (let element in toModify.value){
|
||||||
@ -103,8 +104,9 @@ async function createLessonRequest(){
|
|||||||
requestBuffer.value.lessonEnd = end;
|
requestBuffer.value.lessonEnd = end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(requestType.value === 2) {
|
else if(requestType.value === 2 || requestType.value === 1) {
|
||||||
//delete
|
//delete
|
||||||
requestBuffer.value.lessonId = editElementID;
|
requestBuffer.value.lessonId = editElementID;
|
||||||
requestBuffer.value.requestType = requestType.value;
|
requestBuffer.value.requestType = requestType.value;
|
||||||
@ -136,7 +138,7 @@ async function askChanges(i){
|
|||||||
<div style="margin-bottom:20px;">
|
<div style="margin-bottom:20px;">
|
||||||
Lesson :
|
Lesson :
|
||||||
<select v-if="curriculum != null" v-model="toModify.course">
|
<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>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div style="margin-bottom:20px;">
|
<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>
|
<button style="float:right;" @click="createMod=!createMod">{{i18n("courses.back")}}</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@ -174,7 +176,7 @@ async function askChanges(i){
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<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>
|
<button @click="editElementID= '';"> {{i18n("courses.back")}} </button>
|
||||||
</div>
|
</div>
|
||||||
<div class="listElement">
|
<div class="listElement">
|
||||||
|
@ -15,6 +15,8 @@ export async function createRequest(request){
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function changeRequestState(id, infos){
|
export async function changeRequestState(id, infos){
|
||||||
|
console.log(infos)
|
||||||
|
console.log(await getLessonRequest(id))
|
||||||
return restPatch("/requests/lessonRequest/" + id, infos);
|
return restPatch("/requests/lessonRequest/" + id, infos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user