using MMBLL.ItemStock; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; using System.Threading; namespace MMSL.EndPoints.ItemStock { public class GetItemStock : BaseEndpoint> { private readonly IItemStockBLL _ItemStockBLL; public GetItemStock(IItemStockBLL ItemStockBLL) { _ItemStockBLL = ItemStockBLL; } public override void Configure() { Get("/ItemStock/GetItemStock"); AllowAnonymous(); } public record GetItemStockParameters( [property: FromHeader] string Login, [property: QueryParam] int ItemStockId ); protected override string? GetCacheKey(GetItemStockParameters Parameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration( Parameters.ItemStockId, EntityConstant.OBJECTITEMSTOCK, CacheKeyLevel.USER_LEVEL, LoginDTO ); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetItemStockParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _ItemStockBLL.GetItemStock(req.ItemStockId, LoginDTO); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result, CacheKeyLevel.USER_LEVEL, LoginDTO ); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.USER_LEVEL, LoginDTO, ex.Message, 500 ); } } } }