using FastEndpoints; using FrameworkBLL.GCM; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.GCM { public class GetSelectListGCM : BaseEndpoint> { private readonly IGCMBLL _GCMBLL; public GetSelectListGCM(IGCMBLL IGCMBLL) => _GCMBLL = IGCMBLL; public override void Configure() { Post("/GCM/GetSelectListGCM"); AllowAnonymous(); } public record Parameters( [property: FromHeader] string Login, [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult, [property: FromBody] CriteriaDTO CriteriaDTO ); protected override string? GetCacheKey(Parameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync( Parameters req, LoginDTO LoginDTO, CancellationToken ct) { int firstNumber = req.FirstNumber; int maxResult = req.MaxResult; // Apply default pagination when caller sends 0/0 (mirrors GB4 behaviour) if (firstNumber == 0 && maxResult == 0) maxResult = 10; var data = await _GCMBLL.GetSelectListGCM(firstNumber, maxResult, req.CriteriaDTO, LoginDTO); int totalCount = await _GCMBLL.GetSelectListGCMCount(req.CriteriaDTO, LoginDTO); var response = await GB5Shared.ResponseStandard.Response .CreateSuccessResponse(data, CacheKeyLevel.NOT_REQUIRED, LoginDTO); response.Total = totalCount; return response; } } }