diff --git a/DoliMiddlewareApi/Controllers/InvoicesController.cs b/DoliMiddlewareApi/Controllers/InvoicesController.cs index ebbb668..7de5683 100644 --- a/DoliMiddlewareApi/Controllers/InvoicesController.cs +++ b/DoliMiddlewareApi/Controllers/InvoicesController.cs @@ -26,9 +26,10 @@ public class InvoicesController : ControllerBase public async Task>> GetInvoices( [FromQuery] int limit = 50, [FromQuery] [Range(1, int.MaxValue)] int page = 1, - [FromQuery] string? status = null) + [FromQuery] string? status = null, + [FromQuery] [StringLength(100)] string? search = null) { - var invoices = await _invoiceService.GetInvoicesAsync(limit, page, status); + var invoices = await _invoiceService.GetInvoicesAsync(limit, page, status, search); return Ok(invoices); } @@ -76,4 +77,4 @@ public class InvoicesController : ControllerBase var result = await _invoiceService.AddInvoiceLineAsync(id, lineDto); return CreatedAtAction(nameof(GetInvoice), new { id }, result); } -} \ No newline at end of file +} diff --git a/DoliMiddlewareApi/Services/InvoiceService.cs b/DoliMiddlewareApi/Services/InvoiceService.cs index d907283..c034df1 100644 --- a/DoliMiddlewareApi/Services/InvoiceService.cs +++ b/DoliMiddlewareApi/Services/InvoiceService.cs @@ -19,7 +19,8 @@ public class InvoiceService(IDolibarrApiClient apiClient) public async Task> GetInvoicesAsync( int limit = 50, int page = 1, - string? status = null) + string? status = null, + string? search = null) { // empieza por 1 para el frontend var endpoint = $"invoices?limit={limit}&page={page - 1}"; @@ -29,6 +30,13 @@ public class InvoiceService(IDolibarrApiClient apiClient) endpoint += $"&status={status}"; } + if (!string.IsNullOrWhiteSpace(search)) + { + search=search.Trim().ToUpperInvariant(); + var filter = $"(t.ref:like:'{search}%')"; + endpoint += $"&sqlfilters={Uri.EscapeDataString(filter)}"; + } + var dataList = await apiClient.GetCollectionAsync(endpoint); return dataList.Select(InvoiceMapper.MapToInvoiceDto).ToList(); } @@ -94,4 +102,4 @@ public class InvoiceService(IDolibarrApiClient apiClient) await apiClient.PutAsync($"invoices/{id}", current); } -} \ No newline at end of file +}