Add employee endpoint /visits
This commit is contained in:
parent
6501d3098f
commit
b5a88952ff
@ -53,6 +53,10 @@ public class AdminController {
|
|||||||
|
|
||||||
Optional<List<Visits>> visits = Optional.ofNullable(employeeService.getEmployeeVisits(username));
|
Optional<List<Visits>> visits = Optional.ofNullable(employeeService.getEmployeeVisits(username));
|
||||||
|
|
||||||
|
if (visits.isEmpty()) {
|
||||||
|
return utils.BadRequest("VisitsIsEmpty");
|
||||||
|
}
|
||||||
|
|
||||||
return new ResponseEntity<>(visits.get(), HttpStatus.OK);
|
return new ResponseEntity<>(visits.get(), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import com.example.nto.Utils;
|
|||||||
import com.example.nto.entity.CodeBody;
|
import com.example.nto.entity.CodeBody;
|
||||||
import com.example.nto.entity.Employee;
|
import com.example.nto.entity.Employee;
|
||||||
import com.example.nto.entity.ResponseData;
|
import com.example.nto.entity.ResponseData;
|
||||||
|
import com.example.nto.entity.Visits;
|
||||||
import com.example.nto.service.CodeService;
|
import com.example.nto.service.CodeService;
|
||||||
import com.example.nto.service.EmployeeService;
|
import com.example.nto.service.EmployeeService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
@ -19,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -33,7 +35,7 @@ public class EmployeeController {
|
|||||||
|
|
||||||
private final Utils utils = new Utils();
|
private final Utils utils = new Utils();
|
||||||
|
|
||||||
@Operation(summary = "Get employee info with login")
|
@Operation(summary = "Get employee info")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200",
|
@ApiResponse(responseCode = "200",
|
||||||
description = "OK",
|
description = "OK",
|
||||||
@ -65,6 +67,43 @@ public class EmployeeController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Operation(summary = "Get employee entries")
|
||||||
|
@ApiResponses(value = {
|
||||||
|
@ApiResponse(responseCode = "200",
|
||||||
|
description = "OK",
|
||||||
|
content = {@Content(mediaType = "application/json")}),
|
||||||
|
@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("/visits")
|
||||||
|
public ResponseEntity<?> getEmployeeVisits(Authentication authentication) {
|
||||||
|
try {
|
||||||
|
String username = authentication.getName();
|
||||||
|
|
||||||
|
Optional<Employee> employee = employeeService.findByLogin(username);
|
||||||
|
if (employee.isEmpty()) {
|
||||||
|
return utils.NotFound("EmployeeNotFound");
|
||||||
|
}
|
||||||
|
Optional<List<Visits>> visits = Optional.ofNullable(employeeService.getEmployeeVisits(username));
|
||||||
|
|
||||||
|
if (visits.isEmpty()) {
|
||||||
|
return utils.BadRequest("VisitsIsEmpty");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ResponseEntity<>(visits.get(), HttpStatus.OK);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Exception: " + e.getMessage());
|
||||||
|
return utils.BadRequest(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "Open door with code")
|
@Operation(summary = "Open door with code")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200",
|
@ApiResponse(responseCode = "200",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user