diff options
Diffstat (limited to 'bucky')
| -rw-r--r-- | bucky/app/api.js | 8 | ||||
| -rw-r--r-- | bucky/app/bucky.js | 15 | ||||
| -rw-r--r-- | bucky/app/pages.js | 7 | ||||
| -rw-r--r-- | bucky/db/index.js | 27 |
4 files changed, 54 insertions, 3 deletions
diff --git a/bucky/app/api.js b/bucky/app/api.js index b4231e7..a6aa83f 100644 --- a/bucky/app/api.js +++ b/bucky/app/api.js @@ -34,6 +34,12 @@ function route (app){ function(req, res){ res.json(util.sanitizeUser(res.user)) }) + app.get("/api/users", + middleware.ensureAuthenticated, + bucky.ensureUserlist, + function(req, res) { + res.json(res.users) + }) app.get("/api/profile/:username", middleware.ensureAuthenticated, bucky.ensureUser, @@ -259,9 +265,11 @@ function route (app){ middleware.ensureAuthenticated, bucky.ensureKeywords, bucky.ensureThreadGroups, + bucky.ensureLatestKeywordThreads, function(req, res){ res.json({ keywords: res.keywords, + threads: res.threads, threadGroups: res.threadGroups, }) }) diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js index 3824c5e..8ff0b15 100644 --- a/bucky/app/bucky.js +++ b/bucky/app/bucky.js @@ -296,6 +296,12 @@ var bucky = module.exports = { next() }) }, + ensureLatestKeywordThreads: function (req, res, next){ + db.getLatestKeywordThreads().then(function(threads){ + res.threads = threads + next() + }) + }, ensureThreadGroups: function (req, res, next){ db.getThreadGroups().then(function(threadGroups){ res.threadGroups = threadGroups @@ -564,6 +570,15 @@ var bucky = module.exports = { } }) }, + ensureUserlist: function (req, res, next){ + db.getUsers().then(function(users){ + if (! users) { + return res.sendStatus(404) + } + res.users = users + next() + }) + }, sanitizeUser: function(req, res, next) { res.user = util.sanitizeUser(res.user) next() diff --git a/bucky/app/pages.js b/bucky/app/pages.js index 7f666be..b007742 100644 --- a/bucky/app/pages.js +++ b/bucky/app/pages.js @@ -73,6 +73,13 @@ function route (app){ res.render("pages/profile_form", {title: "edit your profile"}) }) + app.get("/users", + middleware.ensureAuthenticated, + function(req, res){ + res.render("pages/users", { + }) + }) + app.get("/search/", middleware.ensureAuthenticated, function(req, res){ diff --git a/bucky/db/index.js b/bucky/db/index.js index f454c92..53e36dd 100644 --- a/bucky/db/index.js +++ b/bucky/db/index.js @@ -55,8 +55,13 @@ db.createUser = function(data){ } db.getUsers = function () { return User.query(function(qb){ - qb.orderBy("id", "desc") - }).fetchAll() + qb.orderBy("username", "desc") + }).fetchAll({ + columns: [ + "id", "username", "realname", "firstseen", "lastseen", + "location", "website", "avatar", + ] + }) } db.getUser = function(id) { var model = new User({'id': id}) @@ -281,8 +286,24 @@ db.getKeyword = function (keyword) { return Keyword.query("where", "keyword", "=", keyword).fetch() } db.getThreadGroups = function (keyword) { - return knex.column('keyword').sum('viewed').as('viewed').count('*').as('count').column('id').column('title').column('lastmodified').column('privacy').select().from('threads').groupBy('keyword') + return ( + knex.column('keyword') + .sum('viewed').as('viewed') + .count('*').as('count') + .select().from('threads').groupBy('keyword') + ) } +db.getLatestKeywordThreads = function (keyword) { + var ids = knex('threads').max('id').groupBy('keyword') + return ( + knex.select('id', 'keyword', 'title', 'lastmodified', 'privacy').from('threads').where('id', 'in', ids) + ) +} + // .column('id') + // .column('title') + // .column('lastmodified') + // .column('privacy') + db.createKeyword = function(data){ return new db.Keyword(data).save() } |
