using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; /// /// Gateway fleet operations: fleet listing, gateway detail, and site summaries. /// [ApiController] [Route("api/v1/operations")] [Authorize] [Produces("application/json")] public class OperationsController : ControllerBase { private readonly IOperationsService _operations; public OperationsController(IOperationsService operations) => _operations = operations; /// /// Lists registered gateways with optional status and site filters. /// /// Optional gateway status filter (DB literal, e.g. DEGRADED). /// Optional site id filter. /// Gateway fleet items. [HttpGet("gateways")] [AuthorizePermission(ClinicalPermissions.UsersAdmin)] [ProducesResponseType(typeof(ApiResponse>), StatusCodes.Status200OK)] public async Task ListGateways( [FromQuery] string? status, [FromQuery] Guid? siteId, CancellationToken ct) { var items = await _operations.GetGatewayFleetAsync( new GatewayFleetFilter(status, siteId), ct); return Ok(ApiResponse>.Ok(items)); } /// /// Gets a single gateway by id with buffer depth, heartbeat metadata, and sync history. /// /// Gateway id. /// Gateway detail. [HttpGet("gateways/{gatewayId:guid}")] [AuthorizePermission(ClinicalPermissions.UsersAdmin)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] public async Task GetGateway(Guid gatewayId, CancellationToken ct) { var detail = await _operations.GetGatewayDetailAsync(gatewayId, ct); return Ok(ApiResponse.Ok(detail)); } /// /// Returns an aggregate gateway summary for a site. /// /// Site id. /// Site gateway summary. [HttpGet("sites/{siteId:guid}/summary")] [AuthorizePermission(ClinicalPermissions.UsersAdmin)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] public async Task GetSiteSummary(Guid siteId, CancellationToken ct) { var summary = await _operations.GetSiteSummaryAsync(siteId, ct); return Ok(ApiResponse.Ok(summary)); } }