forked from snowcycle/RegisterApp-Java
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathEmployeeByIdQuery.java
More file actions
45 lines (38 loc) · 1.6 KB
/
EmployeeByIdQuery.java
File metadata and controls
45 lines (38 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Last updated 02/20/2021 by Jodi Mitchell
// This file grabs a specific employee by their ID
package edu.uark.registerapp.commands.employees;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import edu.uark.registerapp.commands.ResultCommandInterface;
import edu.uark.registerapp.commands.exceptions.NotFoundException;
import edu.uark.registerapp.models.api.Employee;
import edu.uark.registerapp.models.entities.EmployeeEntity;
import edu.uark.registerapp.models.repositories.EmployeeRepository;
@Service
public class EmployeeByIdQuery implements ResultCommandInterface<Employee>
{
@Override
public Employee execute()
{
final Optional<EmployeeEntity> employeeEntity =
this.employeeRepository.findByEmployeeId(this.employeeId); // This is throwing errors because the
Checking to see if the employee exist. // operations in EmployeeRepository.java are
if (employeeEntity.isPresent()){ // commented out. I had to do this so the app
return new Employee(employeeEntity.get()); // will run as expected.
} else { // I think Once we get everything put together
throw new NotFoundException("Employee"); // with the routers we can uncomment those // functions.
}
}
// Getters and Setters
private int employeeId;
public int getEmployeeId() {
return this.employeeId;
}
public EmployeeByIdQuery setemployeeId(final int employeeId) {
this.employeeId = employeeId;
return this;
}
@Autowired
private EmployeeRepository employeeRepository;
}