using ComplianceBLL.ComplianceAlert; using ComplianceDAL.DTO.Analytics; using Dapr; using GB5Shared.DTO.Framework.Login; using Microsoft.AspNetCore.Mvc; namespace ComplianceSL.Subscriptions; [ApiController] public class AlertCheckSubscriber : ControllerBase { private readonly IComplianceAlertBLL _alertBll; private readonly ILogger _logger; public AlertCheckSubscriber(IComplianceAlertBLL alertBll, ILogger logger) { _alertBll = alertBll; _logger = logger; } // Triggered by a nightly Dapr scheduled job that publishes compliance.alerts.check. // Evaluates filing deadlines, EWB expiries, missing IRNs, and rejected artifacts // and creates/updates TCOMPLIANCE_ALERT records for each finding. [Topic("pubsub", "compliance.alerts.check")] [HttpPost("/Compliance/Subscriptions/AlertCheck")] public async Task HandleAlertCheckAsync( [FromBody] AlertCheckEvent evt, CancellationToken ct) { _logger.LogInformation( "Alert check event received for client {ClientId} at {CheckedAt}", evt.ClientId, evt.CheckedAt); try { var login = new LoginDTO { ClientId = int.Parse(evt.ClientId), DatabaseName = evt.DatabaseName, UserId = evt.UserId }; await _alertBll.RunAlertCheckAsync(login, ct); _logger.LogInformation("Alert check completed for client {ClientId}", evt.ClientId); return Ok(); } catch (Exception ex) { _logger.LogError(ex, "Alert check failed for client {ClientId}", evt.ClientId); return StatusCode(500, ex.Message); } } }