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); + + } } }