+api/{code}/info(<s>Почти работает</s>)
This commit is contained in:
@@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
@@ -31,20 +33,30 @@ public class EmployeeController {
|
||||
}
|
||||
|
||||
@GetMapping("/{code}/auth")
|
||||
public ResponseEntity<?> Isauth(@PathVariable String code) {
|
||||
public HttpStatus Isauth(@PathVariable String code) {
|
||||
if (employeeService.isCodeValid(code)) {
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.OK)
|
||||
.body("данный код существует - можно пользоваться приложением");
|
||||
return HttpStatus.OK;
|
||||
|
||||
} else if (code == null) {
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.BAD_REQUEST)
|
||||
.body("что-то пошло не так");
|
||||
return
|
||||
HttpStatus.BAD_REQUEST;
|
||||
|
||||
} else {
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.UNAUTHORIZED)
|
||||
.body("кода не существует");
|
||||
return
|
||||
HttpStatus.UNAUTHORIZED;
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/{code}/info")
|
||||
public ResponseEntity<?> getInfo(@PathVariable String code){
|
||||
|
||||
Optional<Employee> employee = employeeService.getByCode(code);
|
||||
|
||||
if (employee.isPresent()) {
|
||||
return ResponseEntity.ok(employee.get());
|
||||
} else {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user