Guest User

Untitled

a guest
Jun 25th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. @Component
  2. public class EmployeeHandler {
  3. private final EmployeeRepository repository;
  4.  
  5. public EmployeeHandler(EmployeeRepository repository) {
  6. this.repository = repository;
  7. }
  8.  
  9. public Mono<ServerResponse> getAllEmployees(ServerRequest request) {
  10. Flux<Employee> employees = repository.getAllEmployees();
  11. return ServerResponse.ok()
  12. .contentType(MediaType.APPLICATION_JSON)
  13. .body(employees, Employee.class);
  14. }
  15.  
  16. public Mono<ServerResponse> getEmployee(ServerRequest request) {
  17. String firstName = request.pathVariable("fn");
  18. String lastName = request.pathVariable("ln");
  19. Mono<Employee> employee = repository.getEmployee(firstName, lastName);
  20.  
  21. return ServerResponse.ok()
  22. .contentType(MediaType.APPLICATION_JSON)
  23. .body(employee, Employee.class);
  24. }
  25.  
  26. public Mono<ServerResponse> createNewEmployee(ServerRequest request) {
  27. Mono<Employee> employeeMono = request.bodyToMono(Employee.class);
  28. Mono<Employee> employee = repository.createNewEmployee(employeeMono);
  29.  
  30. return ServerResponse.ok()
  31. .contentType(MediaType.APPLICATION_JSON)
  32. .body(employee, Employee.class);
  33. }
  34.  
  35. public Mono<ServerResponse> deleteEmployee(ServerRequest request) {
  36. String id = request.pathVariable("id");
  37. Mono<Void> employee = repository.deleteEmployee(id);
  38.  
  39. return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).build(employee);
  40. }
  41.  
  42. public Mono<ServerResponse> getAllDepartments(ServerRequest request) {
  43. Flux<Department> allDepartments = repository.getAllDepartments();
  44. return ServerResponse.ok()
  45. .contentType(MediaType.APPLICATION_JSON)
  46. .body(allDepartments, Department.class);
  47. }
  48. }
Add Comment
Please, Sign In to add comment