Skip to content

Commit

Permalink
pos-print: add async receipt printing
Browse files Browse the repository at this point in the history
  • Loading branch information
tsbonev committed Oct 23, 2018
1 parent f1178f9 commit e171f1d
Show file tree
Hide file tree
Showing 23 changed files with 1,345 additions and 51 deletions.
190 changes: 142 additions & 48 deletions docs/swagger/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,90 @@ paths:
Problem occured while printing the receipt
schema:
$ref: "#/definitions/RequestTimeoutError"

/v2/receipts/print:
post:
summary: Print Receipts
parameters:
- in: body
name: request
description: Prining receipts and fiscal receipts
required: true
schema:
$ref: '#/definitions/PrintReceiptRequest'
description: Saving receipts to be pritned asynchronously
responses:
200:
description: Receipt saved and queued to be printed
schema:
type: string
example: "receiptId"
400:
description:
The requested receipt is already saved

/v2/receipts/{id}/status:
get:
summary: Get receipt status
parameters:
- in: path
name: id
type: string
required: true
description: The id of the receipt
responses:
200:
description: Receipt found
schema:
type: string
example: "PRINTING"
404:
description: Receipt not found

/v2/receipts/latest/{limit}:
get:
summary: Gets latest receipts up to a limit
parameters:
- in: path
name: limit
type: integer
format: int32
required: true
description: The limit to return
responses:
200:
description: Receipts retrieved
schema:
type: object
properties:
printStatus:
type: string
requestId:
type: string
operatorId:
type: string
sourceIp:
type: string
isFiscal:
type: boolean
receipt:
$ref: '#/definitions/Receipt'

/v2/receipts/{requestId}/requeue:
post:
summary: Requeues a receipt
parameters:
- in: path
name: requestId
type: string
required: true
description: The request id of the receipt
responses:
200:
description: The receipt was requeued for printing
404:
description: The receipt has not been registered

/v1/reports/operator/print:
post:
summary: Prints Report
Expand Down Expand Up @@ -194,6 +277,10 @@ definitions:
PrintReceiptRequest:
type: object
properties:
receiptId:
type: string
description: Unique id representing the receipt
example: "receiptId"
sourceIp:
type: string
description: Unique ip representing the owner of the device.
Expand All @@ -206,53 +293,60 @@ definitions:
type: boolean
description: true means fiscal receipt, false means text
receipt:
type: object
description: Represents receipt item
properties:
receiptId:
type: string
description: Receipt ID
example: "123"
currency:
type: string
description: Currency
example: "USD"
prefixLines:
type: array
items:
type: string
suffixLines:
type: array
items:
type: string
amount:
type: number
format: double
description: amount to be paid
example: 1.0
receiptItems:
type: object
description: Represents receipt item
properties:
name:
type: string
description: Name of the item
example:
quantity:
type: number
format: double
description: Quantity of the item
example: 2.0
price:
type: number
format: double
description: Price of the item (with vat)
example: 1.0
vat:
type: number
format: double
description: VAT
example: 20.0
$ref: '#/definitions/Receipt'
Receipt:
type: object
description: Represents receipt item
properties:
receiptId:
type: string
description: Receipt ID
example: "123"
currency:
type: string
description: Currency
example: "USD"
prefixLines:
type: array
items:
type: string
suffixLines:
type: array
items:
type: string
amount:
type: number
format: double
description: amount to be paid
example: 1.0
receiptItems:
type: array
items:
$ref: '#/definitions/ReceiptItem'
ReceiptItem:
type: object
description: Represents receipt item
properties:
name:
type: string
description: Name of the item
example:
quantity:
type: number
format: double
description: Quantity of the item
example: 2.0
price:
type: number
format: double
description: Price of the item (with vat)
example: 1.0
vat:
type: number
format: double
description: VAT
example: 20.0

PrintReceiptResponse:
type: object
properties:
Expand Down Expand Up @@ -352,4 +446,4 @@ definitions:
properties:
message:
type: string
example: 'Printer request timeout. Unable to get response after 50 retries'
example: 'Printer request timeout. Unable to get response after 50 retries'
12 changes: 9 additions & 3 deletions pos-print/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.1.1'
ext.kotlin_version = '1.2.71'
repositories {
mavenCentral()
jcenter()
Expand Down Expand Up @@ -51,6 +51,9 @@ dependencies {
compile 'com.google.inject.extensions:guice-servlet:3.0'
compile 'com.google.guava:guava:19.0'

//Apache commons
compile 'commons-io:commons-io:2.5'

// Internal version of Sitebricks
compile('org.mvel:mvel2:2.1.3.Final')
compile('org.jsoup:jsoup:1.8.1')
Expand Down Expand Up @@ -83,11 +86,14 @@ dependencies {
compile 'org.slf4j:slf4j-api:1.6.3'
compile 'ch.qos.logback:logback-classic:0.9.30'

//GuavaServices
compile group: 'com.google.guava', name: 'guava', version: '19.0'

//MongoDatabase
compile 'org.mongodb:mongodb-driver:3.4.2'
compile 'org.mongodb:mongodb-driver:3.6.4'

//FongoDatabase
compile 'com.github.fakemongo:fongo:2.0.9'
compile 'com.github.fakemongo:fongo:2.2.0-RC2'

compile 'com.github.spullara.cli-parser:cli-parser:1.1.2'
compile 'com.google.code.gson:gson:2.8.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.clouway.pos.print;

import com.clouway.pos.print.core.BackgroundReceiptPrintingService;
import com.clouway.pos.print.adapter.http.HttpBackend;
import com.clouway.pos.print.adapter.http.HttpModule;
import com.clouway.pos.print.core.CoreModule;
Expand Down Expand Up @@ -39,15 +40,20 @@ public static void main(String[] args) {
new PersistentModule(client, commandCLI.dbName())
);


HttpBackend backend = new HttpBackend(commandCLI.httpPort(), injector);
backend.start();

BackgroundReceiptPrintingService backgroundPrinter = injector.getInstance(BackgroundReceiptPrintingService.class);
backgroundPrinter.startAsync().awaitRunning();

System.out.printf("POS Print Service is up and running on port: %d\n", commandCLI.httpPort());

Runtime.getRuntime().addShutdownHook(new Thread(() -> {
System.out.println("POS Print Service is going to shutdown.");
try {
backend.stop();
backgroundPrinter.stopAsync();
} catch (Exception e) {
System.out.println("Failed to stop server due: " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.clouway.pos.print.adapter.db

import com.clouway.pos.print.core.IdGenerator
import com.clouway.pos.print.core.ReceiptRepository
import com.clouway.pos.print.core.SimpleUUIDGenerator
import com.google.inject.AbstractModule
import com.google.inject.Provides
import com.google.inject.Singleton
Expand All @@ -13,6 +16,8 @@ class PersistentModule(private val client: MongoClient, private val databaseName

override fun configure() {
bind(CashRegisterRepository::class.java).to(PersistentCashRegisterRepository::class.java).`in`(Singleton::class.java)
bind(ReceiptRepository::class.java).to(PersistentReceiptRepository::class.java).`in`(Singleton::class.java)
bind(IdGenerator::class.java).to(SimpleUUIDGenerator::class.java).`in`(Singleton::class.java)
}

@Provides
Expand Down
Loading

0 comments on commit e171f1d

Please sign in to comment.