Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RestController
- @RequestMapping("/employees")
- public class EmployeeController {
- private List<Employee> employeeList;
- public static List<Integer> employees;
- private Map<Integer, Employee> employeeMap;
- public EmployeeController() {
- this.employeeList = new ArrayList<>();
- this.employeeMap = new HashMap<>();
- employees = new ArrayList<>();
- }
- public static List<Integer> getEmployees() {
- return employees;
- }
- @PostMapping("/{id}/add/{projectId}")
- public String addEmployee(@PathVariable int projectId, @PathVariable int id) {
- if (!employeeMap.containsKey(id)) {
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Employee with this id not found");
- }
- if (employeeList.get(id).getProjectList().contains(projectId)) {
- throw new ResponseStatusException(HttpStatus.IM_USED, "This project is already added");
- }
- if (!ProjectController.getProjects().contains(projectId)) {
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "This project is not created");
- }
- employeeMap.get(id).setProjectList(projectId);
- return String.format("Project was added to employee tasks");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement