using AccountsBLL.AccountReports.AccountLedger; using AccountsDAL.DTO.AccountsReports; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.DTO.Report; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace AccountsSL.EndPoints.AccountReports { // Separate endpoint/query from AccountLedgerReport — Summary is a real SQL-side GROUP BY // (Opening/Debit/Credit/Closing per account), not a different column layout of the same rows, so it // can't share ExecuteReportAsync with Normal/Detail (see the AccountLedger migration plan's // MetaReport/ReportView section on why ReportView's presentation-only model doesn't stretch to cover // this). Its MREPORTVIEW row is still tagged with the same ApplicableMenuIds as Normal/Detail's, so // it appears alongside them in the same view switcher. public class AccountLedgerSummaryReport : BaseReportEndpoint { private readonly IAccountLedgerSummaryBLL _bll; public AccountLedgerSummaryReport(IAccountLedgerSummaryBLL bll) { _bll = bll; } public override void Configure() { Post("/AccountReports/AccountLedgerSummaryReport"); AllowAnonymous(); } public record AccountLedgerSummaryReportParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult ); protected override async IAsyncEnumerable ExecuteReportAsync( AccountLedgerSummaryReportParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { // Summary has no dedicated streaming DAL path (its result set is already grouped/bounded by // distinct accounts, not raw transaction volume) — export reuses the same paged query at a // high cap rather than duplicating a stream method for a result shape that's inherently small. var result = await _bll.GetAccountLedgerSummaryReport( 1, int.MaxValue, req.ReportCallingDTO.CriteriaDTO, sortBy: null, req.ReportCallingDTO.MenuId, login).ConfigureAwait(false); foreach (var row in result.Items) { ct.ThrowIfCancellationRequested(); yield return row; } } protected override async Task> ExecutePagedAsync( AccountLedgerSummaryReportParameter req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetAccountLedgerSummaryReport( req.FirstNumber, req.MaxResult, req.ReportCallingDTO.CriteriaDTO, sortBy: null, req.ReportCallingDTO.MenuId, login).ConfigureAwait(false); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result, CacheKeyLevel.NOT_REQUIRED, login).ConfigureAwait(false); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 500).ConfigureAwait(false); } } } }