diff --git a/src/main/java/net/siegeln/cameleer/saas/vendor/InfrastructureController.java b/src/main/java/net/siegeln/cameleer/saas/vendor/InfrastructureController.java new file mode 100644 index 0000000..cc710bd --- /dev/null +++ b/src/main/java/net/siegeln/cameleer/saas/vendor/InfrastructureController.java @@ -0,0 +1,57 @@ +package net.siegeln.cameleer.saas.vendor; + +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Map; + +@RestController +@RequestMapping("/api/vendor/infrastructure") +@PreAuthorize("hasAuthority('SCOPE_platform:admin')") +public class InfrastructureController { + + private final InfrastructureService infraService; + + public InfrastructureController(InfrastructureService infraService) { + this.infraService = infraService; + } + + public record InfraOverviewResponse( + InfrastructureService.PostgresOverview postgres, + InfrastructureService.ClickHouseOverview clickhouse) {} + + @GetMapping + public ResponseEntity overview() { + return ResponseEntity.ok(new InfraOverviewResponse( + infraService.getPostgresOverview(), + infraService.getClickHouseOverview())); + } + + @GetMapping("/postgres") + public ResponseEntity> postgres() { + return ResponseEntity.ok(Map.of( + "overview", infraService.getPostgresOverview(), + "tenants", infraService.getPostgresTenantStats())); + } + + @GetMapping("/postgres/{slug}") + public ResponseEntity> postgresDetail( + @PathVariable String slug) { + return ResponseEntity.ok(infraService.getPostgresTenantDetail(slug)); + } + + @GetMapping("/clickhouse") + public ResponseEntity> clickhouse() { + return ResponseEntity.ok(Map.of( + "overview", infraService.getClickHouseOverview(), + "tenants", infraService.getClickHouseTenantStats())); + } + + @GetMapping("/clickhouse/{tenantId}") + public ResponseEntity> clickhouseDetail( + @PathVariable String tenantId) { + return ResponseEntity.ok(infraService.getClickHouseTenantDetail(tenantId)); + } +}