39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
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<IActionResult> 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<IActionResult> Control(string adapter, [FromBody] ControlRequest req)
|
|
{
|
|
var a = _registry.Get(adapter);
|
|
if (a is not IHasPoints p) return NotFound();
|
|
await p.SetPointValueAsync(req.DeviceId, req.PointIndex, req.Value);
|
|
return Ok(new { status = "sent" });
|
|
}
|
|
}
|
|
|
|
public class ControlRequest
|
|
{
|
|
public string DeviceId { get; set; } = "";
|
|
public int PointIndex { get; set; }
|
|
public double Value { get; set; }
|
|
}
|