using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using Newtonsoft.Json; using PartnerBLL.ClientDetail; using static GB5Shared.GB5Constant.Constant; namespace PartnerSL.EndPoints.ClientDetail { // Lists every site (CLIENTSITEID) for a client together with its current // PartnerProductId assignment, so the FE can show/change each site's partner // without any manual SQL. public class GetClientDetailList : BaseEndpoint> { private readonly IClientDetailBLL _bll; public GetClientDetailList(IClientDetailBLL bll) => _bll = bll; public override void Configure() { Get("/ClientDetail/GetClientDetailList"); AllowAnonymous(); } public record GetClientDetailListParameters( [property: FromHeader] string Login, [property: QueryParam] int ClientId ); protected override string? GetCacheKey(GetClientDetailListParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( GetClientDetailListParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _bll.GetClientDetailList(req.ClientId, loginDTO); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( JsonConvert.SerializeObject(result), CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }