using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MarketingBLL.Collateral; using static GB5Shared.GB5Constant.Constant; namespace MarketingSL.EndPoints.Collateral; public class GetCollateral : BaseEndpoint> { private readonly ICollateralBLL _CollateralBLL; public GetCollateral(ICollateralBLL collateralBLL) => _CollateralBLL = collateralBLL; public override void Configure() { Get("/Collateral/GetCollateral"); AllowAnonymous(); } public record GetCollateralParameters( [property: QueryParam] int CollateralId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetCollateralParameters req, LoginDTO login) => KeyGenerator.KeyGeneration(req.CollateralId, EntityConstant.OBJECTMARKETINGCOLLATERAL, CacheKeyLevel.CLIENT_LEVEL, login); protected override async Task> ExecuteAsync(GetCollateralParameters req, LoginDTO login, CancellationToken ct) { try { var result = await _CollateralBLL.GetCollateral(req.CollateralId, login!, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.CLIENT_LEVEL, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.CLIENT_LEVEL, login, ex.Message, 500); } } }