using FastEndpoints; using GB5Shared.DaprCache; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMBLL.Allocation; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.Allocation { // ───────────────────────────────────────────────────────────────────── // GetPendingAllocations – POST /Allocation/GetPendingAllocations // // Accepts: // • Login header (LoginDTO, extracted by BaseEndpoint) // • CriteriaDTO body (existing format, all legacy clients continue to work) // • SearchText query param (optional — new clients; legacy embeds in body) // • PageOffset / PageSize query params // // Cache: CLIENT_LEVEL — shared across all users of the same client/tenant. // The criteria body + paging params are hashed by KeyGeneration. // ───────────────────────────────────────────────────────────────────── public class GetPendingAllocations : BaseEndpoint> { private readonly IPendingAllocationBLL _bll; public GetPendingAllocations(IPendingAllocationBLL bll) => _bll = bll; public override void Configure() { Post("/Allocation/GetPendingAllocations"); AllowAnonymous(); } public record Params( [property: FromHeader] string Login, [property: FromBody] CriteriaDTO CriteriaDTO, [property: QueryParam] string? SearchText = null, [property: QueryParam] int PageOffset = 0, [property: QueryParam] int PageSize = 100 ); protected override string? GetCacheKey(Params req, LoginDTO login) { try { return KeyGenerator.KeyGeneration( req.CriteriaDTO, req.PageOffset, CacheKeyLevel.CLIENT_LEVEL, login); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync( Params req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetPendingAllocations( req.CriteriaDTO, req.SearchText, req.PageOffset, req.PageSize, login, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result, CacheKeyLevel.CLIENT_LEVEL, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.CLIENT_LEVEL, login, ex.Message, 500); } } } }