Leandro Hernan Rojas 8303751ab7
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 6m5s
UpClean de Codigo
2025-08-27 17:42:48 -03:00

45 lines
1.5 KiB
C#

using System.Net.Http.Json;
using Domain.Dtos.Stock;
using Domain.Generics;
public class StockScanService : IStockScanService
{
private readonly HttpClient _http;
public StockScanService(HttpClient http)
{
_http = http;
}
/// <summary>
/// Envía el RAW al backend (parsea + busca) y devuelve el primer match mapeado a la UI.
/// </summary>
public async Task<StockItemSelectionDto?> ParseAndMatchAsync(string rawInput, int locationId)
{
if (string.IsNullOrWhiteSpace(rawInput))
return null;
var payload = new StockScanRawRequest(rawInput, locationId, Page: 1, PageSize: 10);
using var resp = await _http.PostAsJsonAsync("/api/lsstockscan/parse-and-search", payload);
if (!resp.IsSuccessStatusCode)
return null;
var pr = await resp.Content.ReadFromJsonAsync<PagedResult<StockItemScanResultDto>>();
var first = pr?.Items?.FirstOrDefault();
if (first is null) return null;
return new StockItemSelectionDto
{
StockItemId = first.StockItemId,
ProductId = first.ProductId,
ProductName = first.ProductName,
Batch = first.Batch ?? string.Empty,
Expiration = first.Expiration?.ToDateTime(TimeOnly.MinValue),
Quantity = first.AvailableQty,
LocationId = first.LocationId ?? locationId,
TraceabilityType = first.TraceabilityType,
Serial = first.Serial ?? string.Empty
};
}
}