diff --git a/src/main/java/com/indexzero/finals/controller/EmployeeController.java b/src/main/java/com/indexzero/finals/controller/EmployeeController.java index ea1ffde..d132af1 100644 --- a/src/main/java/com/indexzero/finals/controller/EmployeeController.java +++ b/src/main/java/com/indexzero/finals/controller/EmployeeController.java @@ -2,6 +2,9 @@ package com.indexzero.finals.controller; import com.indexzero.finals.dto.EmployeeDTO; import com.indexzero.finals.service.EmployeeService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -21,37 +24,83 @@ public class EmployeeController { EmployeeService employeeService; @PostMapping("/login") + @Operation(description = "User Login", summary = "User login") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Login Successful"), + @ApiResponse(responseCode = "401", description = "Unauthorized"), + }) public ResponseEntity login() { return new ResponseEntity(HttpStatus.OK); } @PostMapping("/profile") + @Operation(description = "Get user's profile. Username is taken from Authentication.", summary = "Get user's profile") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Request Successful"), + @ApiResponse(responseCode = "401", description = "Unauthorized"), + }) public ResponseEntity getInfo() { return employeeService.getUserInfo(SecurityContextHolder.getContext().getAuthentication()); } @PatchMapping("/open") + @Operation(description = "Open the door. Code is taken from the code URL param.", summary = "Open the door") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Opening Successful"), + @ApiResponse(responseCode = "401", description = "Unauthorized / Wrong code"), + @ApiResponse(responseCode = "400", description = "Bad Request"), + + }) public ResponseEntity Open(@RequestParam Long code) { return employeeService.openTheDoor(code, SecurityContextHolder.getContext().getAuthentication()); } @DeleteMapping("/{login}/delete") + @Operation(description = "Delete a user by login. (ADMIN only)", summary = "Delete a user by login") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Deletion Successful"), + @ApiResponse(responseCode = "401", description = "Unauthorized"), + @ApiResponse(responseCode = "403", description = "Forbidden"), + @ApiResponse(responseCode = "404", description = "User not found"), + @ApiResponse(responseCode = "409", description = "User you're trying to delete has ADMIN authority"), + }) public ResponseEntity delete(@PathVariable String login) { return employeeService.deleteEmployee(login); } @PatchMapping("/{login}/{state}") + @Operation(description = "Enable/Disable user's ability to use QR code entrance. (ADMIN only) States: active / blocked", summary = "Enable/Disable QR") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Modification Successful"), + @ApiResponse(responseCode = "401", description = "Unauthorized"), + @ApiResponse(responseCode = "403", description = "Forbidden"), + @ApiResponse(responseCode = "404", description = "User not found"), + @ApiResponse(responseCode = "400", description = "State doesn't exist"), + }) public ResponseEntity changeState(@PathVariable String login, @PathVariable String state) { return employeeService.changeState(login, state); } @GetMapping("/all") + @Operation(description = "Get all users with pagination. (ADMIN Only)", summary = "Get all users") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Request Successful"), + @ApiResponse(responseCode = "401", description = "Unauthorized"), + @ApiResponse(responseCode = "403", description = "Forbidden"), + }) public ResponseEntity> getAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) { Pageable pageable = PageRequest.of(page, size); return employeeService.getAllEmployees(pageable); } @GetMapping("/{login}") + @Operation(description = "Get user's profile by login (ADMIN only)", summary = "Get user's profile by login") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Modification Successful"), + @ApiResponse(responseCode = "401", description = "Unauthorized"), + @ApiResponse(responseCode = "403", description = "Forbidden"), + @ApiResponse(responseCode = "404", description = "User not found"), + }) public ResponseEntity getEmployeeByLogin(@PathVariable String login) { return employeeService.getEmployeeByLogin(login); } diff --git a/src/main/java/com/indexzero/finals/controller/EntranceController.java b/src/main/java/com/indexzero/finals/controller/EntranceController.java index 94e715f..67c6799 100644 --- a/src/main/java/com/indexzero/finals/controller/EntranceController.java +++ b/src/main/java/com/indexzero/finals/controller/EntranceController.java @@ -41,12 +41,12 @@ public class EntranceController { } @GetMapping("/all") + @Operation(description = "Get all entrances of all users with pagination (ADMIN only)", summary = "Get all entrances") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Request Successful."), @ApiResponse(responseCode = "401", description = "Unauthorized"), @ApiResponse(responseCode = "403", description = "Forbidden"), }) - @Operation(description = "Get all entrances of all users (ADMIN only)", summary = "Get all entrances") public ResponseEntity> getAllEntrances(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) { Pageable pageable = PageRequest.of(page, size); return entranceService.getAllEntrances(pageable); diff --git a/src/main/java/com/indexzero/finals/service/impl/EmployeeServiceImpl.java b/src/main/java/com/indexzero/finals/service/impl/EmployeeServiceImpl.java index d75ac3e..e499739 100644 --- a/src/main/java/com/indexzero/finals/service/impl/EmployeeServiceImpl.java +++ b/src/main/java/com/indexzero/finals/service/impl/EmployeeServiceImpl.java @@ -68,7 +68,7 @@ public class EmployeeServiceImpl implements EmployeeService { Employee e = employeeRepository.findByLogin(login); if(e != null) { if (Objects.equals(e.getAuthorities().iterator().next().getAuthority(), "ADMIN")) { - return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + return new ResponseEntity<>(HttpStatus.CONFLICT); } else { employeeRepository.delete(e);