|
| 1 | +package com.baeldung.reactive.webflux; |
| 2 | + |
| 3 | +import java.util.HashMap; |
| 4 | +import java.util.Map; |
| 5 | + |
| 6 | +import org.springframework.stereotype.Repository; |
| 7 | + |
| 8 | +import reactor.core.publisher.Flux; |
| 9 | +import reactor.core.publisher.Mono; |
| 10 | + |
| 11 | +@Repository |
| 12 | +public class EmployeeRepository { |
| 13 | + |
| 14 | + static Map<String,Employee> employeeData; |
| 15 | + |
| 16 | + static Map<String,String> employeeAccessData; |
| 17 | + |
| 18 | + static |
| 19 | + { |
| 20 | + employeeData = new HashMap<>(); |
| 21 | + employeeData.put("1",new Employee("1","Employee 1")); |
| 22 | + employeeData.put("2",new Employee("2","Employee 2")); |
| 23 | + employeeData.put("3",new Employee("3","Employee 3")); |
| 24 | + employeeData.put("4",new Employee("4","Employee 4")); |
| 25 | + employeeData.put("5",new Employee("5","Employee 5")); |
| 26 | + employeeData.put("6",new Employee("6","Employee 6")); |
| 27 | + employeeData.put("7",new Employee("7","Employee 7")); |
| 28 | + employeeData.put("8",new Employee("8","Employee 8")); |
| 29 | + employeeData.put("9",new Employee("9","Employee 9")); |
| 30 | + employeeData.put("10",new Employee("10","Employee 10")); |
| 31 | + |
| 32 | + employeeAccessData=new HashMap<>(); |
| 33 | + employeeAccessData.put("1", "Employee 1 Access Key"); |
| 34 | + employeeAccessData.put("2", "Employee 2 Access Key"); |
| 35 | + employeeAccessData.put("3", "Employee 3 Access Key"); |
| 36 | + employeeAccessData.put("4", "Employee 4 Access Key"); |
| 37 | + employeeAccessData.put("5", "Employee 5 Access Key"); |
| 38 | + employeeAccessData.put("6", "Employee 6 Access Key"); |
| 39 | + employeeAccessData.put("7", "Employee 7 Access Key"); |
| 40 | + employeeAccessData.put("8", "Employee 8 Access Key"); |
| 41 | + employeeAccessData.put("9", "Employee 9 Access Key"); |
| 42 | + employeeAccessData.put("10", "Employee 10 Access Key"); |
| 43 | + } |
| 44 | + |
| 45 | + public Mono<Employee> findEmployeeById(String id) |
| 46 | + { |
| 47 | + return Mono.just(employeeData.get(id)); |
| 48 | + } |
| 49 | + |
| 50 | + public Flux<Employee> findAllEmployees() |
| 51 | + { |
| 52 | + return Flux.fromIterable(employeeData.values()); |
| 53 | + } |
| 54 | + |
| 55 | + public Mono<Employee> updateEmployee(Employee employee) |
| 56 | + { |
| 57 | + Employee existingEmployee=employeeData.get(employee.getId()); |
| 58 | + if(existingEmployee!=null) |
| 59 | + { |
| 60 | + existingEmployee.setName(employee.getName()); |
| 61 | + } |
| 62 | + return Mono.just(existingEmployee); |
| 63 | + } |
| 64 | +} |
0 commit comments