using FastEndpoints; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMBLL.LotDetail; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.LotDetail { /// /// Lot stock picklist. /// Migrated from GB4 POST /mms/Lot.svc/LotDetail/SelectList /// (LotService.GetSelectListLotForLotDetail). The GB4 `/mms` prefix is dropped — /// prefixing is handled at the gateway, not by the endpoint. /// public class GetSelectListLotDetail : BaseEndpoint> { private readonly ILotDetailBLL _LotDetailBLL; public GetSelectListLotDetail(ILotDetailBLL ILotDetailBLL) { _LotDetailBLL = ILotDetailBLL; } public override void Configure() { Post("/LotDetail/GetSelectListLotDetail"); AllowAnonymous(); } public record GetSelectListLotDetailParameters( [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult, [property: FromHeader] string Login, [property: FromBody] CriteriaDTO CriteriaDTO ); // No GetCacheKey override — live stock balances must never be served from cache. protected override async Task> ExecuteAsync( GetSelectListLotDetailParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { int firstNumber = req.FirstNumber; int maxResult = req.MaxResult; // GB4 read these defaults from common config ("FromNumber"/"ToNumber"); // GB5 has no such config path, so use the same fallback as GetSelectListItem. if (firstNumber == 0 && maxResult == 0) { firstNumber = 0; maxResult = 10; } var result = await _LotDetailBLL .GetSelectListLotDetail(firstNumber, maxResult, req.CriteriaDTO, LoginDTO!, ct); // -1/-1 = unpaged, so the count reflects the whole filtered result set. // GB4 stubbed this and always returned 0. int total = Convert.ToInt32(await _LotDetailBLL .GetSelectListLotDetail(-1, -1, req.CriteriaDTO, LoginDTO!, ct, true)); var response = await GB5Shared.ResponseStandard.Response .CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, LoginDTO); response.Total = total; return response; } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO, ex.Message, 500); } } } }