Merge pull request 'Notifications on Schedule' (#172) from NotificationSchedule into master
Some checks failed
Some checks failed
Reviewed-on: #172
This commit is contained in:
commit
71c2af7fcb
@ -12,14 +12,8 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
import ovh.herisson.Clyde.Services.*;
|
||||||
import ovh.herisson.Clyde.Services.LessonRequestService;
|
import ovh.herisson.Clyde.Tables.*;
|
||||||
import ovh.herisson.Clyde.Services.LessonService;
|
|
||||||
import ovh.herisson.Clyde.Services.ProtectionService;
|
|
||||||
import ovh.herisson.Clyde.Tables.LessonChangesRequest;
|
|
||||||
import ovh.herisson.Clyde.Tables.RequestState;
|
|
||||||
import ovh.herisson.Clyde.Tables.Role;
|
|
||||||
import ovh.herisson.Clyde.Tables.User;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -28,11 +22,13 @@ import java.util.Map;
|
|||||||
public class LessonRequestsController {
|
public class LessonRequestsController {
|
||||||
private final LessonRequestService lessonRequestServ;
|
private final LessonRequestService lessonRequestServ;
|
||||||
private final AuthenticatorService authServ;
|
private final AuthenticatorService authServ;
|
||||||
|
private final UserService userServ;
|
||||||
|
|
||||||
private final LessonService lessonServ;
|
private final LessonService lessonServ;
|
||||||
public LessonRequestsController(LessonRequestService lessonRequestServer, AuthenticatorService authServ, LessonService lessonServ) {
|
public LessonRequestsController(LessonRequestService lessonRequestServer, AuthenticatorService authServ, UserService userServ, LessonService lessonServ) {
|
||||||
this.lessonRequestServ = lessonRequestServer;
|
this.lessonRequestServ = lessonRequestServer;
|
||||||
this.authServ = authServ;
|
this.authServ = authServ;
|
||||||
|
this.userServ = userServ;
|
||||||
this.lessonServ = lessonServ;
|
this.lessonServ = lessonServ;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -113,6 +109,7 @@ public class LessonRequestsController {
|
|||||||
if(lessonRequest.getRequestType() == 0 ) {
|
if(lessonRequest.getRequestType() == 0 ) {
|
||||||
if (!lessonRequestServ.modifyCreateRequestState(lessonRequest, state, local))
|
if (!lessonRequestServ.modifyCreateRequestState(lessonRequest, state, local))
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
userServ.Notify(lessonRequest.getUser(), new Notification("Request took in charge","Request"+ state + ":" + lessonRequest.getCourse().getTitle(), "#/manage-owned-lessons"));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(lessonRequest.getRequestType() == 1){
|
else if(lessonRequest.getRequestType() == 1){
|
||||||
@ -122,12 +119,14 @@ public class LessonRequestsController {
|
|||||||
if(!lessonRequestServ.modifyChangeRequestState(infos,lessonRequest.getLessonId(),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);
|
||||||
|
userServ.Notify(lessonRequest.getUser(), new Notification("Request took in charge","Request"+ state + ":" + lessonServ.findById(lessonRequest.getLessonId()).getCourse().getTitle(), "#/manage-owned-lessons"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else{
|
else{
|
||||||
|
userServ.Notify(lessonRequest.getUser(), new Notification("Request took in charge","Request"+ state + ":" + lessonServ.findById(lessonRequest.getLessonId()).getCourse().getTitle(), "#/manage-owned-lessons"));
|
||||||
lessonRequestServ.modifyDeleteRequest(lessonRequest, state);
|
lessonRequestServ.modifyDeleteRequest(lessonRequest, state);
|
||||||
lessonRequest.setState(state);
|
lessonRequest.setState(state);
|
||||||
|
|
||||||
}
|
}
|
||||||
lessonRequestServ.save(lessonRequest);
|
lessonRequestServ.save(lessonRequest);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
@ -22,6 +22,9 @@ public interface ScheduleLessonRepository extends CrudRepository<ScheduleLesson,
|
|||||||
@Query("select distinct sl.schedule from ScheduleLesson sl where sl.schedule.curriculum = ?1")
|
@Query("select distinct sl.schedule from ScheduleLesson sl where sl.schedule.curriculum = ?1")
|
||||||
Schedule findScheduleByCurriculum(Curriculum curriculum);
|
Schedule findScheduleByCurriculum(Curriculum curriculum);
|
||||||
|
|
||||||
|
@Query("select distinct sl from ScheduleLesson sl where sl.lesson = ?1")
|
||||||
|
ScheduleLesson findByLesson(Lesson lesson);
|
||||||
|
|
||||||
@Modifying
|
@Modifying
|
||||||
@Transactional
|
@Transactional
|
||||||
@Query("delete from ScheduleLesson sl where sl.lesson =?1")
|
@Query("delete from ScheduleLesson sl where sl.lesson =?1")
|
||||||
|
@ -13,9 +13,11 @@ public interface UserCurriculumRepository extends CrudRepository<UserCurriculum,
|
|||||||
@Query("select uc.curriculum from UserCurriculum uc where uc.user = ?1")
|
@Query("select uc.curriculum from UserCurriculum uc where uc.user = ?1")
|
||||||
Curriculum findByUser(User student);
|
Curriculum findByUser(User student);
|
||||||
|
|
||||||
|
@Query("select distinct uc.user from UserCurriculum uc where uc.curriculum = ?1")
|
||||||
|
Iterable<User> findUsersByCurriculum(Curriculum curriculum);
|
||||||
|
|
||||||
ArrayList<UserCurriculum> findByUserOrderByCurriculum(User student);
|
ArrayList<UserCurriculum> findByUserOrderByCurriculum(User student);
|
||||||
UserCurriculum findByUserAndCurriculumAndActual(User user, Curriculum curriculum, boolean actual);
|
UserCurriculum findByUserAndCurriculumAndActual(User user, Curriculum curriculum, boolean actual);
|
||||||
|
|
||||||
ArrayList<UserCurriculum> findByUserAndActual(User user, boolean actual);
|
ArrayList<UserCurriculum> findByUserAndActual(User user, boolean actual);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,7 @@ package ovh.herisson.Clyde.Services;
|
|||||||
* @scope Extension Horaire
|
* @scope Extension Horaire
|
||||||
******************************************************/
|
******************************************************/
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
import ovh.herisson.Clyde.Repositories.*;
|
||||||
import ovh.herisson.Clyde.Repositories.CurriculumCourseRepository;
|
|
||||||
import ovh.herisson.Clyde.Repositories.LessonRepository;
|
|
||||||
import ovh.herisson.Clyde.Repositories.UserCurriculumRepository;
|
|
||||||
import ovh.herisson.Clyde.Tables.*;
|
import ovh.herisson.Clyde.Tables.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -19,12 +16,17 @@ import java.util.Map;
|
|||||||
@Service
|
@Service
|
||||||
public class LessonService {
|
public class LessonService {
|
||||||
private final LessonRepository lessonRepo;
|
private final LessonRepository lessonRepo;
|
||||||
|
|
||||||
|
private final ScheduleLessonRepository scheduleLessonRepo;
|
||||||
private final UserCurriculumRepository userCurriculumRepo;
|
private final UserCurriculumRepository userCurriculumRepo;
|
||||||
|
private final UserService userServ;
|
||||||
private final CourseRepository courseRepo;
|
private final CourseRepository courseRepo;
|
||||||
private final CurriculumCourseRepository curriculumCourseRepo;
|
private final CurriculumCourseRepository curriculumCourseRepo;
|
||||||
public LessonService(LessonRepository lessonRepo, UserCurriculumRepository userCurriculumRepo, CourseRepository courseRepo, CurriculumCourseRepository curriculumCourseRepo){
|
public LessonService(LessonRepository lessonRepo, ScheduleLessonRepository scheduleLessonRepo, UserCurriculumRepository userCurriculumRepo, UserService userServ, CourseRepository courseRepo, CurriculumCourseRepository curriculumCourseRepo){
|
||||||
this.lessonRepo = lessonRepo;
|
this.lessonRepo = lessonRepo;
|
||||||
|
this.scheduleLessonRepo = scheduleLessonRepo;
|
||||||
this.userCurriculumRepo = userCurriculumRepo;
|
this.userCurriculumRepo = userCurriculumRepo;
|
||||||
|
this.userServ = userServ;
|
||||||
this.courseRepo = courseRepo;
|
this.courseRepo = courseRepo;
|
||||||
this.curriculumCourseRepo = curriculumCourseRepo;
|
this.curriculumCourseRepo = curriculumCourseRepo;
|
||||||
}
|
}
|
||||||
@ -136,7 +138,12 @@ public class LessonService {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lessonRepo.save(target);
|
Lesson lesson = lessonRepo.save(target);
|
||||||
|
ScheduleLesson scheduleLesson = scheduleLessonRepo.findByLesson(lesson);
|
||||||
|
Iterable<User> users = userCurriculumRepo.findUsersByCurriculum(scheduleLesson.getSchedule().getCurriculum());
|
||||||
|
for(User user: users){
|
||||||
|
userServ.Notify(user, new Notification("Course modified in the schedule", "Course Modified " + lesson.getCourse().getTitle() , "/#/schedule"));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -9,22 +9,26 @@ import org.springframework.stereotype.Service;
|
|||||||
import ovh.herisson.Clyde.Repositories.LessonRepository;
|
import ovh.herisson.Clyde.Repositories.LessonRepository;
|
||||||
import ovh.herisson.Clyde.Repositories.ScheduleLessonRepository;
|
import ovh.herisson.Clyde.Repositories.ScheduleLessonRepository;
|
||||||
import ovh.herisson.Clyde.Repositories.ScheduleRepository;
|
import ovh.herisson.Clyde.Repositories.ScheduleRepository;
|
||||||
|
import ovh.herisson.Clyde.Repositories.UserCurriculumRepository;
|
||||||
import ovh.herisson.Clyde.Tables.*;
|
import ovh.herisson.Clyde.Tables.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ScheduleLessonService {
|
public class ScheduleLessonService {
|
||||||
|
|
||||||
private final ScheduleLessonRepository scheduleLessonRepo;
|
private final ScheduleLessonRepository scheduleLessonRepo;
|
||||||
|
|
||||||
|
private final UserCurriculumRepository userCurriculumRepo;
|
||||||
|
private final UserService userServ;
|
||||||
private final LessonRepository lessonRepo;
|
private final LessonRepository lessonRepo;
|
||||||
private final ScheduleRepository scheduleRepo;
|
private final ScheduleRepository scheduleRepo;
|
||||||
public ScheduleLessonService(ScheduleLessonRepository scheduleLessonRepo, LessonRepository lessonRepo, ScheduleRepository scheduleRepo) {
|
public ScheduleLessonService(ScheduleLessonRepository scheduleLessonRepo, UserCurriculumRepository userCurriculumRepo, UserService userServ, LessonRepository lessonRepo, ScheduleRepository scheduleRepo) {
|
||||||
this.scheduleLessonRepo = scheduleLessonRepo;
|
this.scheduleLessonRepo = scheduleLessonRepo;
|
||||||
|
this.userCurriculumRepo = userCurriculumRepo;
|
||||||
|
this.userServ = userServ;
|
||||||
this.lessonRepo = lessonRepo;
|
this.lessonRepo = lessonRepo;
|
||||||
this.scheduleRepo = scheduleRepo;
|
this.scheduleRepo = scheduleRepo;
|
||||||
}
|
}
|
||||||
@ -32,19 +36,22 @@ public class ScheduleLessonService {
|
|||||||
if(scheduleLesson == null)
|
if(scheduleLesson == null)
|
||||||
return false;
|
return false;
|
||||||
scheduleLessonRepo.save(scheduleLesson);
|
scheduleLessonRepo.save(scheduleLesson);
|
||||||
|
Iterable<User> users = userCurriculumRepo.findUsersByCurriculum(scheduleLesson.getSchedule().getCurriculum());
|
||||||
|
for(User user: users){
|
||||||
|
userServ.Notify(user, new Notification("New course in the schedule", "Course added " + scheduleLesson.getLesson().getCourse().getTitle(), "/#/schedule"));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Save a lesson to all the schedule it is linked
|
* Save a lesson to all the schedule it is linked
|
||||||
*/
|
*/
|
||||||
public boolean saveToAllSchedule(Lesson lesson){
|
public void saveToAllSchedule(Lesson lesson){
|
||||||
Iterable<Schedule> schedules = scheduleRepo.findAllLessonSchedule(lesson.getCourse());
|
Iterable<Schedule> schedules = scheduleRepo.findAllLessonSchedule(lesson.getCourse());
|
||||||
if(schedules == null)
|
if(schedules == null)
|
||||||
return false;
|
return;
|
||||||
for (Schedule schedule : schedules){
|
for (Schedule schedule : schedules){
|
||||||
save(new ScheduleLesson(schedule, lesson));
|
save(new ScheduleLesson(schedule, lesson));
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Delete a scheduleLesson via its lesson
|
* Delete a scheduleLesson via its lesson
|
||||||
@ -52,6 +59,11 @@ public class ScheduleLessonService {
|
|||||||
public boolean delete(long lessonId){
|
public boolean delete(long lessonId){
|
||||||
if(lessonId == 0)
|
if(lessonId == 0)
|
||||||
return false;
|
return false;
|
||||||
|
ScheduleLesson scheduleLesson = scheduleLessonRepo.findByLesson(lessonRepo.findById(lessonId));
|
||||||
|
Iterable<User> users = userCurriculumRepo.findUsersByCurriculum(scheduleLesson.getSchedule().getCurriculum());
|
||||||
|
for(User user: users){
|
||||||
|
userServ.Notify(user, new Notification("Course deleted in the schedule","Course deleted " + scheduleLesson.getLesson().getCourse().getTitle(), "/#/schedule"));
|
||||||
|
}
|
||||||
scheduleLessonRepo.delete(lessonRepo.findById(lessonId));
|
scheduleLessonRepo.delete(lessonRepo.findById(lessonId));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import ovh.herisson.Clyde.Tables.Msg.Discussion;
|
|||||||
import ovh.herisson.Clyde.Tables.Msg.Message;
|
import ovh.herisson.Clyde.Tables.Msg.Message;
|
||||||
import ovh.herisson.Clyde.Tables.Notification.Status;
|
import ovh.herisson.Clyde.Tables.Notification.Status;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -41,7 +42,7 @@ public class User {
|
|||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
|
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
|
||||||
private List<Notification> notifications;
|
private List<Notification> notifications = new ArrayList<>();
|
||||||
|
|
||||||
////// Extension Messagerie /////
|
////// Extension Messagerie /////
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
|
Loading…
Reference in New Issue
Block a user