using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMBLL.StockValuation; using MMDAL.DTO.StockValuation; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.StockValuation { public class RunStockValuation : BaseEndpoint> { private readonly IStockValuationBLL _bll; public RunStockValuation(IStockValuationBLL bll) { _bll = bll; } public override void Configure() { Post("/StockValuation/RunStockValuation"); AllowAnonymous(); } public record RunStockValuationParameters( [property: FromHeader] string Login, [property: FromBody] StockValuationFilterDTO Filter ); protected override string? GetCacheKey(RunStockValuationParameters Parameters, LoginDTO LoginDTO) => null; protected override async Task> ExecuteAsync( RunStockValuationParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { req.Filter.TriggeredByUserId = LoginDTO.UserId; var result = await _bll.StartBatchRunAsync(req.Filter, 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); } } } }