View Javadoc
1   package fr.tiogars.inception.settings.user.controllers;
2   
3   import java.security.Principal;
4   
5   import org.springframework.http.ResponseEntity;
6   import org.springframework.web.bind.annotation.GetMapping;
7   import org.springframework.web.bind.annotation.RestController;
8   
9   import fr.tiogars.inception.settings.user.entities.UserSettings;
10  import fr.tiogars.inception.settings.user.services.UserSettingsService;
11  import io.swagger.v3.oas.annotations.Operation;
12  import io.swagger.v3.oas.annotations.security.SecurityRequirement;
13  import io.swagger.v3.oas.annotations.tags.Tag;
14  
15  /** Exposes the endpoint that reads the settings of the authenticated account. */
16  @Tag(name = "User settings", description = "User and ANONYMOUS role settings operations.")
17  @RestController
18  public class MyUserSettingsReadController {
19  
20      private final UserSettingsService service;
21  
22      MyUserSettingsReadController(UserSettingsService service) {
23          this.service = service;
24      }
25  
26      @Operation(summary = "Read the settings of the authenticated account")
27      @SecurityRequirement(name = "bearerAuth")
28      @GetMapping("/api/v1/settings/user/me")
29      ResponseEntity<UserSettings> readMyUserSettings(Principal principal) {
30          return service.findByUsername(principal.getName())
31                  .map(ResponseEntity::ok)
32                  .orElseGet(() -> ResponseEntity.notFound().build());
33      }
34  }