forked from snowcycle/RegisterApp-Java
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathEmployeeQuery.java
More file actions
54 lines (46 loc) · 1.35 KB
/
EmployeeQuery.java
File metadata and controls
54 lines (46 loc) · 1.35 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
46
47
48
49
50
51
52
53
54
// Find employee by Id
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>
{
// Functionality
@Override
public Employee execute()
{
// Query employee from database by record ID
final Optional<EmployeeEntity> employeeEntity =
this.employeeRepository.findById(this.employeeId);
if (employeeEntity.isPresent())
{
// Map employee entity to Employee object
return new Employee(employeeEntity.get());
}
else
{
// Employee was not found
throw new NotFoundException("Employee");
}
}
// Create employee record ID with getters and setters
private UUID employeeId;
public UUID getEmployeeId()
{
return this.employeeId;
}
public EmployeeQuery setEmployeeId(final UUID employeeId)
{
this.employeeId = employeeId;
return this;
}
@Autowired
private EmployeeRepository employeeRepository;
}