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

View File

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