-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDashboardController.java
More file actions
51 lines (44 loc) · 1.9 KB
/
Copy pathDashboardController.java
File metadata and controls
51 lines (44 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.dbaagent.controller;
import com.dbaagent.service.DashboardService;
import com.dbaagent.service.security.AccessControlService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* REST API for performance dashboard
*
* <p><b>Authorization:</b> every endpoint here takes a caller-supplied connection id, so
* each one asserts access itself ({@code assertCanReadConnectionContent} for reads,
* {@code assertCanManageConnectionContent} for writes). {@code SecurityConfig} only
* requires an authenticated principal — nothing upstream inspects a connection id. See
* {@code ConnectionScopedAuthorizationSafetyTest}.
*/
@RestController
@RequestMapping("/dashboard")
@RequiredArgsConstructor
@Slf4j
public class DashboardController {
private final DashboardService dashboardService;
private final AccessControlService accessControlService;
/**
* Get performance dashboard data for a connection
*/
@GetMapping("/performance/{connectionId}")
public ResponseEntity<DashboardService.DashboardData> getPerformanceDashboard(
@PathVariable String connectionId,
@RequestParam(required = false, defaultValue = "30") Integer days
) {
try {
accessControlService.assertCanReadConnectionContent(connectionId);
log.info("Fetching performance dashboard for connection: {}, days: {}", connectionId, days);
DashboardService.DashboardData data = dashboardService.getDashboardData(connectionId, days);
return ResponseEntity.ok(data);
} catch (org.springframework.web.server.ResponseStatusException e) {
throw e;
} catch (Exception e) {
log.error("Error fetching performance dashboard", e);
return ResponseEntity.internalServerError().build();
}
}
}