From 6bac2c63fb55d5973c2fb8704de0bef77843f8a0 Mon Sep 17 00:00:00 2001 From: JM Date: Wed, 15 Apr 2026 16:49:41 +0200 Subject: [PATCH] =?UTF-8?q?a=C3=B1ado=20el=20Controller=20y=20metodo=20par?= =?UTF-8?q?a=20comprobar=20desde=20el=20servicio=20si=20existe=20x=20docum?= =?UTF-8?q?ento?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DocumentController.cs | 27 +++++++++++++++++++ DoliMiddlewareApi/Services/DocumentService.cs | 13 ++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 DoliMiddlewareApi/Controllers/DocumentController.cs diff --git a/DoliMiddlewareApi/Controllers/DocumentController.cs b/DoliMiddlewareApi/Controllers/DocumentController.cs new file mode 100644 index 0000000..82351c8 --- /dev/null +++ b/DoliMiddlewareApi/Controllers/DocumentController.cs @@ -0,0 +1,27 @@ +using DoliMiddlewareApi.Services; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace DoliMiddlewareApi.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class DocumentController(DocumentService documentService) : ControllerBase + { + + [HttpPut("invoice/{invoiceRef}/build")] + public async Task BuildInvoicePdf(string invoiceRef) + { + await documentService.BuildInvoicePdfAsync(invoiceRef); + + var exists = await documentService.ExistsAsync(invoiceRef); + + return Ok(new + { + generated = exists, + invoiceRef + }); + } + + } +} diff --git a/DoliMiddlewareApi/Services/DocumentService.cs b/DoliMiddlewareApi/Services/DocumentService.cs index c3f75cc..0d762e5 100644 --- a/DoliMiddlewareApi/Services/DocumentService.cs +++ b/DoliMiddlewareApi/Services/DocumentService.cs @@ -18,6 +18,17 @@ namespace DoliMiddlewareApi.Services await apiClient.PutAsync("documents/builddoc",request); } - + + public async Task ExistsAsync(string invoiceRef) + { + var file = $"¨{invoiceRef}/{invoiceRef}.pdf"; + + var endpoint = $"documents?modulepart=invoice&id={invoiceRef}"; + + var docs = await apiClient.GetCollectionAsync(endpoint); + + return docs.Contains(file); + + } } }