-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathEmployeeDeleteCommand.java
More file actions
42 lines (34 loc) · 1.23 KB
/
EmployeeDeleteCommand.java
File metadata and controls
42 lines (34 loc) · 1.23 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
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 org.springframework.transaction.annotation.Transactional;
import edu.uark.registerapp.commands.VoidCommandInterface;
import edu.uark.registerapp.commands.exceptions.NotFoundException;
import edu.uark.registerapp.models.entities.EmployeeEntity;
import edu.uark.registerapp.models.repositories.EmployeeRepository;
@Service
public class EmployeeDeleteCommand implements VoidCommandInterface {
@Transactional
@Override
public void execute() {
final Optional<EmployeeEntity> employeeEntity =
this.employeeRepository.findById(this.employeeId);
if (!employeeEntity.isPresent()) { // No record with the associated record ID exists in the database.
throw new NotFoundException("Product");
}
this.employeeRepository.delete(employeeEntity.get());
}
// Properties
private UUID employeeId;
public UUID getEmployeeId() {
return this.employeeId;
}
public EmployeeDeleteCommand setEmployeeId(final UUID productId) {
this.employeeId = productId;
return this;
}
@Autowired
private EmployeeRepository employeeRepository;
}