using AccountsBLL.Warehouse; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace AccountsSL.EndPoints.Warehouse { // FFINANCE posting trigger — the JobEngine webhook target (see the plan file's "Data Warehouse // Posting" section: a new MJOBDEFINE row + MWEBSERVICE row + TSCHEDULER cron point at this // endpoint, replacing legacy's self-polling MDATAWAREHOUSE model entirely). Also directly // callable for a manual/full-range repost via JobEngine's own TriggerJob-with-explicit-params // path — this endpoint itself doesn't distinguish "scheduled" from "manual," that's purely a // JobEngine-side concern. public class PostFFinance : BaseEndpoint> { // FFINANCE is FACTID=2 (confirmed live in MWAREHOUSEFACT, Analytics_Phase1A_Warehouse_ // Registry_*.sql) — this endpoint is now a thin, hardcoded-FactId wrapper over the generic // IWarehouseFactPostingBLL so the already-deployed, already-verified route/shape keeps // working unchanged. See PostFact.cs for posting any OTHER fact table in the same family. private const int FFINANCE_FACT_ID = 2; private readonly IWarehouseFactPostingBLL _bll; public PostFFinance(IWarehouseFactPostingBLL bll) { _bll = bll; } public override void Configure() { Post("/Warehouse/PostFFinance"); AllowAnonymous(); } public record PostFFinanceParameters( [property: FromHeader] string Login, [property: FromBody] PostFFinanceRequestDTO Request ); public class PostFFinanceRequestDTO { public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } // Null/empty = every active OU (the scheduled job's default). Explicit list = a // targeted/manual repost. public List? OuIds { get; set; } } protected override async Task> ExecuteAsync( PostFFinanceParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _bll.PostFactAsync( FFINANCE_FACT_ID, req.Request.DateFrom, req.Request.DateTo, req.Request.OuIds, LoginDTO, ct).ConfigureAwait(false); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result, CacheKeyLevel.NOT_REQUIRED, LoginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO, ex.Message, 500); } } } }