adition of some services to admin
This commit is contained in:
@@ -28,6 +28,10 @@ public class AdminService {
|
||||
return career;
|
||||
}
|
||||
|
||||
public Career getCareer(Long id) {
|
||||
return careerRepository.findById(id).get();
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<Career> createUpdateCareers(List<Career> careers) {
|
||||
ArrayList<Career> updates = new ArrayList<>();
|
||||
|
||||
@@ -67,6 +67,14 @@ public class SecretaryService {
|
||||
return repository.save(updates);
|
||||
}
|
||||
|
||||
public Secretary disableSecretary(Long id){
|
||||
Secretary secretary = getSecretary(id);
|
||||
AuthUser authUser = secretary.getUser();
|
||||
authUser.setActive(false);
|
||||
secretary.setUser(authUser);
|
||||
return repository.save(secretary);
|
||||
}
|
||||
|
||||
public List<Student> findStudents(AuthUser secretary) {
|
||||
return findStudents(getSecretary(secretary));
|
||||
}
|
||||
|
||||
@@ -95,5 +95,11 @@ public class SicknesService {
|
||||
}
|
||||
return lastIndex;
|
||||
}
|
||||
|
||||
public Symptoms disableSymptom(Long id){
|
||||
Symptoms symptom = symptomsRepository.findById(id).get();
|
||||
symptom.setRiskLevel((short)0);
|
||||
return save(symptom);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.unam.acatlan.coviserv.controller;
|
||||
|
||||
import com.decsef.auth.manager.entity.AuthUser;
|
||||
import com.decsef.auth.manager.payload.CreateUserResponse;
|
||||
import com.decsef.auth.manager.service.AuthService;
|
||||
import com.unam.acatlan.coviserv.Entity.Career;
|
||||
@@ -8,10 +9,7 @@ import com.unam.acatlan.coviserv.Entity.Symptoms;
|
||||
import com.unam.acatlan.coviserv.Payloads.NewSecretary;
|
||||
import com.unam.acatlan.coviserv.Payloads.NewSymptomPayload;
|
||||
import com.unam.acatlan.coviserv.RoleName;
|
||||
import com.unam.acatlan.coviserv.Service.ManageService;
|
||||
import com.unam.acatlan.coviserv.Service.SecretaryService;
|
||||
import com.unam.acatlan.coviserv.Service.SicknesService;
|
||||
import com.unam.acatlan.coviserv.Service.UserService;
|
||||
import com.unam.acatlan.coviserv.Service.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@@ -40,6 +38,9 @@ public class AdminController {
|
||||
@Autowired
|
||||
private ManageService manageService;
|
||||
|
||||
@Autowired
|
||||
private AdminService adminService;
|
||||
|
||||
@PostMapping("/newSymptoms")
|
||||
public Symptoms newSymptoms(@Autowired Authentication authentication, @Valid @RequestBody NewSymptomPayload newSymptom) {
|
||||
Symptoms symptom = new Symptoms(sicknesService.getLastIndex(), newSymptom.getDescription(), newSymptom.getRiskLevel());
|
||||
@@ -48,7 +49,6 @@ public class AdminController {
|
||||
|
||||
@PostMapping("/newSecretary/{codeCarer}")
|
||||
public Secretary newSecretary(
|
||||
@Autowired Authentication authentication,
|
||||
@Valid @RequestBody NewSecretary secretaryPayload,
|
||||
@PathVariable Long codeCarer) {
|
||||
CreateUserResponse userResponse = secretaryService.save(secretaryPayload);
|
||||
@@ -60,6 +60,28 @@ public class AdminController {
|
||||
return secretaryService.getLastSecretary();
|
||||
}
|
||||
|
||||
@PostMapping("/disableSecretary/{idSecretary}")
|
||||
public Secretary disableSecretary(
|
||||
@PathVariable Long idSecretary) {
|
||||
return secretaryService.disableSecretary(idSecretary);
|
||||
}
|
||||
|
||||
@PostMapping("/disableSymptom/{idSymptom}")
|
||||
public Symptoms disableSymptom(
|
||||
@PathVariable Long idSymptom
|
||||
){
|
||||
return sicknesService.disableSymptom(idSymptom);
|
||||
}
|
||||
|
||||
@PostMapping("/disableCarer/{idCarer}")
|
||||
public Career disableCarer(
|
||||
@PathVariable Long idCarer
|
||||
){
|
||||
Career career = adminService.getCareer(idCarer);
|
||||
career.setSecretary((long)0);
|
||||
return adminService.createUpdateCareer(career);
|
||||
}
|
||||
|
||||
@PostMapping("/newCarer")
|
||||
public Career newCarer(@Valid @RequestBody Career career) {
|
||||
if (!manageService.careerExists(career.getCode())) {
|
||||
|
||||
@@ -36,13 +36,14 @@ public class LoginController {
|
||||
|
||||
@PostMapping("/sign-up")
|
||||
public ResponseEntity<?> signUp(@Valid @RequestBody SingUpUserRequest signUpRequest) {
|
||||
int role;
|
||||
if (signUpRequest.getCuenta().length() < 9) {
|
||||
role = 1;
|
||||
} else {
|
||||
role = 0;
|
||||
}
|
||||
|
||||
if (!authService.userExists(signUpRequest.getCuenta())) {
|
||||
int role;
|
||||
if (signUpRequest.getCuenta().length() < 9) {
|
||||
role = 1;
|
||||
} else {
|
||||
role = 0;
|
||||
}
|
||||
CreateUserResponse createUserResponse = userService.create(signUpRequest, RoleName.list().get(role));
|
||||
|
||||
if (createUserResponse.isSuccess()) {
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.Objects;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
@Secured(RoleName.ROLE_USER)
|
||||
@Secured({RoleName.ROLE_USER, RoleName.ROLE_SECRETARY, RoleName.ROLE_ADMIN})
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
|
||||
Reference in New Issue
Block a user