using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.DTO.Report; using GB5Shared.FastEndPoint; using MMBLL.InventoryReports; using MMDAL.DTO.InventoryReports; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.InventoryReports { // Inventory Overview Dashboard, "Stock Overview / Stock Position Analysis" tile -- also folds // in the WIP-by-stage sub-panel (see StockOverviewDashboardDTO.cs for why that's not a // separate tile). New aggregation over TSTOCKPOSITION, GB5's own real, live-updated table // (previously only exposed as a single-item internal lookup). public class GetStockOverviewDashboard : BaseReportEndpoint { private readonly IInventoryReportsBLL _bll; public GetStockOverviewDashboard(IInventoryReportsBLL bll) { _bll = bll; } public override void Configure() { Post("/InventoryReports/GetStockOverviewDashboard"); AllowAnonymous(); } public record GetStockOverviewDashboardParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, [property: QueryParam] int OuId ); protected override async IAsyncEnumerable ExecuteReportAsync( GetStockOverviewDashboardParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { var result = await _bll.GetStockOverviewDashboard(req.OuId, login, ct).ConfigureAwait(false); foreach (var row in result.ByCategory) { ct.ThrowIfCancellationRequested(); yield return row; } } protected override async Task> ExecutePagedAsync( GetStockOverviewDashboardParameter req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetStockOverviewDashboard(req.OuId, login, ct).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); } } } }