using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.GateEntry; using PayRollDAL.DTO.GateEntry; using System.Collections.Generic; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.GateEntry { /// /// Accepts raw scanner / event-sheet data (supplier name, material code, batch no, PO no, etc.) /// and returns a fully-resolved TGATEENTRYDETAIL structure with all database IDs populated. /// /// The caller can submit one or more line items in a single request (single = list with one element). /// Per-row errors are returned inside each result's Errors array — the response HTTP status is /// always 200; inspect IsValid to decide whether the row can be passed to SaveGateEntry. /// /// Typical flow: /// 1. POST /GateEntry/ResolveGateEntryDetail → get resolved detail rows /// 2. Review any Errors, fix inputs if needed /// 3. POST /GateEntry/SaveGateEntry with the resolved GateEntryDTO /// public class ResolveGateEntryDetail : BaseEndpoint> { private readonly IGateEntryBLL _GateEntryBLL; public ResolveGateEntryDetail(IGateEntryBLL gateEntryBLL) { _GateEntryBLL = gateEntryBLL; } public override void Configure() { Post("/GateEntry/ResolveGateEntryDetail"); AllowAnonymous(); } public record ResolveGateEntryDetailParameters( [property: FromHeader] string Login, [property: FromBody] List Items ); // Write endpoint — no cache //protected override string? GetCacheKey( // ResolveGateEntryDetailParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( ResolveGateEntryDetailParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _GateEntryBLL.ResolveGateEntryDetails( req.Items, loginDTO); 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); } } } }