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 { // Generic fact-posting trigger for any MWAREHOUSEFACT row sharing FFINANCE's family (OU+Day // grain, TVOUCHER/MACCOUNT/MACCOUNTGROUP source, nature-bucket aggregation) — see the plan // file's "Extension — Generalizing to Admin-Defined Fact Tables" section. Adding a new fact // table within this family (create the physical table via SqlWorkbench/DBA, then insert // MWAREHOUSEFACT/MWAREHOUSEMEASURE/MWAREHOUSEMEASUREPOSTINGRULE rows) needs zero code beyond // calling this endpoint with that table's FactId. PostFFinance.cs remains a separate, untouched // thin wrapper hardcoding FactId=2 for backward compatibility with its already-deployed callers. public class PostFact : BaseEndpoint> { private readonly IWarehouseFactPostingBLL _bll; public PostFact(IWarehouseFactPostingBLL bll) { _bll = bll; } public override void Configure() { Post("/Warehouse/PostFact"); AllowAnonymous(); } public record PostFactParameters( [property: FromHeader] string Login, [property: FromBody] PostFactRequestDTO Request ); public class PostFactRequestDTO { public int FactId { get; set; } public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } // Null/empty = every active OU. Explicit list = a targeted/manual repost. public List? OuIds { get; set; } } protected override async Task> ExecuteAsync( PostFactParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _bll.PostFactAsync( req.Request.FactId, 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); } } } }