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