using AccountsBLL.TDSCategory; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace AccountsSL.EndPoints.TDSCategory { // Faithful port of GB4 TDSCategory.svc's GetTDSCategoryForAccount — given an account, returns // every MTDSCATEGORY row that references it in any of its four role-account slots // (Deduction/Paid/Suffered/Claim). public class GetTDSCategoryForAccount : BaseEndpoint> { private readonly ITDSCategoryBLL _TDSCategoryBLL; public GetTDSCategoryForAccount(ITDSCategoryBLL TDSCategoryBLL) { _TDSCategoryBLL = TDSCategoryBLL; } public override void Configure() { Get("/TDSCategory/Account"); AllowAnonymous(); } public record GetTDSCategoryForAccountParameters( [property: FromHeader] string Login, [property: QueryParam] int AccountId ); // Not cached: the cache key hash is derived only from (ObjectId, ObjectTypeId, login // context) — no per-endpoint salt. Both OBJECTACCOUNT (used by GetAccountParameter.cs, // same AccountId) and OBJECTTDSCATEGORY (used by GetTDSCategory.cs, keyed by // TDSCategoryId — could numerically coincide with an AccountId) risk colliding with an // unrelated endpoint's cached response for this same id. No dedicated EntityConstant // exists for "TDS categories for an account", so this endpoint skips caching entirely // rather than reuse a constant that isn't actually unique to this query. protected override string? GetCacheKey(GetTDSCategoryForAccountParameters Parameters, LoginDTO LoginDTO) => null; protected override async Task> ExecuteAsync(GetTDSCategoryForAccountParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _TDSCategoryBLL.GetTDSCategoryForAccount(req.AccountId, 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); } } } }