using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.DTO.Report; using GB5Shared.FastEndPoint; using MMBLL.MMReports; using MMDAL.DTO.MMReports; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.MMReports { // Procurement Overview Dashboard, Tile 4 -- "Spend Analysis". "Savings"/"Maverick Spend" from // the mockup are dropped -- neither concept exists in GB5 today (see the Procurement dashboard // plan). Ships spend trend, category-wise %, top-suppliers pareto, and contract coverage %. public class GetSpendAnalysisDashboard : BaseReportEndpoint { private readonly IMMReportsBLL _bll; public GetSpendAnalysisDashboard(IMMReportsBLL bll) { _bll = bll; } public override void Configure() { Post("/MMReports/GetSpendAnalysisDashboard"); AllowAnonymous(); } public record GetSpendAnalysisDashboardParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, [property: QueryParam] string BizTransactionClassIds ); protected override async IAsyncEnumerable ExecuteReportAsync( GetSpendAnalysisDashboardParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { var result = await _bll.GetSpendAnalysisDashboard( req.BizTransactionClassIds, req.ReportCallingDTO.CriteriaDTO, login, ct).ConfigureAwait(false); foreach (var row in result.CategoryBreakdown) { ct.ThrowIfCancellationRequested(); yield return row; } } protected override async Task> ExecutePagedAsync( GetSpendAnalysisDashboardParameter req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetSpendAnalysisDashboard( req.BizTransactionClassIds, req.ReportCallingDTO.CriteriaDTO, 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); } } } }