using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PartnerBLL.ClientDetail; using PartnerDAL.DTO.ClientDetail; using static GB5Shared.GB5Constant.Constant; namespace PartnerSL.EndPoints.ClientDetail { // Registers a NEW ConnectionName against an EXISTING physical database — e.g. // ConnectionName "Sankar" pointing at DatabaseName "DEMO", alongside other // ConnectionNames already using that same database, each with its own independent // PartnerProductId assignment for white-labeling. This is the opposite case from core // provisioning's /lic/Onboarding.svc/OnboardClient, which creates a brand-new physical // database per client and gives the caller no control over ConnectionName/DatabaseName // at all (confirmed: neither field exists on that request). No schema change to // MSERVERCONFIG — every value here is caller-supplied and validated (ConnectionName // uniqueness, DatabaseName must belong to an existing active connection) before insert. // // After calling this, use CreateClientDetail then AssignPartnerProduct with the same // ClientId/ClientSiteId to complete the white-labeling assignment. public class RegisterConnection : BaseEndpoint> { private readonly IClientDetailBLL _bll; public RegisterConnection(IClientDetailBLL bll) => _bll = bll; public override void Configure() { Post("/ClientDetail/RegisterConnection"); AllowAnonymous(); } public record RegisterConnectionParameters( [property: FromHeader] string Login, [property: FromBody] RegisterConnectionDTO RegisterConnectionDTO ); protected override string? GetCacheKey(RegisterConnectionParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( RegisterConnectionParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _bll.RegisterConnection(req.RegisterConnectionDTO, loginDTO); 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); } } } }