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 12, 2018
1 parent f1178f9 commit 808872f
Show file tree
Hide file tree
Showing 18 changed files with 1,210 additions and 52 deletions.
148 changes: 99 additions & 49 deletions docs/swagger/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,46 @@ paths:
Problem occured while printing the receipt
schema:
$ref: "#/definitions/RequestTimeoutError"


/v2/receipts/req/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/req/print/status/{id}:
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

/v1/reports/operator/print:
post:
summary: Prints Report
Expand Down Expand Up @@ -194,6 +233,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 +249,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 +402,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'
9 changes: 6 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 @@ -83,11 +83,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,7 @@
package com.clouway.pos.print.adapter.db

import com.clouway.pos.print.core.PrintingListener
import com.clouway.pos.print.core.ReceiptRepository
import com.google.inject.AbstractModule
import com.google.inject.Provides
import com.google.inject.Singleton
Expand All @@ -13,6 +15,7 @@ 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)
}

@Provides
Expand Down
Loading

0 comments on commit 808872f

Please sign in to comment.