[Utils] move result-models methods to class Utils

This commit is contained in:
Denis Oleynik 2025-02-19 15:40:38 +03:00
parent 9bc8425381
commit 7d59c875dd
2 changed files with 20 additions and 43 deletions

View File

@ -0,0 +1,20 @@
package com.example.nto;
import com.example.nto.entity.ResponseData;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
public class Utils {
public ResponseEntity<ResponseData> NotFound() {
return new ResponseEntity<>(new ResponseData(HttpStatus.UNAUTHORIZED.value(), "Login not found or invalid"), HttpStatus.UNAUTHORIZED);
}
public ResponseEntity<ResponseData> BadRequest() {
return new ResponseEntity<>(new ResponseData(HttpStatus.BAD_REQUEST.value(), "Something went wrong"), HttpStatus.BAD_REQUEST);
}
public ResponseEntity<ResponseData> Ok(String message) {
return new ResponseEntity<>(new ResponseData(HttpStatus.OK.value(), message), HttpStatus.OK);
}
}

View File

@ -25,49 +25,6 @@ public class EmployeeController {
@Autowired
private EmployeeService employeeService;
private ResponseEntity<ResponseData> NotFound() {
return new ResponseEntity<>(new ResponseData(HttpStatus.UNAUTHORIZED.value(), "Login not found or invalid"), HttpStatus.UNAUTHORIZED);
}
private ResponseEntity<ResponseData> BadRequest() {
return new ResponseEntity<>(new ResponseData(HttpStatus.BAD_REQUEST.value(), "Something went wrong"), HttpStatus.BAD_REQUEST);
}
private ResponseEntity<ResponseData> Ok(String message) {
return new ResponseEntity<>(new ResponseData(HttpStatus.OK.value(), message), HttpStatus.OK);
}
@Operation(summary = "Auth employee with login")
@ApiResponses(value = {
@ApiResponse(responseCode = "200",
description = "Auth employee with login success",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = ResponseData.class))}),
@ApiResponse(responseCode = "401",
description = "Login not found or invalid",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = ResponseData.class))}),
@ApiResponse(responseCode = "400",
description = "Something went wrong",
content = {@Content(mediaType = "application/json",
schema = @Schema(implementation = ResponseData.class))})
})
@GetMapping("/api/{login}/auth")
public ResponseEntity<?> auth(@PathVariable("login") String login) {
try {
if (login == null || login.isEmpty() || !employeeService.existsByLogin(login)) {
return NotFound();
}
return Ok("Auth success");
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
return BadRequest();
}
}
@Operation(summary = "Get employee info with login")
@ApiResponses(value = {
@ApiResponse(responseCode = "200",