using FastEndpoints; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.Periodic; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.Endpoints.Periodic { // GB4: Periodic.svc/GetPeriodic — IPeriodic.cs WebInvoke UriTemplate // "/GetPeriodic/?PayPeriodId={PayPeriodId}&FirstNumber={FirstNumber}&MaxResult={MaxResult}", // Method = "POST" (the operation's own doc-comment says GET, but the live attribute is POST — // verified directly against IPeriodic.cs before porting). public class GetPeriodic : BaseEndpoint> { private readonly IPeriodicBLL _PeriodicBLL; public GetPeriodic(IPeriodicBLL PeriodicBLL) { _PeriodicBLL = PeriodicBLL; } public override void Configure() { Post("/Periodic/GetPeriodic"); AllowAnonymous(); } public record GetPeriodicParameters( [property: FromHeader] string Login, [property: FromBody] CriteriaDTO CriteriaDTO, [property: QueryParam] int PayPeriodId, [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult ); // No GetCacheKey override — matches the existing GetPeriodicList endpoint's convention // (default null; CacheKeyLevel.NOT_REQUIRED below skips Dapr caching for this read). protected override async Task> ExecuteAsync( GetPeriodicParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var (items, total) = await _PeriodicBLL.GetPeriodic( req.PayPeriodId, req.FirstNumber, req.MaxResult, req.CriteriaDTO, loginDTO!, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( new { Items = items, Total = total }, CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }