Phase0_Day1_gateway_rebuilt
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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.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; }
|
||||
}
|
||||
Reference in New Issue
Block a user