using IntegrationGateway.Core.Abstractions; using IntegrationGateway.Core.Infrastructure; using Microsoft.AspNetCore.Mvc; namespace IntegrationGateway.Host.Controllers; [ApiController] [Route("api/gateway/realtime")] public class PointsController : ControllerBase { private readonly AdapterRegistry _registry; public PointsController(AdapterRegistry registry) => _registry = registry; [HttpGet("{adapter}/{deviceId}")] public async Task GetRealtime(string adapter, string deviceId) { var a = _registry.Get(adapter); if (a is not IHasPoints p) return NotFound(); return Ok(await p.GetRealtimeValuesAsync(deviceId)); } [HttpPost("{adapter}/control")] public async Task Control(string adapter, [FromBody] ControlRequest req) { var a = _registry.Get(adapter); if (a is not IHasPoints p) return NotFound(); await p.SetPointValueAsync(req.DeviceSourceId, req.PointIndex, req.Value); return Ok(new { status = "sent" }); } } public class ControlRequest { public string DeviceSourceId { get; set; } = ""; public int PointIndex { get; set; } public double Value { get; set; } }