using AccountsBLL.AccountReports.PAndLReport; using AccountsDAL.DTO.Reports; 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 { // GB5-native replacement for the GB4 legacy gb4/as/AccountsReports.svc/PLVertical endpoint — // MREPORT -1399985039 "P and L Vertical", live menus AC20094 (Schedule)/AC20095 (Group)/ // AC20096 (Account), each passing its own GroupType (2/1/0 respectively — see PAndLReportQB.cs // class header for the full migration context). Cut over via MWEBSERVICE.SECONDURITEMPLATE, not // by replacing the legacy URITEMPLATE — see the companion migration. public class PAndLVerticalReport : BaseReportEndpoint { private readonly IPAndLReportBLL _bll; public PAndLVerticalReport(IPAndLReportBLL bll) { _bll = bll; } public override void Configure() { Post("/AccountReports/PAndLVerticalReport"); AllowAnonymous(); } public record PAndLVerticalReportParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, // String, not int — matches the literal {Type} substitution already configured live on // MMENU.URIPARAMETERVALUE for AC20094/95/96 ('ACCOUNTSCHEDULE'/'ACCOUNTGROUP'/'ACCOUNT'), // which this endpoint must accept as-is rather than requiring a menu-metadata change. [property: QueryParam] string? Type, [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult ); private static int ToGroupType(string? type) => type?.ToUpperInvariant() switch { "ACCOUNTGROUP" => 1, "ACCOUNTSCHEDULE" => 2, _ => 0, }; protected override async IAsyncEnumerable ExecuteReportAsync( PAndLVerticalReportParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { var rows = await _bll.GetPAndLVertical( ToGroupType(req.Type), req.ReportCallingDTO.CriteriaDTO, req.ReportCallingDTO.MenuId, login).ConfigureAwait(false); foreach (var row in rows) { ct.ThrowIfCancellationRequested(); yield return row; } } protected override async Task> ExecutePagedAsync( PAndLVerticalReportParameter req, LoginDTO login, CancellationToken ct) { try { var rows = await _bll.GetPAndLVertical( ToGroupType(req.Type), req.ReportCallingDTO.CriteriaDTO, req.ReportCallingDTO.MenuId, login).ConfigureAwait(false); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( rows, 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); } } } }