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 DeleteCollateral : BaseEndpoint> { private readonly ICollateralBLL _CollateralBLL; public DeleteCollateral(ICollateralBLL collateralBLL) => _CollateralBLL = collateralBLL; public override void Configure() { Delete("/Collateral/DeleteCollateral"); AllowAnonymous(); } public record DeleteCollateralParameters( [property: FromHeader] string Login, [property: QueryParam] int CollateralId ); protected override string? GetCacheKey(DeleteCollateralParameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync(DeleteCollateralParameters req, LoginDTO login, CancellationToken ct) { try { var result = await _CollateralBLL.DeleteCollateral(req.CollateralId, login!, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 500); } } }