One more fix #2

This commit is contained in:
A1pha 2024-12-06 12:08:19 +03:00
parent f5b6bd9211
commit b730d8d5ac
2 changed files with 7 additions and 5 deletions

View File

@ -15,8 +15,6 @@ public class CodeController {
@PatchMapping("/api/{login}/open")
public Code update(@PathVariable String login, @RequestBody Code newCode) {
if (newCode.getValue() == 0)
throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
return codeService.update(login, newCode);
}
}

View File

@ -55,9 +55,16 @@ public class EmployeeCodeServiceImpl implements EmployeeService, CodeService {
@Override
public Code update(String login, Code newCode) {
Employee employee = findByLogin(login);
long employeeId = employee.getId();
employee.setLastVisit(LocalDateTime.now());
updateEmployee(employeeId, employee);
if (newCode.getValue() == 0)
throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
Optional<Code> codeOptional = codeRepository.findById(employeeId);
Code code;
if (codeOptional.isEmpty()) {
@ -71,9 +78,6 @@ public class EmployeeCodeServiceImpl implements EmployeeService, CodeService {
code.setValue(newCode.getValue());
}
employee.setLastVisit(LocalDateTime.now());
updateEmployee(employeeId, employee);
return codeRepository.save(code);
}