Merge pull request 'Closes #68' (#79) from 3002833/Backend:main into restfull

Reviewed-on: Maradona/Backend#79
pull/1/head
David Hess 2024-11-11 09:45:29 +01:00
commit 4ac81f0586
3 changed files with 24 additions and 4 deletions

View File

@ -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());
}

View File

@ -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;
}

View File

@ -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() {