Some fixes
This commit is contained in:
parent
6023a897df
commit
2d88b38796
@ -3,7 +3,9 @@ package com.example.nto.controller;
|
|||||||
import com.example.nto.entity.Code;
|
import com.example.nto.entity.Code;
|
||||||
import com.example.nto.service.CodeService;
|
import com.example.nto.service.CodeService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@ -13,6 +15,8 @@ public class CodeController {
|
|||||||
|
|
||||||
@PatchMapping("/api/{login}/open")
|
@PatchMapping("/api/{login}/open")
|
||||||
public Code update(@PathVariable String login, @RequestBody Code newCode) {
|
public Code update(@PathVariable String login, @RequestBody Code newCode) {
|
||||||
|
if (newCode.getValue() == 0)
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
|
||||||
return codeService.update(login, newCode);
|
return codeService.update(login, newCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,9 @@ package com.example.nto.controller;
|
|||||||
import com.example.nto.entity.Employee;
|
import com.example.nto.entity.Employee;
|
||||||
import com.example.nto.service.EmployeeService;
|
import com.example.nto.service.EmployeeService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@ -62,13 +62,14 @@ public class EmployeeCodeServiceImpl implements EmployeeService, CodeService {
|
|||||||
updateEmployee(employeeId, employee);
|
updateEmployee(employeeId, employee);
|
||||||
|
|
||||||
Optional<Code> codeOptional = codeRepository.findById(employeeId);
|
Optional<Code> codeOptional = codeRepository.findById(employeeId);
|
||||||
if (codeOptional.isEmpty())
|
Code code;
|
||||||
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED,
|
if (codeOptional.isEmpty()) {
|
||||||
"There is no account with login " + login + " or it is incorrect");
|
code = newCode;
|
||||||
|
code.setId(employeeId);
|
||||||
Code code = codeOptional.get();
|
} else {
|
||||||
|
code = codeOptional.get();
|
||||||
code.setValue(newCode.getValue());
|
code.setValue(newCode.getValue());
|
||||||
|
}
|
||||||
return codeRepository.save(code);
|
return codeRepository.save(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user