add voice service call service and more
This commit is contained in:
@@ -8,10 +8,12 @@ namespace GreenHome.Api.Controllers;
|
||||
public class TelemetryController : ControllerBase
|
||||
{
|
||||
private readonly ITelemetryService telemetryService;
|
||||
private readonly IAlertService alertService;
|
||||
|
||||
public TelemetryController(ITelemetryService telemetryService)
|
||||
public TelemetryController(ITelemetryService telemetryService, IAlertService alertService)
|
||||
{
|
||||
this.telemetryService = telemetryService;
|
||||
this.alertService = alertService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -37,6 +39,26 @@ public class TelemetryController : ControllerBase
|
||||
TimestampUtc = DateTime.UtcNow
|
||||
};
|
||||
var id = await telemetryService.AddAsync(dto, cancellationToken);
|
||||
|
||||
// Check and send alerts if needed (fire and forget)
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get deviceId from the saved telemetry record
|
||||
var deviceId = dto.DeviceId;
|
||||
if (deviceId > 0)
|
||||
{
|
||||
await alertService.CheckAndSendAlertsAsync(deviceId, dto, cancellationToken);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Log error but don't fail the request
|
||||
// Errors are logged in AlertService
|
||||
}
|
||||
}, cancellationToken);
|
||||
|
||||
return Ok(id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user