using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMBLL.MaterialAccount; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.MaterialAccount { public class GetMaterialAccount : BaseEndpoint { private readonly IMaterialAccountBLL _MaterialAccountBLL; public GetMaterialAccount(IMaterialAccountBLL MaterialAccountBLL) { _MaterialAccountBLL = MaterialAccountBLL; } public override void Configure() { Get("/MaterialAccount/GetMaterialAccount"); AllowAnonymous(); } public record GetMaterialAccountParameters( [property: QueryParam] int MaterialAccountId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetMaterialAccountParameters parameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(parameters.MaterialAccountId!, EntityConstant.OBJECTMATERIALACCOUNT, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetMaterialAccountParameters parameters, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _MaterialAccountBLL.GetMaterialAccount(parameters.MaterialAccountId, 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); } } } }