add smsRecievers field and send alert messages to user device
This commit is contained in:
@@ -25,32 +25,44 @@ public class TelemetryController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("AddData")]
|
||||
public async Task<ActionResult<int>> Create([FromQuery] TelemetryDto telementry, CancellationToken cancellationToken)
|
||||
public async Task<ActionResult<string>> Create([FromQuery] TelemetryDto telementry, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
telementry.TimestampUtc = DateTime.UtcNow;
|
||||
var id = await telemetryService.AddAsync(telementry, cancellationToken);
|
||||
|
||||
// Check and send alerts if needed (fire and forget)
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get deviceId from the saved telemetry record
|
||||
var deviceId = telementry.DeviceId;
|
||||
if (deviceId > 0)
|
||||
{
|
||||
await alertService.CheckAndSendAlertsAsync(deviceId, telementry, cancellationToken);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Log error but don't fail the request
|
||||
// Errors are logged in AlertService
|
||||
}
|
||||
}, cancellationToken);
|
||||
string? message;
|
||||
|
||||
return Ok(id);
|
||||
var deviceId = telementry.DeviceId;
|
||||
if(deviceId > 0)
|
||||
{
|
||||
message = await alertService.CheckAndSendAlertsAsync(deviceId, telementry, cancellationToken);
|
||||
if(!string.IsNullOrEmpty(message))
|
||||
{
|
||||
return Ok(message);
|
||||
}
|
||||
}
|
||||
|
||||
// Check and send alerts if needed (fire and forget)
|
||||
// _ = Task.Run(async () =>
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// // Get deviceId from the saved telemetry record
|
||||
// var deviceId = telementry.DeviceId;
|
||||
// if (deviceId > 0)
|
||||
// {
|
||||
// await alertService.CheckAndSendAlertsAsync(deviceId, telementry, cancellationToken);
|
||||
// }
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// // Log error but don't fail the request
|
||||
// // Errors are logged in AlertService
|
||||
// }
|
||||
// }, cancellationToken);
|
||||
|
||||
return Ok(id + "");
|
||||
}
|
||||
|
||||
[HttpGet("minmax")]
|
||||
|
||||
Reference in New Issue
Block a user