diff options
| author | Adam Soltys <[email protected]> | 2012-11-12 22:43:39 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2012-11-12 22:43:39 -0800 |
| commit | 5bba3395bc0bb84dcd24a7ade0c855a6beb6dbef (patch) | |
| tree | 47507cd021c87c6e13eb9931ced40f570c5c5fe7 | |
| parent | 28575e4e34117a01390d49701fe4e2e0fe3f7ce9 (diff) | |
| download | coinos-server-5bba3395bc0bb84dcd24a7ade0c855a6beb6dbef.tar.gz coinos-server-5bba3395bc0bb84dcd24a7ade0c855a6beb6dbef.zip | |
Save transactions in redis
| -rw-r--r-- | app.coffee | 40 | ||||
| -rw-r--r-- | public/js/calculator.coffee | 16 | ||||
| -rw-r--r-- | views/calculator.html | 3 | ||||
| -rw-r--r-- | views/index.html | 2 |
4 files changed, 38 insertions, 23 deletions
@@ -24,23 +24,24 @@ app.get('/report', (req, res) -> res.render('report', js: (-> global.js), css: (-> global.css)) ) -app.get('/client/:client', (req, res) -> +app.get('/:user.json', (req, res) -> db = require("redis").createClient() - db.hgetall(req.params.client, (err, obj) -> + db.hgetall(req.params.user, (err, obj) -> res.write(JSON.stringify(obj)) res.end() ) ) -app.get('/transactions/:login', (req, res) -> - connection = require('mysql').createConnection(config.database) +app.get('/:user/transactions', (req, res) -> + db = require("redis").createClient() + user = req.params.user - connection.connect() - connection.query("SELECT * FROM transactions", - [req.params.login], (err, rows) -> - res.write(JSON.stringify(rows)) - connection.end() - res.end() + db.lrange("#{user}:transactions", 0, -1, (err, transactions) -> + for i in transactions + db.hgetall("#{user}:transactions:#{i}", (err, t) -> + res.write(JSON.stringify(t)) + res.end() + ) ) ) @@ -60,7 +61,7 @@ app.get('/ticker', (req, res) -> ) ) -app.post('/create', (req, res) -> +app.post('/users', (req, res) -> db = require("redis").createClient() db.hmset(req.body.login, req.body, -> res.writeHead(302, 'Location': '/' + req.body.login) @@ -68,9 +69,22 @@ app.post('/create', (req, res) -> ) ) -app.get('/:client', (req, res) -> +app.post('/:user/transactions', (req, res) -> + user = req.params.user + db = require("redis").createClient() + db.incr('transactions', (err, id) -> + db.hmset("#{user}:transactions:#{id}", req.body, -> + db.rpush("#{user}:transactions", id, -> + res.write(JSON.stringify(req.body)) + res.end() + ) + ) + ) +) + +app.get('/:user', (req, res) -> res.render('calculator', - client: req.params.client, + user: req.params.user, js: (-> global.js), css: (-> global.css) ) diff --git a/public/js/calculator.coffee b/public/js/calculator.coffee index 6861bb16..01523d9a 100644 --- a/public/js/calculator.coffee +++ b/public/js/calculator.coffee @@ -7,7 +7,7 @@ g = exports ? this $(-> g.websocket = null - g.client = $('#client').val() + g.user = $('#user').val() g.title = get('title') g.address = get('address') g.commission = get('commission') @@ -18,8 +18,8 @@ $(-> setupQR() setupSocket() - if client? and client - $.getJSON('client/' + client, (data) -> + if user? and user + $.getJSON(user + '.json', (data) -> g.title = data.name g.address = data.address g.commission = data.commission @@ -124,11 +124,11 @@ setupSocket = -> $('#payment').hide() $('#received').fadeIn('slow') - $.get('record_transaction.php', - address: from_address, - date: moment().format("YYYY-MM-DD HH:mm:ss"), - received: received, - exchange: g.exchange + $.post("/#{g.user}/transactions", + address: from_address, + date: moment().format("YYYY-MM-DD HH:mm:ss"), + received: received, + exchange: g.exchange ) get = (name) -> diff --git a/views/calculator.html b/views/calculator.html index 792b5b02..87042825 100644 --- a/views/calculator.html +++ b/views/calculator.html @@ -11,7 +11,8 @@ <body> <div class="container-fluid"> <div id="calculator" style="display: none"> - <input id="client" type="hidden" value="{{client}}" /> + <input id="user" type="hidden" value="{{user}}" /> + <h1 id="title"></h1> <img id="logo" src="img/logo.jpg" alt="Logo" /> diff --git a/views/index.html b/views/index.html index 1182ff4e..c9f2cee8 100644 --- a/views/index.html +++ b/views/index.html @@ -9,7 +9,7 @@ </head> <body> <div class="container-fluid"> - <form action="create" method="post"> + <form action="users" method="post"> <h1>Calculator Setup</h1> <label for="login">Alias:</label> |
