using System.Text.Json; using Dapr; using EntitlementBLL.Onboarding; using Microsoft.AspNetCore.Mvc; namespace EntitlementSL.Subscriptions; // sqlworkbench.changerequest.executed -> ResumeAfterProvisioningExecutedAsync. Published by // SwBLL.ChangeRequest.ChangeRequestBLL.Execute() via GB5Shared.EventLogPublish.PublishEventLogAsync // on Dapr pubsub component "pubsub" (confirmed from EventLogPublish's own source — it always // publishes on "pubsub", never the "goodbooks-pubsub" component GoLiveDeclaredSubscriber uses // for its own, differently-sourced event). // // Binds the raw payload as JsonElement rather than a typed record deliberately: EventLogPublish // wraps the real payload in a PublishDTO envelope whose Request.Data field is itself a // double-JSON-encoded string (confirmed by reading EventLogPublish.cs directly) — parsing that // reliably from here would be fragile. Instead this handler treats the event purely as a // "check now" wake-up signal: ResumeAfterProvisioningExecutedAsync re-verifies every // still-waiting ProvisioningJob's own tracked SwChangeRequestId by calling SqlWorkbench // directly, so an imprecise or even unparseable payload can never cause a wrong job to // resume, or a real completion to be missed. [ApiController] public class ClientProvisioningExecutedSubscriber : ControllerBase { private readonly IClientOnboardingOrchestratorBLL _Orchestrator; private readonly ILogger _Logger; public ClientProvisioningExecutedSubscriber( IClientOnboardingOrchestratorBLL orchestrator, ILogger logger) { _Orchestrator = orchestrator; _Logger = logger; } [Topic("pubsub", "sqlworkbench.changerequest.executed")] [HttpPost("/lic/Subscriptions/ClientProvisioningExecuted")] public async Task HandleAsync([FromBody] JsonElement payload, CancellationToken ct) { try { await _Orchestrator.ResumeAfterProvisioningExecutedAsync(ct); return Ok(); } catch (Exception ex) { _Logger.LogError(ex, "ClientProvisioningExecutedSubscriber failed to resume onboarding."); return StatusCode(500, ex.Message); } } }