Skip to content
Permalink
Browse files
check if employee is already assigned
  • Loading branch information
mgeiss committed Jun 28, 2017
1 parent 733149b commit 23688fb1f9002c562595d8ca23c7b20057980a80
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
@@ -27,4 +27,6 @@ public interface TellerRepository extends JpaRepository<TellerEntity, Long> {
Optional<TellerEntity> findByIdentifier(final String identifier);

List<TellerEntity> findByOfficeIdentifier(final String officeIdentifier);

Optional<TellerEntity> findFirstByAssignedEmployeeIdentifier(final String employeeIdentifier);
}
@@ -106,4 +106,8 @@ private List<TellerEntry> fetchTellerEntries(final String accountIdentifier, fin

return tellerEntries;
}

public Optional<Teller> findByAssignedEmployee(final String employeeIdentifier) {
return this.tellerRepository.findFirstByAssignedEmployeeIdentifier(employeeIdentifier).map(TellerMapper::map);
}
}
@@ -166,10 +166,6 @@ ResponseEntity<Void> post(@PathVariable("officeIdentifier") final String officeI
@RequestBody @Valid final TellerManagementCommand tellerManagementCommand) {
final Teller teller = this.verifyTeller(tellerCode);

if (tellerManagementCommand.getAmount() != null && tellerManagementCommand.getAmount() > teller.getCashdrawLimit()) {
throw ServiceException.badRequest("Adjustment exceeds cashdraw limit.");
}

final TellerManagementCommand.Action action = TellerManagementCommand.Action.valueOf(tellerManagementCommand.getAction());
switch (action) {
case OPEN:
@@ -215,6 +211,12 @@ private void verifyAccount(final String accountIdentifier) {
}

private void verifyEmployee(final String employeeIdentifier) {
final Optional<Teller> optionalTeller = this.tellerManagementService.findByAssignedEmployee(employeeIdentifier);
if (optionalTeller.isPresent()) {
throw ServiceException.conflict("Employee {0} already assigned to teller {1}.",
employeeIdentifier, optionalTeller.get().getCode());
}

if (!this.organizationService.employeeExists(employeeIdentifier)) {
throw ServiceException.badRequest("Employee {0} not found.", employeeIdentifier);
}

0 comments on commit 23688fb

Please sign in to comment.