diff --git a/e-invoice-api/src/main/kotlin/net/codinux/invoicing/api/InvoicingResource.kt b/e-invoice-api/src/main/kotlin/net/codinux/invoicing/api/InvoicingResource.kt index 42f5a12..b24f5b6 100644 --- a/e-invoice-api/src/main/kotlin/net/codinux/invoicing/api/InvoicingResource.kt +++ b/e-invoice-api/src/main/kotlin/net/codinux/invoicing/api/InvoicingResource.kt @@ -67,20 +67,29 @@ class InvoicingResource( @Path("extract") @POST - @Consumes(MediaType.APPLICATION_OCTET_STREAM) + @Consumes(MediaTypePdf, MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_JSON) @Operation(summary = "Extract invoice data from a Factur-X / ZUGFeRD or XRechnung file") @Tag(name = "Extract") - fun extractInvoiceData(invoice: FileUpload) = - service.extractInvoiceData(invoice.uploadedFile()) + fun extractInvoiceDataFromPdf(invoice: java.nio.file.Path) = + service.extractInvoiceDataFromPdf(invoice) + + @Path("extract") + @POST + @Consumes(MediaType.APPLICATION_XML) + @Produces(MediaType.APPLICATION_JSON) + @Operation(summary = "Extract invoice data from a Factur-X / ZUGFeRD or XRechnung file") + @Tag(name = "Extract") + fun extractInvoiceDataFromXml(invoice: java.nio.file.Path) = + service.extractInvoiceDataFromXml(invoice) @Path("validate") @POST @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Operation(summary = "Validate a Factur-X / ZUGFeRD or XRechnung file") @Tag(name = "Validate") - fun validateInvoiceXml(invoice: FileUpload) = - service.validateInvoice(invoice.uploadedFile()).reportAsXml + fun validateInvoiceXml(invoice: java.nio.file.Path) = + service.validateInvoice(invoice).reportAsXml private fun createPdfFileResponse(pdfFile: java.nio.file.Path, invoice: Invoice): Response = diff --git a/e-invoice-api/src/main/kotlin/net/codinux/invoicing/service/InvoicingService.kt b/e-invoice-api/src/main/kotlin/net/codinux/invoicing/service/InvoicingService.kt index 2efe69a..86a8f5b 100644 --- a/e-invoice-api/src/main/kotlin/net/codinux/invoicing/service/InvoicingService.kt +++ b/e-invoice-api/src/main/kotlin/net/codinux/invoicing/service/InvoicingService.kt @@ -7,7 +7,6 @@ import net.codinux.invoicing.reader.EInvoiceReader import net.codinux.invoicing.validation.EInvoiceValidator import java.io.File import java.nio.file.Path -import kotlin.io.path.extension @Singleton class InvoicingService { @@ -42,17 +41,15 @@ class InvoicingService { } - fun extractInvoiceData(invoiceFile: Path) = when (invoiceFile.extension.lowercase()) { - "xml" -> reader.extractFromXml(invoiceFile.toFile()) - "pdf" -> reader.extractFromPdf(invoiceFile.toFile()) - else -> throw IllegalArgumentException("We can only extract eInvoice data from .xml and .pdf files") - } + fun extractInvoiceDataFromPdf(invoiceFile: Path) = + reader.extractFromPdf(invoiceFile.toFile()) + + fun extractInvoiceDataFromXml(invoiceFile: Path) = + reader.extractFromXml(invoiceFile.toFile()) - fun validateInvoice(invoiceFile: Path) =when (invoiceFile.extension.lowercase()) { - "xml", "pdf" -> validator.validate(invoiceFile.toFile()) - else -> throw IllegalArgumentException("We can only validate .xml and .pdf eInvoice files") - } + fun validateInvoice(invoiceFile: Path) = + validator.validate(invoiceFile.toFile()) private fun createTempPdfFile(): Path =