Implemented InvoicingResource to create eInvoices via REST API
This commit is contained in:
parent
8aae8fc3d2
commit
07007ad619
|
@ -1,3 +1,15 @@
|
|||
buildscript {
|
||||
val kotlinVersion: String by extra
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
// don't know why but otherwise Quarkus is not able to index the classes of e-invoice-domain
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
allprojects {
|
||||
group = "net.codinux.invoicing"
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package net.codinux.invoicing.api
|
||||
|
||||
import jakarta.ws.rs.*
|
||||
import jakarta.ws.rs.core.MediaType
|
||||
import jakarta.ws.rs.core.Response
|
||||
import net.codinux.invoicing.model.Invoice
|
||||
import net.codinux.invoicing.service.InvoicingService
|
||||
import org.eclipse.microprofile.openapi.annotations.Operation
|
||||
|
||||
@Path("")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
class InvoicingResource(
|
||||
private val service: InvoicingService
|
||||
) {
|
||||
|
||||
@Path("xrechnung")
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_XML)
|
||||
@Operation(summary = "Create a XRechnung XML")
|
||||
fun createXRechnung(invoice: Invoice) =
|
||||
service.createXRechnung(invoice)
|
||||
|
||||
@Path("facturx/xml")
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_XML)
|
||||
@Operation(summary = "Create a Factur-X / ZUGFeRD XML (ZUGFeRD is a synonym for Factur-X)")
|
||||
fun createFacturXXml(invoice: Invoice) =
|
||||
service.createFacturXXml(invoice)
|
||||
|
||||
@Path("facturx/pdf")
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
@Operation(summary = "Create a Factur-X / ZUGFeRD XML, transforms it to PDF and attaches before created XML to it")
|
||||
fun createFacturXPdf(invoice: Invoice): Response {
|
||||
val pdfFile = service.createFacturXPdf(invoice)
|
||||
|
||||
return Response.ok(pdfFile)
|
||||
.header("Content-Disposition", "attachment;filename=\"Invoice.pdf\"")
|
||||
.build()
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package net.codinux.invoicing.service
|
||||
|
||||
import jakarta.inject.Singleton
|
||||
import net.codinux.invoicing.creation.EInvoiceCreator
|
||||
import net.codinux.invoicing.model.Invoice
|
||||
import java.io.File
|
||||
|
||||
@Singleton
|
||||
class InvoicingService {
|
||||
|
||||
private val creator = EInvoiceCreator()
|
||||
|
||||
|
||||
fun createXRechnung(invoice: Invoice): String =
|
||||
creator.createXRechnungXml(invoice)
|
||||
|
||||
fun createFacturXXml(invoice: Invoice): String =
|
||||
creator.createZugferdXml(invoice)
|
||||
|
||||
fun createFacturXPdf(invoice: Invoice): File {
|
||||
val resultFile = File.createTempFile("factur-x", ".pdf").also {
|
||||
it.deleteOnExit()
|
||||
}
|
||||
|
||||
creator.createZugferdPdf(invoice, resultFile)
|
||||
|
||||
return resultFile
|
||||
}
|
||||
|
||||
}
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
quarkus.http.enable-compression=true
|
||||
|
||||
quarkus.http.cors=true
|
||||
%dev.quarkus.http.cors=true
|
||||
quarkus.http.cors.origins=*
|
||||
quarkus.http.cors.headers=accept, authorization, content-type, x-requested-with
|
||||
quarkus.http.cors.methods=GET, OPTIONS
|
||||
quarkus.http.cors.methods=GET, POST, PUT, DELETE, OPTIONS
|
||||
|
||||
|
||||
# log request response times
|
||||
|
@ -40,6 +40,9 @@ quarkus.log.loki.field.kubernetes.include=true
|
|||
quarkus.log.loki.field.kubernetes.prefix=off
|
||||
quarkus.log.loki.field.kubernetes.field.containername.include=false
|
||||
|
||||
# to turn off verbose FOP messages
|
||||
quarkus.log.category."org.apache.fop.apps".level=ERROR
|
||||
|
||||
|
||||
# Live reload
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package net.codinux.invoicing.api
|
||||
|
||||
import io.quarkus.test.junit.QuarkusIntegrationTest
|
||||
|
||||
@QuarkusIntegrationTest
|
||||
class InvoicingResourceIT : InvoicingResourceTest()
|
|
@ -0,0 +1,20 @@
|
|||
package net.codinux.invoicing.api
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest
|
||||
import io.restassured.RestAssured.given
|
||||
import org.hamcrest.CoreMatchers.`is`
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@QuarkusTest
|
||||
class InvoicingResourceTest {
|
||||
|
||||
@Test
|
||||
fun testHelloEndpoint() {
|
||||
given()
|
||||
.`when`().get("/hello")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(`is`("Hello from Quarkus REST"))
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue