Made it work but it's not nice
This commit is contained in:
parent
f9db232fbc
commit
a1fe8befce
|
@ -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 =
|
||||
|
|
|
@ -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 =
|
||||
|
|
Loading…
Reference in New Issue