Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Some db abstraction

  • Loading branch information...
commit d20c6434ca100080f79c4102d03fa11b94987923 1 parent 2606a52
@indutny authored
View
28 core/lib/db/index.js
@@ -0,0 +1,28 @@
+var Db = module.exports = function(options) {
+};
+
+Db.prototype.findConversationsInBBox = function(bbox) {
+};
+
+Db.prototype.watchConversationsInBBox = function(bbox, last) {
+};
+
+Db.prototype.createConversation = function(data) {
+}
+
+Db.prototype.getConversation = function(id) {
+};
+
+Db.prototype.watchConversation = function(id, last) {
+};
+
+Db.prototype.updateConversation = function(data) {
+};
+
+Db.prototype.postMessage = function(id, data) {
+};
+
+Db.prototype.codes = {
+ DB_OK: 0,
+ DB_ERROR: 1
+};
View
28 core/lib/db/mongodb/index.js
@@ -0,0 +1,28 @@
+var Db = module.exports = function(options) {
+};
+
+Db.prototype.findConversationsInBBox = function(bbox) {
+};
+
+Db.prototype.watchConversationsInBBox = function(bbox, last) {
+};
+
+Db.prototype.createConversation = function(data) {
+}
+
+Db.prototype.getConversation = function(id) {
+};
+
+Db.prototype.watchConversation = function(id, last) {
+};
+
+Db.prototype.updateConversation = function(data) {
+};
+
+Db.prototype.postMessage = function(id, data) {
+};
+
+Db.prototype.codes = {
+ DB_OK: 0,
+ DB_ERROR: 1
+};
View
76 core/lib/routes/api.js
@@ -1,22 +1,58 @@
-module.exports = function(app) {
- // Get conversations list
- app.get('/api/v1/conversation', function(req, res) {
+module.exports = function(db) {
+ return function(app) {
+ // Get conversations in bbox
+ app.get('/api/v1/conversation', function(req, res) {
+ var status = db.findConversationsInBBox({
+ // ... bbox will be here
+ });
+
+ // Check status and respond to client
+ });
- });
-
- // Create new conversation
- app.put('/api/v1/conversation', function(req, res) {
- });
-
- // Get conversation
- app.get('/api/v1/conversation/:conversation', function(req, res) {
- });
-
- // Post message
- app.post('/api/v1/conversation/:conversation', function(req, res) {
- });
-
- // Get changes
- app.get('/api/v1/conversation/:conversation/_changes', function(req, res) {
- });
+ // Watch conversations list
+ app.get('/api/v1/conversation', function(req, res) {
+ var status = db.watchConversationsInBBox({
+ // ... bbox will be here
+ });
+
+ // Check status and respond to client
+ });
+
+ // Create new conversation
+ app.put('/api/v1/conversation', function(req, res) {
+ var status = db.createConversation({
+ // ... some data ...
+ });
+
+ // Check status and respond to client
+ });
+
+ // Get conversation
+ app.get('/api/v1/conversation/:conversation', function(req, res) {
+ var conversation = db.getConversation(req.params.conversation);
+
+ // Check status and respond to client
+ });
+
+ // Post message
+ app.post('/api/v1/conversation/:conversation', function(req, res) {
+ var status = db.updateConversation(req.params.conversation, {
+ // ... some data ...
+ });
+
+ // Check status and respond to client
+ });
+
+ // Get changes
+ app.get('/api/v1/conversation/:conversation/_changes/:last_id?', function(req, res) {
+ var emitter = db.watchConversation(req.params.conversation,
+ req.params.last_id || 0);
+
+ // Check status and respond to client
+
+ emitter.on('change', function(data) {
+ // Do something
+ });
+ });
+ };
};
View
2  core/lib/routes/user.js
@@ -1 +1 @@
-module.exports = function(app) {
+module.exports = function(db) {
View
8 core/mapchat
@@ -2,6 +2,10 @@
var connect = require('connect'),
io = require('socket.io'),
+ db = new (require('./lib/db/mongodb'))({
+ server: '127.0.0.1',
+ port: 27017
+ }),
route_api = require('./lib/routes/api'),
route_user = require('./lib/routes/user');
@@ -11,8 +15,8 @@ var server = connect.createServer(
connect.methodOverride(),
connect.compiler({src: __dirname + '/../pub', enable: ['less'] }),
connect.session(),
- connect.router(route_user),
- connect.router(route_api),
+ connect.router(route_user(db)),
+ connect.router(route_api(db)),
connect.cache(),
connect.staticProvider(__dirname + '/../pub')
);
Please sign in to comment.
Something went wrong with that request. Please try again.