-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathEmployeeQuery.java
More file actions
41 lines (34 loc) · 1.14 KB
/
EmployeeQuery.java
File metadata and controls
41 lines (34 loc) · 1.14 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
package edu.uark.registerapp.commands.employees;
import java.util.Optional;
import java.util.UUID;
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 EmployeeQuery implements ResultCommandInterface<Employee> {
@Override
public Employee execute() {
final Optional<EmployeeEntity> employeeEntity =
this.employeeRepository.findById(this.employeeId);
if (employeeEntity.isPresent()) {
return new Employee(employeeEntity.get());
} else {
throw new NotFoundException("Employee");
}
}
// Properties
private UUID employeeId;
public UUID getEmployeeId() {
return this.employeeId;
}
public EmployeeQuery setEmployeeId(final UUID employeeId) {
this.employeeId = employeeId;
return this;
}
@Autowired
private EmployeeRepository employeeRepository;
}