añado el Controller y metodo para comprobar desde el servicio si existe x documento

This commit is contained in:
JM 2026-04-15 16:49:41 +02:00
parent 0e7bee7e43
commit 6bac2c63fb
2 changed files with 39 additions and 1 deletions

View File

@ -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<IActionResult> BuildInvoicePdf(string invoiceRef)
{
await documentService.BuildInvoicePdfAsync(invoiceRef);
var exists = await documentService.ExistsAsync(invoiceRef);
return Ok(new
{
generated = exists,
invoiceRef
});
}
}
}

View File

@ -18,6 +18,17 @@ namespace DoliMiddlewareApi.Services
await apiClient.PutAsync("documents/builddoc",request); await apiClient.PutAsync("documents/builddoc",request);
} }
public async Task<bool> ExistsAsync(string invoiceRef)
{
var file = $"¨{invoiceRef}/{invoiceRef}.pdf";
var endpoint = $"documents?modulepart=invoice&id={invoiceRef}";
var docs = await apiClient.GetCollectionAsync<string>(endpoint);
return docs.Contains(file);
}
} }
} }