using FAMBLL.Depreciation; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FAMSL.EndPoints.Depreciation { public class GetDepreciation : BaseEndpoint> { private readonly IDepreciationBLL _DepreciationBLL; public GetDepreciation(IDepreciationBLL IDepreciationBLL) { _DepreciationBLL = IDepreciationBLL; } public override void Configure() { Get("/Depreciation/GetDepreciation"); AllowAnonymous(); } public record GetDepreciationParameters( [property: FromHeader] string Login, [property: QueryParam] int DepreciationId ); protected override string? GetCacheKey(GetDepreciationParameters Parameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(Parameters.DepreciationId!, EntityConstant.OBJECTDEPRECIATION, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetDepreciationParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _DepreciationBLL.GetDepreciation(req.DepreciationId, 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); } } } }