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 VerifyClientDomain : BaseEndpoint> { private readonly IClientDomainBLL _bll; private readonly DomainCacheService _domainCache; public VerifyClientDomain(IClientDomainBLL bll, DomainCacheService domainCache) { _bll = bll; _domainCache = domainCache; } public override void Configure() { Post("/ClientDomain/VerifyClientDomain"); AllowAnonymous(); } public record VerifyClientDomainParameters( [property: FromHeader] string Login, [property: QueryParam] int DomainId ); protected override string? GetCacheKey(VerifyClientDomainParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( VerifyClientDomainParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _bll.VerifyClientDomain(req.DomainId, loginDTO); // Force cache refresh — the verified domain should be resolved from next request _ = _domainCache.RefreshAsync(ct); 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); } } } }