Added GET endpoint
This commit is contained in:
parent
ae6ae7071a
commit
64427fe27e
|
@ -5,9 +5,7 @@ import net.codinux.banking.epcqrcode.EpcQrCodeGenerator
|
|||
import net.codinux.banking.epcqrcode.rest.dto.GenerateEpcQrCodeRequestDto
|
||||
import net.codinux.banking.epcqrcode.rest.dto.GenerateEpcQrCodeResponseDto
|
||||
import org.slf4j.LoggerFactory
|
||||
import javax.ws.rs.POST
|
||||
import javax.ws.rs.Path
|
||||
import javax.ws.rs.Produces
|
||||
import javax.ws.rs.*
|
||||
import javax.ws.rs.core.MediaType
|
||||
import javax.ws.rs.core.Response
|
||||
|
||||
|
@ -23,18 +21,28 @@ class EpcQrCodeResource {
|
|||
protected val epcQrCodeGenerator = EpcQrCodeGenerator()
|
||||
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
fun createEpcQrCodeGet(@BeanParam request: GenerateEpcQrCodeRequestDto): Response {
|
||||
return handleJsonRequest(request)
|
||||
}
|
||||
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
fun createEpcQrCode(requestDto: GenerateEpcQrCodeRequestDto): Response {
|
||||
fun createEpcQrCodePost(request: GenerateEpcQrCodeRequestDto): Response {
|
||||
return handleJsonRequest(request)
|
||||
}
|
||||
|
||||
private fun handleJsonRequest(request: GenerateEpcQrCodeRequestDto): Response {
|
||||
try {
|
||||
val epcQrCode = epcQrCodeGenerator.generateEpcQrCode(mapToEpcQrCodeConfig(requestDto), requestDto.imageHeightAndWidth)
|
||||
val epcQrCode = epcQrCodeGenerator.generateEpcQrCode(mapToEpcQrCodeConfig(request), request.imageHeightAndWidth)
|
||||
val qrCodeBytes = epcQrCode.bytes // TODO: convert to Base64
|
||||
|
||||
return Response.ok(GenerateEpcQrCodeResponseDto(qrCodeBytes))
|
||||
.header("Access-Control-Allow-Origin", "*")
|
||||
.build()
|
||||
} catch (e: Exception) {
|
||||
log.error("Could not create QR code for $requestDto", e)
|
||||
log.error("Could not create QR code for $request", e)
|
||||
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.statusCode, e.localizedMessage) // TODO: it's almost always a bad idea to pass exception message to the outside
|
||||
.header("Access-Control-Allow-Origin", "*")
|
||||
|
|
|
@ -3,26 +3,40 @@ package net.codinux.banking.epcqrcode.rest.dto
|
|||
import net.codinux.banking.epcqrcode.EpcQrCode
|
||||
import net.codinux.banking.epcqrcode.EpcQrCodeCharacterSet
|
||||
import net.codinux.banking.epcqrcode.ImageFormat
|
||||
import javax.ws.rs.DefaultValue
|
||||
import javax.ws.rs.QueryParam
|
||||
|
||||
|
||||
class GenerateEpcQrCodeRequestDto {
|
||||
|
||||
@QueryParam("receiverName")
|
||||
var receiverName: String = ""
|
||||
|
||||
@QueryParam("bic")
|
||||
var bic: String? = null
|
||||
|
||||
@QueryParam("iban")
|
||||
var iban: String = ""
|
||||
|
||||
@QueryParam("amount")
|
||||
var amount: String? = null
|
||||
|
||||
@QueryParam("reference")
|
||||
var reference: String? = null
|
||||
|
||||
@QueryParam("noteToUser")
|
||||
var noteToUser: String? = null
|
||||
|
||||
@DefaultValue("" + EpcQrCode.DefaultHeightAndWidth)
|
||||
@QueryParam("imageHeightAndWidth")
|
||||
var imageHeightAndWidth: Int = EpcQrCode.DefaultHeightAndWidth
|
||||
|
||||
@DefaultValue("PNG")
|
||||
@QueryParam("imageFormat")
|
||||
var imageFormat: ImageFormat = ImageFormat.PNG
|
||||
|
||||
@DefaultValue("UTF_8")
|
||||
@QueryParam("encoding")
|
||||
var encoding: EpcQrCodeCharacterSet = EpcQrCodeCharacterSet.UTF_8
|
||||
|
||||
}
|
Loading…
Reference in New Issue