Made it work but it's not nice

This commit is contained in:
dankito 2024-11-21 04:25:31 +01:00
parent f9db232fbc
commit a1fe8befce
2 changed files with 21 additions and 15 deletions

View File

@ -67,20 +67,29 @@ class InvoicingResource(
@Path("extract") @Path("extract")
@POST @POST
@Consumes(MediaType.APPLICATION_OCTET_STREAM) @Consumes(MediaTypePdf, MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Extract invoice data from a Factur-X / ZUGFeRD or XRechnung file") @Operation(summary = "Extract invoice data from a Factur-X / ZUGFeRD or XRechnung file")
@Tag(name = "Extract") @Tag(name = "Extract")
fun extractInvoiceData(invoice: FileUpload) = fun extractInvoiceDataFromPdf(invoice: java.nio.file.Path) =
service.extractInvoiceData(invoice.uploadedFile()) 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") @Path("validate")
@POST @POST
@Consumes(MediaType.APPLICATION_OCTET_STREAM) @Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Operation(summary = "Validate a Factur-X / ZUGFeRD or XRechnung file") @Operation(summary = "Validate a Factur-X / ZUGFeRD or XRechnung file")
@Tag(name = "Validate") @Tag(name = "Validate")
fun validateInvoiceXml(invoice: FileUpload) = fun validateInvoiceXml(invoice: java.nio.file.Path) =
service.validateInvoice(invoice.uploadedFile()).reportAsXml service.validateInvoice(invoice).reportAsXml
private fun createPdfFileResponse(pdfFile: java.nio.file.Path, invoice: Invoice): Response = private fun createPdfFileResponse(pdfFile: java.nio.file.Path, invoice: Invoice): Response =

View File

@ -7,7 +7,6 @@ import net.codinux.invoicing.reader.EInvoiceReader
import net.codinux.invoicing.validation.EInvoiceValidator import net.codinux.invoicing.validation.EInvoiceValidator
import java.io.File import java.io.File
import java.nio.file.Path import java.nio.file.Path
import kotlin.io.path.extension
@Singleton @Singleton
class InvoicingService { class InvoicingService {
@ -42,17 +41,15 @@ class InvoicingService {
} }
fun extractInvoiceData(invoiceFile: Path) = when (invoiceFile.extension.lowercase()) { fun extractInvoiceDataFromPdf(invoiceFile: Path) =
"xml" -> reader.extractFromXml(invoiceFile.toFile()) reader.extractFromPdf(invoiceFile.toFile())
"pdf" -> reader.extractFromPdf(invoiceFile.toFile())
else -> throw IllegalArgumentException("We can only extract eInvoice data from .xml and .pdf files") fun extractInvoiceDataFromXml(invoiceFile: Path) =
} reader.extractFromXml(invoiceFile.toFile())
fun validateInvoice(invoiceFile: Path) =when (invoiceFile.extension.lowercase()) { fun validateInvoice(invoiceFile: Path) =
"xml", "pdf" -> validator.validate(invoiceFile.toFile()) validator.validate(invoiceFile.toFile())
else -> throw IllegalArgumentException("We can only validate .xml and .pdf eInvoice files")
}
private fun createTempPdfFile(): Path = private fun createTempPdfFile(): Path =