DashboardController.java

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

  2. import com.github.benmanes.caffeine.cache.LoadingCache;
  3. import io.swagger.v3.oas.annotations.Operation;
  4. import io.swagger.v3.oas.annotations.responses.ApiResponse;
  5. import io.swagger.v3.oas.annotations.tags.Tag;
  6. import lombok.RequiredArgsConstructor;
  7. import lombok.extern.slf4j.Slf4j;
  8. import no.nav.data.team.dashboard.dto.DashResponse;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.http.ResponseEntity;
  11. import org.springframework.scheduling.annotation.Scheduled;
  12. import org.springframework.web.bind.annotation.GetMapping;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RestController;

  15. import static java.util.Objects.requireNonNull;


  16. @Slf4j
  17. @RestController
  18. @RequiredArgsConstructor
  19. @RequestMapping("/dash")
  20. @Tag(name = "Dashboard")
  21. public class DashboardController {
  22.     @Autowired
  23.     private LoadingCache<String, DashResponse> dashCache;

  24.     @Operation(summary = "Get Dashboard data")
  25.     @ApiResponse(description = "Data fetched")
  26.     @GetMapping
  27.     public ResponseEntity<DashResponse> getDashboardData() {
  28.         return ResponseEntity.ok(requireNonNull(dashCache.get("singleton")));
  29.     }

  30.     @Scheduled(initialDelayString = "PT2M", fixedRateString = "PT30S")
  31.     public void warmup() {
  32.         getDashboardData();
  33.     }

  34. }