All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 6m39s
82 lines
3.3 KiB
C#
82 lines
3.3 KiB
C#
using Core.Interfaces.Stock; // ILSStockScanDom
|
|
using Domain.Dtos.Stock; // StockItemSearchParams, StockItemScanResultDto
|
|
using Domain.Generics; // PagedResult<T>
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Transversal.Services;
|
|
|
|
namespace API.Controllers.Stock
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class LSStockScanController : ControllerBase
|
|
{
|
|
private readonly ILSStockScanDom _service;
|
|
|
|
public LSStockScanController(ILSStockScanDom service)
|
|
{
|
|
_service = service;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Búsqueda paginada de ítems de stock por código/texto, lote y filtros opcionales.
|
|
/// </summary>
|
|
[HttpPost("search")]
|
|
public async Task<ActionResult<PagedResult<StockItemScanResultDto>>> Search([FromBody] StockItemSearchParams searchParams)
|
|
{
|
|
var result = await _service.SearchAsync(searchParams);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// Realiza una búsqueda paginada de ítems de stock utilizando datos ya parseados
|
|
/// (por ejemplo, provenientes de un código GS1 escaneado).
|
|
/// </summary>
|
|
/// <param name="searchParams">
|
|
/// Parámetros de búsqueda ya procesados y listos para filtrar en base de datos,
|
|
/// incluyendo código de producto, lote, fecha de vencimiento, ubicación, etc.
|
|
/// </param>
|
|
/// <returns>
|
|
/// Lista paginada de ítems de stock que cumplen con los filtros especificados.
|
|
/// </returns>
|
|
|
|
[HttpPost("search-parsed")]
|
|
public async Task<ActionResult<PagedResult<StockItemScanResultDto>>> SearchParsed([FromBody] StockItemParsedSearchParams searchParams)
|
|
{
|
|
var result = await _service.SearchParsedAsync(searchParams);
|
|
return Ok(result);
|
|
}
|
|
|
|
// DTO liviano para el request RAW
|
|
public record StockScanRawRequest(string Raw, int LocationId, int Page = 1, int PageSize = 10);
|
|
|
|
/// <summary>
|
|
/// Recibe un escaneo RAW (GS1-128/DataMatrix), lo parsea y ejecuta la búsqueda paginada.
|
|
/// </summary>
|
|
[HttpPost("parse-and-search")]
|
|
public async Task<ActionResult<PagedResult<StockItemScanResultDto>>> ParseAndSearch([FromBody] StockScanRawRequest req)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(req.Raw))
|
|
return BadRequest("Raw is required.");
|
|
|
|
// 1) Parseo GS1 en backend
|
|
var parsed = Gs1CodeParser.Parse(req.Raw.Trim());
|
|
|
|
// 2) Armar parámetros "ya parseados"
|
|
var sp = new StockItemParsedSearchParams
|
|
{
|
|
Gtin = string.IsNullOrWhiteSpace(parsed.Gtin) ? parsed.Variant : parsed.Gtin, // (22) como fallback
|
|
Batch = string.IsNullOrWhiteSpace(parsed.Lot) ? null : parsed.Lot,
|
|
Expiration = parsed.ExpirationDate.HasValue ? DateOnly.FromDateTime(parsed.ExpirationDate.Value) : null,
|
|
Serial = string.IsNullOrWhiteSpace(parsed.Serial) ? null : parsed.Serial,
|
|
LocationId = req.LocationId,
|
|
Page = req.Page,
|
|
PageSize = req.PageSize
|
|
};
|
|
|
|
// 3) Delegar a la misma lógica que ya tenés implementada
|
|
var result = await _service.SearchParsedAsync(sp);
|
|
return Ok(result);
|
|
}
|
|
|
|
}
|
|
}
|