fix: EmployeeId bullshit
parent
0706bd294a
commit
b75614982c
|
@ -48,7 +48,8 @@ public class EmployeeController {
|
|||
*/
|
||||
@GetMapping({ "/", "" })
|
||||
public ResponseEntity<Employee> get(@RequestParam Long id) {
|
||||
return employeeService.getEmployeeById(id)
|
||||
var employee = employeeService.getEmployeeById(id);
|
||||
return employee
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.stream.Collectors;
|
|||
public class Employee {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private Long eid;
|
||||
|
||||
private Integer employeeNr;
|
||||
|
||||
|
@ -34,6 +34,14 @@ public class Employee {
|
|||
@JsonManagedReference
|
||||
private List<EmployeeSecondarySkill> secondarySkills;
|
||||
|
||||
public void setEid(Long eid) {
|
||||
this.eid = eid;
|
||||
}
|
||||
|
||||
public Long getEid() {
|
||||
return eid;
|
||||
}
|
||||
|
||||
public void setEmployeeNr(Integer employeeNr) {
|
||||
this.employeeNr = employeeNr;
|
||||
}
|
||||
|
|
|
@ -22,11 +22,22 @@ public class EmployeeService {
|
|||
}
|
||||
|
||||
public Optional<Employee> getEmployeeById(Long id) {
|
||||
return employeeRepository.findById(id);
|
||||
var employees = employeeRepository.findAll();
|
||||
for (Employee employee : employees) {
|
||||
if (employee.getEid().equals(id)) {
|
||||
return Optional.of(employee);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public void deleteEmployee(Long id) {
|
||||
employeeRepository.deleteById(id);
|
||||
for (Employee employee : employeeRepository.findAll()) {
|
||||
if (employee.getEid().equals(id)) {
|
||||
employeeRepository.delete(employee);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Iterable<Employee> getAllEmployees() {
|
||||
|
|
Loading…
Reference in New Issue