SettingsController.java

  1. package no.nav.data.team.settings;


  2. import io.swagger.v3.oas.annotations.Operation;
  3. import io.swagger.v3.oas.annotations.responses.ApiResponse;
  4. import io.swagger.v3.oas.annotations.responses.ApiResponses;
  5. import io.swagger.v3.oas.annotations.tags.Tag;
  6. import lombok.extern.slf4j.Slf4j;
  7. import no.nav.data.common.security.SecurityUtils;
  8. import no.nav.data.team.settings.dto.Settings;
  9. import org.springframework.http.ResponseEntity;
  10. import org.springframework.web.bind.annotation.GetMapping;
  11. import org.springframework.web.bind.annotation.PostMapping;
  12. import org.springframework.web.bind.annotation.RequestBody;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RestController;

  15. import java.util.List;

  16. @Slf4j
  17. @RestController
  18. @Tag(description = "Settings", name = "Settings")
  19. @RequestMapping("/settings")
  20. public class SettingsController {

  21.     private final SettingsService service;

  22.     public SettingsController(SettingsService service) {
  23.         this.service = service;
  24.     }

  25.     @Operation(summary = "Get Settings")
  26.     @ApiResponses(value = {@ApiResponse(description = "Settings fetched")})
  27.     @GetMapping
  28.     public ResponseEntity<Settings> get() {
  29.         log.info("Received request for Settings");
  30.         Settings settings = service.getSettings();
  31.         if (!SecurityUtils.isAdmin()) {
  32.             // Non admin users shouldn't see who is filtered out
  33.             settings.setIdentFilter(List.of());
  34.         }
  35.         return ResponseEntity.ok(settings);
  36.     }

  37.     @Operation(summary = "Write Settings")
  38.     @ApiResponses(value = {@ApiResponse(description = "Settings written")})
  39.     @PostMapping
  40.     public ResponseEntity<Settings> write(@RequestBody Settings settings) {
  41.         log.info("Received request to write Settings");
  42.         return ResponseEntity.ok(service.updateSettings(settings));
  43.     }


  44. }