using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMBLL.StockValuation; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.StockValuation { public class GetValuationRuns : BaseEndpoint> { private readonly IStockValuationBLL _bll; public GetValuationRuns(IStockValuationBLL bll) { _bll = bll; } public override void Configure() { Get("/StockValuation/GetValuationRuns"); AllowAnonymous(); } public record GetValuationRunsParameters( [property: FromHeader] string Login, [property: QueryParam] int OUID, [property: QueryParam] DateOnly FromDate, [property: QueryParam] DateOnly ToDate ); protected override string? GetCacheKey(GetValuationRunsParameters Parameters, LoginDTO LoginDTO) => null; protected override async Task> ExecuteAsync( GetValuationRunsParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _bll.GetValuationRunsAsync(req.OUID, req.FromDate, req.ToDate, LoginDTO, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result, CacheKeyLevel.NOT_REQUIRED, LoginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO, ex.Message, 500); } } } }