use of rest.spring.entity.Manager in project spring-boot-rest-api by shaikhhafiz.
the class ManagerController method updateManager.
/**
* Update an manager by id
* @param managerId
* @param managerDetails
* @return
*/
@PutMapping("/manager/{id}")
public ResponseEntity<Manager> updateManager(@PathVariable(value = "id") Long managerId, @Valid @RequestBody Manager managerDetails) {
Manager manager = managerService.findById(managerId);
if (manager == null) {
return ResponseEntity.notFound().build();
}
managerDetails.setId(managerId);
Manager updatedManager = managerService.update(managerDetails);
return ResponseEntity.ok(updatedManager);
}
use of rest.spring.entity.Manager in project spring-boot-rest-api by shaikhhafiz.
the class EmployeeController method updateEmployee.
/**
* Update an employee by id
* @param employeeId
* @param employeeDetails
* @return
*/
@PutMapping("employees/{id}")
public ResponseEntity<Employee> updateEmployee(@PathVariable("managerId") Long managerId, @PathVariable(value = "id") Long employeeId, @Valid @RequestBody Employee employeeDetails) {
Manager manager = null;
manager = managerService.findById(managerId);
if (manager == null) {
return new ResponseEntity("Manager with manager id " + managerId + "is not exist", HttpStatus.NO_CONTENT);
}
Employee employee = null;
employee = employeeService.findById(employeeId);
if (employee == null) {
return new ResponseEntity("Employee with employee id " + employeeId + "is not exist", HttpStatus.NO_CONTENT);
}
employee.setName(employeeDetails.getName());
employee.setEmail(employeeDetails.getEmail());
employee.setDesignation(employeeDetails.getDesignation());
employee.setSalary(employeeDetails.getSalary());
employee.setManager(manager);
Employee updatedEmployee = employeeService.update(employee);
return new ResponseEntity(updatedEmployee, HttpStatus.OK);
}
use of rest.spring.entity.Manager in project spring-boot-rest-api by shaikhhafiz.
the class EmployeeController method employeeList.
/**
* Get list of all employee
* @return
*/
@GetMapping("/employees")
public ResponseEntity<List<Employee>> employeeList(@PathVariable("managerId") Long managerId) {
Manager manager = null;
List<Employee> employees = null;
try {
manager = managerService.findById(managerId);
if (manager == null) {
return new ResponseEntity("Manager with manager id " + managerId + " does not exist", HttpStatus.NO_CONTENT);
} else if (manager != null) {
employees = employeeService.findAllByManager(manager);
if (employees.isEmpty()) {
return new ResponseEntity("There have no employees with manager id " + managerId, HttpStatus.NO_CONTENT);
}
}
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage());
}
return new ResponseEntity<List<Employee>>(employees, HttpStatus.OK);
}
use of rest.spring.entity.Manager in project spring-boot-rest-api by shaikhhafiz.
the class ManagerController method deleteManager.
/**
* Delete a manager by id
* @param managerId
* @return
*/
@DeleteMapping("/manager/{id}")
public ResponseEntity<Manager> deleteManager(@PathVariable(value = "id") Long managerId) {
Manager manager = managerService.findById(managerId);
if (manager == null) {
return ResponseEntity.notFound().build();
}
managerService.delete(manager);
return ResponseEntity.ok().build();
}
Aggregations