Improve demo
This commit is contained in:
@@ -3,10 +3,14 @@ import com.devsoap.dbt.config.DBTConfig
|
||||
import com.devsoap.dbt.demo.DatabaseService
|
||||
import com.devsoap.dbt.services.TransactionManagerService
|
||||
import org.h2.jdbcx.JdbcDataSource
|
||||
import ratpack.form.Form
|
||||
import ratpack.handlebars.HandlebarsModule
|
||||
import ratpack.http.Status
|
||||
|
||||
import javax.sql.DataSource
|
||||
|
||||
import static ratpack.groovy.Groovy.ratpack
|
||||
import static ratpack.handlebars.Template.handlebarsTemplate
|
||||
|
||||
ratpack {
|
||||
|
||||
@@ -16,6 +20,8 @@ ratpack {
|
||||
}
|
||||
|
||||
bindings {
|
||||
module HandlebarsModule
|
||||
|
||||
module (DBTModule) {
|
||||
it.ledger.remoteUrl = 'http://localhost:5050/ledger'
|
||||
it.executor.remoteUrl = 'http://localhost:5050/executor'
|
||||
@@ -27,31 +33,43 @@ ratpack {
|
||||
|
||||
handlers {
|
||||
|
||||
/**
|
||||
* Consumer services
|
||||
*/
|
||||
get('') {
|
||||
get(TransactionManagerService).execute { transaction ->
|
||||
transaction.query("INSERT INTO LOGS(LOG_ID,LOG_VALUE) VALUES (${new Random().nextInt()}, 'HELLO')")
|
||||
}.then {
|
||||
redirect("/gateway/${it['id'].textValue()}")
|
||||
get {
|
||||
render handlebarsTemplate('index.html')
|
||||
}
|
||||
|
||||
post('addQueryToTransaction') {
|
||||
def transactionManager = get(TransactionManagerService)
|
||||
parse(Form).then { Form form ->
|
||||
def query = form.get('query')
|
||||
def transactionId = form.get('transactionId')
|
||||
if(transactionId) {
|
||||
transactionManager.execute(transactionId) {
|
||||
it.query(query)
|
||||
} .then {
|
||||
response.send(it.toString())
|
||||
}
|
||||
} else {
|
||||
transactionManager.execute {
|
||||
it.query(query)
|
||||
} .then {
|
||||
response.send(it.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get('gateway/:transactionId?') {
|
||||
get(TransactionManagerService).execute(pathTokens.transactionId, { transaction ->
|
||||
transaction.query("INSERT INTO LOGS(LOG_ID,LOG_VALUE) VALUES (${new Random().nextInt()}, 'WORLD')")
|
||||
}).then {
|
||||
redirect("/gateway2/${it['id'].textValue()}")
|
||||
}
|
||||
}
|
||||
|
||||
get('gateway2/:transactionId?') {
|
||||
get(TransactionManagerService).execute(pathTokens.transactionId, { transaction ->
|
||||
transaction.query("SELECT * FROM LOGS")
|
||||
transaction.complete()
|
||||
}).then {
|
||||
redirect('/ledger')
|
||||
post('executeTransaction') {
|
||||
def transactionManager = get(TransactionManagerService)
|
||||
parse(Form).then { Form form ->
|
||||
def transactionId = form.get('transactionId')
|
||||
transactionManager.execute(transactionId) {
|
||||
it.complete()
|
||||
}.onError {
|
||||
response.status(Status.of(501))
|
||||
response.send(it.message)
|
||||
}.then {
|
||||
response.send(it.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user