From b75614982c5c272cdedcd844ed43ea31bdd28871 Mon Sep 17 00:00:00 2001 From: Lunix-420 Date: Mon, 11 Nov 2024 09:42:28 +0100 Subject: [PATCH] fix: EmployeeId bullshit --- .../controllers/api/EmployeeController.java | 3 ++- .../com/maradona/backend/entities/Employee.java | 10 +++++++++- .../backend/services/EmployeeService.java | 15 +++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/maradona/backend/controllers/api/EmployeeController.java b/src/main/java/com/maradona/backend/controllers/api/EmployeeController.java index 4a509a4..a9a3fb6 100644 --- a/src/main/java/com/maradona/backend/controllers/api/EmployeeController.java +++ b/src/main/java/com/maradona/backend/controllers/api/EmployeeController.java @@ -48,7 +48,8 @@ public class EmployeeController { */ @GetMapping({ "/", "" }) public ResponseEntity get(@RequestParam Long id) { - return employeeService.getEmployeeById(id) + var employee = employeeService.getEmployeeById(id); + return employee .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } diff --git a/src/main/java/com/maradona/backend/entities/Employee.java b/src/main/java/com/maradona/backend/entities/Employee.java index 0c211a1..5d06051 100644 --- a/src/main/java/com/maradona/backend/entities/Employee.java +++ b/src/main/java/com/maradona/backend/entities/Employee.java @@ -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 secondarySkills; + public void setEid(Long eid) { + this.eid = eid; + } + + public Long getEid() { + return eid; + } + public void setEmployeeNr(Integer employeeNr) { this.employeeNr = employeeNr; } diff --git a/src/main/java/com/maradona/backend/services/EmployeeService.java b/src/main/java/com/maradona/backend/services/EmployeeService.java index 610c4b8..5d49343 100644 --- a/src/main/java/com/maradona/backend/services/EmployeeService.java +++ b/src/main/java/com/maradona/backend/services/EmployeeService.java @@ -22,11 +22,22 @@ public class EmployeeService { } public Optional 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 getAllEmployees() {