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, "KPI Summary" tile. Composes three sources -- see // InventoryKPISummaryDTO.cs for the full breakdown (bespoke Total Stock Value, FINVENTORY-fact // Movement Value, reused Reorder Breach / Ageing tile numbers). public class GetInventoryKPISummary : BaseReportEndpoint { private readonly IInventoryReportsBLL _bll; public GetInventoryKPISummary(IInventoryReportsBLL bll) { _bll = bll; } public override void Configure() { Post("/InventoryReports/GetInventoryKPISummary"); AllowAnonymous(); } public record GetInventoryKPISummaryParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, [property: QueryParam] int OuId, [property: QueryParam] DateTime? PeriodFromDate, [property: QueryParam] DateTime? PeriodToDate ); protected override async IAsyncEnumerable ExecuteReportAsync( GetInventoryKPISummaryParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { var result = await _bll.GetInventoryKPISummary( req.OuId, login.ClientId, req.PeriodFromDate, req.PeriodToDate, login, ct).ConfigureAwait(false); yield return result; } protected override async Task> ExecutePagedAsync( GetInventoryKPISummaryParameter req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetInventoryKPISummary( req.OuId, login.ClientId, req.PeriodFromDate, req.PeriodToDate, 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); } } } }