-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathAuditController.java
More file actions
51 lines (44 loc) · 1.86 KB
/
Copy pathAuditController.java
File metadata and controls
51 lines (44 loc) · 1.86 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.tricentisdemo.sap.customer360.web;
import com.tricentisdemo.sap.customer360.persistence.AuditEvent;
import com.tricentisdemo.sap.customer360.service.AuditService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
* Postgres-only access-audit read surface — no SAP call on this path.
*
* <p>Exposes two equivalent routes for the same underlying query so both
* "audit-centric" consumers ({@code /api/v1/audit}) and the legacy
* customer-centric UI ({@code /api/v1/customers/recent-views}) resolve
* without the generic 500-from-NoResourceFoundException trap.
*/
@RestController
@Tag(name = "Audit", description = "Service-level access audit (Postgres read)")
public class AuditController {
private static final Logger log = LoggerFactory.getLogger(AuditController.class);
private final AuditService audit;
public AuditController(AuditService audit) {
this.audit = audit;
}
@Operation(summary = "Most recent 50 audit events across all customers",
description = "Postgres-only — no SAP call. Useful for compliance/ops dashboards.")
@GetMapping({"/api/v1/audit", "/api/v1/customers/recent-views"})
public ResponseEntity<Map<String, Object>> recent() {
log.info("GET audit recent-views");
List<AuditEvent> events = audit.recent();
if (events == null) {
events = List.of();
}
return ResponseEntity.ok(Map.of(
"items", events,
"count", events.size()
));
}
}