6.3 Wire MQTT publish into FramesController
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -161,7 +161,7 @@ Each type lives in `src/FrameProcessor/Domain/`. Tests in `tests/FrameProcessor.
|
|||||||
- Topic: `{BaseTopic}/{mac}`, payload UTF-8 `"update"`, QoS 1, retained false.
|
- Topic: `{BaseTopic}/{mac}`, payload UTF-8 `"update"`, QoS 1, retained false.
|
||||||
- Returns success/failure (no throw).
|
- Returns success/failure (no throw).
|
||||||
|
|
||||||
### [ ] 6.3 Wire into `FramesController`
|
### [x] 6.3 Wire into `FramesController`
|
||||||
- After successful save, call `PublishAsync`; set `mqttPublished` accordingly in the response.
|
- After successful save, call `PublishAsync`; set `mqttPublished` accordingly in the response.
|
||||||
|
|
||||||
### [ ] 6.4 `/health` reports MQTT status
|
### [ ] 6.4 `/health` reports MQTT status
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using FrameProcessor.Configuration;
|
using FrameProcessor.Configuration;
|
||||||
using FrameProcessor.Domain;
|
using FrameProcessor.Domain;
|
||||||
using FrameProcessor.ImagePipeline;
|
using FrameProcessor.ImagePipeline;
|
||||||
|
using FrameProcessor.Mqtt;
|
||||||
using FrameProcessor.Storage;
|
using FrameProcessor.Storage;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
@@ -13,12 +14,14 @@ public sealed class FramesController : ControllerBase
|
|||||||
private readonly FramesRegistry _frames;
|
private readonly FramesRegistry _frames;
|
||||||
private readonly IImagePipeline _pipeline;
|
private readonly IImagePipeline _pipeline;
|
||||||
private readonly ImageStore _store;
|
private readonly ImageStore _store;
|
||||||
|
private readonly MqttPublisher _mqtt;
|
||||||
|
|
||||||
public FramesController(FramesRegistry frames, IImagePipeline pipeline, ImageStore store)
|
public FramesController(FramesRegistry frames, IImagePipeline pipeline, ImageStore store, MqttPublisher mqtt)
|
||||||
{
|
{
|
||||||
_frames = frames;
|
_frames = frames;
|
||||||
_pipeline = pipeline;
|
_pipeline = pipeline;
|
||||||
_store = store;
|
_store = store;
|
||||||
|
_mqtt = mqtt;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("{name}/image")]
|
[HttpPost("{name}/image")]
|
||||||
@@ -43,13 +46,15 @@ public sealed class FramesController : ControllerBase
|
|||||||
|
|
||||||
await _store.WriteAsync(frame.Mac, pngBytes, cancellationToken).ConfigureAwait(false);
|
await _store.WriteAsync(frame.Mac, pngBytes, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
var publishResult = await _mqtt.PublishAsync(frame.Mac, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
return Ok(new
|
return Ok(new
|
||||||
{
|
{
|
||||||
frame = frame.Name.Value,
|
frame = frame.Name.Value,
|
||||||
mac = frame.Mac.ToString(),
|
mac = frame.Mac.ToString(),
|
||||||
url = $"/i/{frame.Mac}.png",
|
url = $"/i/{frame.Mac}.png",
|
||||||
processedAt = DateTimeOffset.UtcNow,
|
processedAt = DateTimeOffset.UtcNow,
|
||||||
mqttPublished = false,
|
mqttPublished = publishResult == PublishResult.Success,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user