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 { // Replaces the manual "UPDATE MCLIENTDETAILS SET PARTNERPRODUCTID = ..." step — // assigns (or clears, with PartnerProductId = -1) which PartnerProduct a client's // site is white-labeled under. Validates the PartnerProductId exists in the caller's // own tenant DB before writing, so this can never point a client at a partner product // that isn't actually present in that client's own ProductionDB. public class AssignPartnerProduct : BaseEndpoint> { private readonly IClientDetailBLL _bll; public AssignPartnerProduct(IClientDetailBLL bll) => _bll = bll; public override void Configure() { Post("/ClientDetail/AssignPartnerProduct"); AllowAnonymous(); } public record AssignPartnerProductParameters( [property: FromHeader] string Login, [property: FromBody] ClientDetailDTO ClientDetailDTO ); protected override string? GetCacheKey(AssignPartnerProductParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( AssignPartnerProductParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _bll.AssignPartnerProduct(req.ClientDetailDTO, 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); } } } }