paging in list

This commit is contained in:
Meutel 2014-01-22 20:39:31 +01:00
parent bff2fb1bb1
commit 8839e5fb3a
2 changed files with 10 additions and 4 deletions

View File

@ -18,7 +18,6 @@ Author.prototype = Object.create(Endpoint.prototype, {
//TODO related //TODO related
action.loadResource = function(resId, callback) { action.loadResource = function(resId, callback) {
logger.debug('loading author ' + resId); logger.debug('loading author ' + resId);
// TODO load from db
db.get('SELECT * FROM authors WHERE id = '+ resId, function(err, row) { db.get('SELECT * FROM authors WHERE id = '+ resId, function(err, row) {
callback(err, row); callback(err, row);
}); });
@ -27,10 +26,15 @@ Author.prototype = Object.create(Endpoint.prototype, {
break; break;
case 'list': case 'list':
action.loadResources = function(onload, onend) { action.loadResources = function(onload, onend) {
//TODO load from bdd var query = 'SELECT * FROM authors LIMIT ? OFFSET ?';
db.each('SELECT * FROM authors LIMIT 30', function (err, row) { if (!this.perPage) this.perPage = 30;
//TODO sanitize
if (!this.page) this.page = 0;
db.each(query, this.perPage, this.page*this.perPage, function (err, row) {
onload(err, row); onload(err, row);
}, function() { }, function(err) {
//TODO err
if (err) logger.error(err);
onend(); onend();
}); });
}; };

View File

@ -21,6 +21,8 @@ Endpoint.prototype = {
//TODO search //TODO search
} else if (col && method == 'GET') { } else if (col && method == 'GET') {
action = new Action.ListAction(); action = new Action.ListAction();
action.page = url.query.page;
action.perPage = url.query.per_page;
} else if (!col && method == 'POST') { } else if (!col && method == 'POST') {
//TODO edit //TODO edit
} else if (!col && method == 'GET') { } else if (!col && method == 'GET') {