using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.DTO.Promotion; using GB5Shared.FastEndPoint; using GB5Shared.Promotion; using static GB5Shared.GB5Constant.Constant; namespace WiSL.EndPoints.Promotion { // ============================================================ // ExportForPromotionBridge — internal service-to-service endpoint, called only by // FrameworkBLL's RemoteHttpPromotionAdapter (running in FrameworkSL's own process). Placed in // WiSL but serves EVERY promotable entity consolidated into this same Host process // (EngagementHost) — resolution is by EntityTypeCode via keyed DI, not tied to WorkInstruction // specifically, so CMS's own promotable entities (once wired) reuse these same 3 endpoints // rather than duplicating them per module. See GB5Shared/DTO/Promotion/PromotionBridgeDTOs.cs // and TMSSL's identical set (the original template) for the full reasoning. // ============================================================ public class ExportForPromotionBridge : BaseEndpoint> { private readonly IServiceProvider _ServiceProvider; public ExportForPromotionBridge(IServiceProvider serviceProvider) { _ServiceProvider = serviceProvider; } public override void Configure() { Post("/PromotionBridge/ExportForPromotion"); AllowAnonymous(); } public record Parameters( [property: FromBody] PromotionBridgeExportRequestDTO Body, [property: FromHeader] string Login ); protected override string? GetCacheKey(Parameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync(Parameters req, LoginDTO loginDTO, CancellationToken ct) { try { var bundle = await PromotionBridgeService.ExportAsync( _ServiceProvider, req.Body.EntityTypeCode, req.Body.OriginEntityId, loginDTO, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(bundle, CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }