cleaned all controllers
This commit is contained in:
@ -35,8 +35,8 @@ public class AuthenticatorService {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void register(InscriptionRequest inscriptionRequest) {
|
||||
inscriptionService.save(inscriptionRequest);
|
||||
public InscriptionRequest register(InscriptionRequest inscriptionRequest) {
|
||||
return inscriptionService.save(inscriptionRequest);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -28,6 +28,9 @@ public class CourseService {
|
||||
public Course modifyData(long id, Map<String, Object> updates, Role role) {
|
||||
Course target = courseRepo.findById(id);
|
||||
|
||||
if (target == null)
|
||||
return null;
|
||||
|
||||
if (role == Role.Teacher){
|
||||
for (Map.Entry<String, Object> entry : updates.entrySet()){
|
||||
if (entry.getKey().equals("title")){
|
||||
@ -52,4 +55,8 @@ public class CourseService {
|
||||
}
|
||||
return courseRepo.save(target);
|
||||
}
|
||||
|
||||
public void delete(Long id) {
|
||||
courseRepo.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
||||
import ovh.herisson.Clyde.Repositories.CurriculumRepository;
|
||||
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||
|
||||
@ -10,23 +9,18 @@ public class CurriculumService {
|
||||
|
||||
private final CurriculumRepository curriculumRepo;
|
||||
|
||||
private final CourseRepository courseRepo;
|
||||
|
||||
public CurriculumService(CurriculumRepository curriculumRepo, CourseRepository courseRepo){
|
||||
public CurriculumService(CurriculumRepository curriculumRepo){
|
||||
this.curriculumRepo = curriculumRepo;
|
||||
this.courseRepo = courseRepo;
|
||||
}
|
||||
|
||||
|
||||
public void save(Curriculum curriculum){
|
||||
curriculumRepo.save(curriculum);
|
||||
public Curriculum save(Curriculum curriculum){
|
||||
return curriculumRepo.save(curriculum);
|
||||
}
|
||||
|
||||
public Curriculum findById(long id){
|
||||
return curriculumRepo.findById(id);
|
||||
}
|
||||
|
||||
public Iterable<Curriculum> findAll(){
|
||||
return curriculumRepo.findAll();
|
||||
public void delete(Long id) {
|
||||
curriculumRepo.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,8 +14,8 @@ public class InscriptionService {
|
||||
this.inscriptionRepo = inscriptionRepo;
|
||||
}
|
||||
|
||||
public void save(InscriptionRequest inscriptionRequest){
|
||||
inscriptionRepo.save(inscriptionRequest);
|
||||
public InscriptionRequest save(InscriptionRequest inscriptionRequest){
|
||||
return inscriptionRepo.save(inscriptionRequest);
|
||||
}
|
||||
|
||||
public InscriptionRequest getById(long id){
|
||||
@ -26,9 +26,14 @@ public class InscriptionService {
|
||||
return inscriptionRepo.findAll();
|
||||
}
|
||||
|
||||
public void modifyState(long id, RequestState requestState) {
|
||||
public boolean modifyState(long id, RequestState requestState) {
|
||||
InscriptionRequest inscriptionRequest = getById(id);
|
||||
|
||||
if (inscriptionRequest == null)
|
||||
return false;
|
||||
|
||||
inscriptionRequest.setState(requestState);
|
||||
save(inscriptionRequest);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,9 @@ public class TeacherCourseService {
|
||||
|
||||
public boolean saveAll(Iterable<Long> teacherIds, Course course){
|
||||
|
||||
if (course == null)
|
||||
return false;
|
||||
|
||||
ArrayList<Long> addedIds = new ArrayList<>();
|
||||
for (Long teacherId : teacherIds){
|
||||
User teacher = userRepo.findById((long) teacherId);
|
||||
|
||||
@ -36,7 +36,11 @@ public class UserService {
|
||||
* @param target the user to update
|
||||
* @return if the changes were done or not
|
||||
*/
|
||||
public boolean modifyData(User poster, Map<String ,Object> updates, User target){
|
||||
public boolean modifyData(long targetId, Map<String ,Object> updates, User poster){
|
||||
|
||||
User target = userRepo.findById(targetId);
|
||||
if (target == null)
|
||||
return false;
|
||||
|
||||
if (poster.getRegNo().equals(target.getRegNo())){
|
||||
for (Map.Entry<String, Object> entry : updates.entrySet()){
|
||||
@ -80,7 +84,7 @@ public class UserService {
|
||||
|
||||
if ( !entry.getKey().equals("role")) {return false;}
|
||||
|
||||
if (entry.getValue() == Role.Admin){return false;}
|
||||
if (entry.getValue() == Role.Admin) {return false;}
|
||||
|
||||
target.setRole((Role) entry.getValue());
|
||||
userRepo.save(target);
|
||||
@ -95,9 +99,9 @@ public class UserService {
|
||||
return passwordEncoder.matches(tryingPassword, user.getPassword());
|
||||
}
|
||||
|
||||
public void save(User user){
|
||||
public User save(User user){
|
||||
user.setPassword(passwordEncoder.encode(user.getPassword()));
|
||||
userRepo.save(user);
|
||||
return userRepo.save(user);
|
||||
}
|
||||
|
||||
public Iterable<User> getAll(){
|
||||
|
||||
Reference in New Issue
Block a user