using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.DTO.Report; using GB5Shared.FastEndPoint; using PayRollBLL.Employee; using PayRollDAL.DTO.Employee; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.Employee { // Route name matches the legacy GB4 Employee.svc/ProfileReport endpoint exactly — // MWEBSERVICE -1399995297 is repointed at this route (see the HRMS migration script). // Reuses the existing legacy REPORTID -1399952970 / MENUID -1399993358 "Employee Profile" // report-view metadata already seeded in this DB — no new MREPORT rows needed. public class GetEmployeeProfileReport : BaseReportEndpoint { private readonly IEmployeeBLL _EmployeeBLL; public GetEmployeeProfileReport(IEmployeeBLL IEmployeeBLL) { _EmployeeBLL = IEmployeeBLL; } public override void Configure() { Post("/Employee/GetEmployeeProfileReport"); // Roles("User") throws 500 here — no host in this repo configures AddAuthentication, // so FastEndpoints has no scheme to challenge against (repo-wide gap, not specific to // this endpoint). AllowAnonymous matches every other endpoint in this SL module today. AllowAnonymous(); } public record GetEmployeeProfileReportParameter( [property: FromHeader] string Login, [property: FromBody] ReportCallingDTO ReportCallingDTO, [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult ); // REQUIRED — streams every matching row, used for exports and NDJSON. Ignores paging. protected override async IAsyncEnumerable ExecuteReportAsync( GetEmployeeProfileReportParameter req, LoginDTO login, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct) { var (items, _) = await _EmployeeBLL.GetEmployeeProfileReport( 1, int.MaxValue, req.ReportCallingDTO.CriteriaDTO, login, ct).ConfigureAwait(false); foreach (var row in items) { ct.ThrowIfCancellationRequested(); yield return row; } } // OVERRIDE — the UI table path, with real SQL-level paging + totals (fixes the legacy // GB4 bug where the master list was unpaged and Response.Total was never set). protected override async Task> ExecutePagedAsync( GetEmployeeProfileReportParameter req, LoginDTO login, CancellationToken ct) { try { var (items, total) = await _EmployeeBLL.GetEmployeeProfileReport( req.FirstNumber, req.MaxResult, req.ReportCallingDTO.CriteriaDTO, login, ct).ConfigureAwait(false); var response = await GB5Shared.ResponseStandard.Response .CreateSuccessResponse(items, CacheKeyLevel.NOT_REQUIRED, login).ConfigureAwait(false); response.Total = total; return response; } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 500).ConfigureAwait(false); } } } }