View Javadoc
1   package fr.tiogars.domaintemplate.domains.auth.role.controllers;
2   
3   import org.springframework.http.ResponseEntity;
4   import org.springframework.web.bind.annotation.GetMapping;
5   import org.springframework.web.bind.annotation.PathVariable;
6   import org.springframework.web.bind.annotation.RestController;
7   
8   import fr.tiogars.domaintemplate.domains.auth.role.entities.Role;
9   import fr.tiogars.domaintemplate.domains.auth.role.services.RoleService;
10  import io.swagger.v3.oas.annotations.Operation;
11  import io.swagger.v3.oas.annotations.security.SecurityRequirement;
12  import io.swagger.v3.oas.annotations.tags.Tag;
13  
14  /** Exposes the endpoint that reads roles. */
15  @Tag(name = "Roles", description = "Role management operations.")
16  @RestController
17  public class RoleReadController {
18  
19      private final RoleService service;
20  
21      RoleReadController(RoleService service) {
22          this.service = service;
23      }
24  
25      @Operation(summary = "Read a role")
26      @SecurityRequirement(name = "bearerAuth")
27      @GetMapping("/api/v1/auth/roles/{id}")
28      ResponseEntity<Role> readRole(@PathVariable Long id) {
29          return service.findById(id)
30                  .map(ResponseEntity::ok)
31                  .orElseGet(() -> ResponseEntity.notFound().build());
32      }
33  }