using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PartnerBLL.ClientDomain; using PartnerSL.Services; using static GB5Shared.GB5Constant.Constant; namespace PartnerSL.EndPoints.ClientDomain { public class DeleteClientDomain : BaseEndpoint> { private readonly IClientDomainBLL _bll; private readonly DomainCacheService _domainCache; public DeleteClientDomain(IClientDomainBLL bll, DomainCacheService domainCache) { _bll = bll; _domainCache = domainCache; } public override void Configure() { Delete("/ClientDomain/DeleteClientDomain"); AllowAnonymous(); } public record DeleteClientDomainParameters( [property: FromHeader] string Login, [property: QueryParam] int DomainId, [property: QueryParam] string DomainName ); protected override string? GetCacheKey(DeleteClientDomainParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( DeleteClientDomainParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _bll.DeleteClientDomain(req.DomainId, loginDTO); _domainCache.Invalidate(req.DomainName); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }