using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.OverTime; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.OverTime { // GB4 route: OverTime.svc/Post/Auto/Over/Time/?OUId={..}&FromDate={..}&ToDate={..} (GET). // Per explicit user instruction this is implemented as a POST FastEndpoint carrying the // same OUId/FromDate/ToDate contract (GET with only query params and no body is unusual // for a state-changing batch operation — POST matches FastEndpoints/GB5 conventions for // every other OverTime write operation in this migration). // // NOTE: this is a long-running synchronous batch loop (every OU x every day in range). // See final migration report — this should likely move to a background job. public class PostAutoOverTime : BaseEndpoint> { private readonly IOverTimeBLL _OverTimeBLL; public PostAutoOverTime(IOverTimeBLL OverTimeBLL) { _OverTimeBLL = OverTimeBLL; } public override void Configure() { Post("/OverTime/PostAutoOverTime"); AllowAnonymous(); } public record PostAutoOverTimeParameters( [property: QueryParam] int OUId, [property: QueryParam] string FromDate, [property: QueryParam] string ToDate, [property: FromHeader] string Login ); protected override string? GetCacheKey(PostAutoOverTimeParameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync( PostAutoOverTimeParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _OverTimeBLL.PostAutoOverTime(req.OUId, req.FromDate, req.ToDate, loginDTO, ct); 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); } } } }