using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PartnerBLL.ClientDomain; using PartnerDAL.DTO.ClientDomain; using PartnerSL.Services; using static GB5Shared.GB5Constant.Constant; namespace PartnerSL.EndPoints.ClientDomain { public class SaveClientDomain : BaseEndpoint> { private readonly IClientDomainBLL _bll; private readonly DomainCacheService _domainCache; public SaveClientDomain(IClientDomainBLL bll, DomainCacheService domainCache) { _bll = bll; _domainCache = domainCache; } public override void Configure() { Post("/ClientDomain/SaveClientDomain"); AllowAnonymous(); } public record SaveClientDomainParameters( [property: FromHeader] string Login, [property: FromBody] ClientDomainDTO ClientDomainDTO ); protected override string? GetCacheKey(SaveClientDomainParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( SaveClientDomainParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _bll.SaveClientDomain(req.ClientDomainDTO, loginDTO); // Invalidate cache so the next GetDomainTenant call reflects the new mapping _domainCache.Invalidate(req.ClientDomainDTO.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); } } } }