using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMBLL.MMHead; using MMDAL.DTO.MMHead; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.MMHead { // Ported from GB4's POST /mms/MMHead.svc/Account/Posting/From/FE/?IsSummary= // Previews the account posting entries a document would generate, computed from the // FE-submitted (not-yet-saved) document — contrast with VoucherFormingFromMMHeadProcedureBased, // which forms a voucher from an already-saved one. public class AccountPostingFromFE : BaseEndpoint { private readonly IMMHeadBLL _MMHeadBLL; public AccountPostingFromFE(IMMHeadBLL MMHeadBLL) { _MMHeadBLL = MMHeadBLL; } public override void Configure() { Post("/MMHead/AccountPostingFromFE"); AllowAnonymous(); } public record AccountPostingFromFEParameters( [property: FromBody] MMHeadDTO MMHeadDTO, [property: QueryParam] byte IsSummary, [property: FromHeader] string Login ); // Never cached — this previews a live, unsaved document every call. protected override string? GetCacheKey(AccountPostingFromFEParameters parameters, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( AccountPostingFromFEParameters parameters, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _MMHeadBLL.AccountPostingFromFE( parameters.MMHeadDTO, parameters.IsSummary, loginDTO!, ct); 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); } } } }