From ca9fcaf2f9392e1d879f2306953e78fffdf4632c Mon Sep 17 00:00:00 2001 From: IndexZero Date: Wed, 19 Feb 2025 15:10:36 +0300 Subject: [PATCH] Added new request and documentation for it --- .../finals/controller/EntranceController.java | 20 ++++++++++++++++--- .../finals/service/EntranceService.java | 1 + .../service/impl/EntranceServiceImpl.java | 16 +++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/indexzero/finals/controller/EntranceController.java b/src/main/java/com/indexzero/finals/controller/EntranceController.java index 67c6799..004da8a 100644 --- a/src/main/java/com/indexzero/finals/controller/EntranceController.java +++ b/src/main/java/com/indexzero/finals/controller/EntranceController.java @@ -21,7 +21,7 @@ public class EntranceController { @GetMapping - @Operation(description = "Get all entrances of a user with pagination. Username is taken from Authentication", summary = "Get all entrances of a user") + @Operation(description = "Get all entries of a user with pagination. Username is taken from Authentication", summary = "Get all entries of a user") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Request Successful."), @ApiResponse(responseCode = "401", description = "Unauthorized"), @@ -30,8 +30,9 @@ public class EntranceController { Pageable pageable = PageRequest.of(page, size); return entranceService.getEmployeeEntrances(pageable, SecurityContextHolder.getContext().getAuthentication()); } + @GetMapping("/last") - @Operation(description = "Get user's last entrance. Username is taken from Authentication", summary = "Get user's last entrance") + @Operation(description = "Get user's last entries. Username is taken from Authentication", summary = "Get user's last entry") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Request Successful."), @ApiResponse(responseCode = "401", description = "Unauthorized"), @@ -41,7 +42,7 @@ public class EntranceController { } @GetMapping("/all") - @Operation(description = "Get all entrances of all users with pagination (ADMIN only)", summary = "Get all entrances") + @Operation(description = "Get all entries of all users with pagination (ADMIN only)", summary = "Get all entries") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Request Successful."), @ApiResponse(responseCode = "401", description = "Unauthorized"), @@ -52,4 +53,17 @@ public class EntranceController { return entranceService.getAllEntrances(pageable); } + @GetMapping("/{login}") + @Operation(description = "Get all entries of a user by login (ADMIN only)", summary = "Get entries by login") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Request Successful."), + @ApiResponse(responseCode = "401", description = "Unauthorized"), + @ApiResponse(responseCode = "403", description = "Forbidden"), + @ApiResponse(responseCode = "404", description = "User not found") + }) + public ResponseEntity> getEntrancesByLogin (@PathVariable String login, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) { + Pageable pageable = PageRequest.of(page, size); + return entranceService.getEntrancesByLogin(pageable, login); + } + } diff --git a/src/main/java/com/indexzero/finals/service/EntranceService.java b/src/main/java/com/indexzero/finals/service/EntranceService.java index de08d06..192f59b 100644 --- a/src/main/java/com/indexzero/finals/service/EntranceService.java +++ b/src/main/java/com/indexzero/finals/service/EntranceService.java @@ -10,6 +10,7 @@ public interface EntranceService { ResponseEntity> getEmployeeEntrances(Pageable pageable, Authentication auth); ResponseEntity getLastEntrance(Authentication auth); ResponseEntity> getAllEntrances(Pageable pageable); + ResponseEntity> getEntrancesByLogin(Pageable pageable, String login); } diff --git a/src/main/java/com/indexzero/finals/service/impl/EntranceServiceImpl.java b/src/main/java/com/indexzero/finals/service/impl/EntranceServiceImpl.java index 7b35a6e..3d6e5d5 100644 --- a/src/main/java/com/indexzero/finals/service/impl/EntranceServiceImpl.java +++ b/src/main/java/com/indexzero/finals/service/impl/EntranceServiceImpl.java @@ -53,4 +53,20 @@ public class EntranceServiceImpl implements EntranceService { Page page = new PageImpl<>(entrancesdto, pageable, entrances.size()); return new ResponseEntity<>(page, HttpStatus.OK); } + + @Override + public ResponseEntity> getEntrancesByLogin(Pageable pageable, String login) { + Employee e = employeeRepository.findByLogin(login); + if(e != null) { + List entrances = e.getEntrances(); + List entrancesdto = entrances.stream().map(EntranceMapper::convertToDTO).collect(Collectors.toList()); + + Page page = new PageImpl<>(entrancesdto, pageable, entrances.size()); + + return new ResponseEntity<>(page, HttpStatus.OK); + } + else { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + } }