diff --git a/IMPLEMENTATION.md b/IMPLEMENTATION.md index 5019d97..3059fb9 100644 --- a/IMPLEMENTATION.md +++ b/IMPLEMENTATION.md @@ -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. - 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. ### [ ] 6.4 `/health` reports MQTT status diff --git a/src/FrameProcessor/Controllers/FramesController.cs b/src/FrameProcessor/Controllers/FramesController.cs index dafeb82..5ccb408 100644 --- a/src/FrameProcessor/Controllers/FramesController.cs +++ b/src/FrameProcessor/Controllers/FramesController.cs @@ -1,6 +1,7 @@ using FrameProcessor.Configuration; using FrameProcessor.Domain; using FrameProcessor.ImagePipeline; +using FrameProcessor.Mqtt; using FrameProcessor.Storage; using Microsoft.AspNetCore.Mvc; @@ -13,12 +14,14 @@ public sealed class FramesController : ControllerBase private readonly FramesRegistry _frames; private readonly IImagePipeline _pipeline; 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; _pipeline = pipeline; _store = store; + _mqtt = mqtt; } [HttpPost("{name}/image")] @@ -43,13 +46,15 @@ public sealed class FramesController : ControllerBase await _store.WriteAsync(frame.Mac, pngBytes, cancellationToken).ConfigureAwait(false); + var publishResult = await _mqtt.PublishAsync(frame.Mac, cancellationToken).ConfigureAwait(false); + return Ok(new { frame = frame.Name.Value, mac = frame.Mac.ToString(), url = $"/i/{frame.Mac}.png", processedAt = DateTimeOffset.UtcNow, - mqttPublished = false, + mqttPublished = publishResult == PublishResult.Success, }); } }