summaryrefslogtreecommitdiff
path: root/bucky/app
diff options
context:
space:
mode:
Diffstat (limited to 'bucky/app')
-rw-r--r--bucky/app/api.js17
-rw-r--r--bucky/app/bucky.js40
2 files changed, 57 insertions, 0 deletions
diff --git a/bucky/app/api.js b/bucky/app/api.js
index 7a0e068..80cba16 100644
--- a/bucky/app/api.js
+++ b/bucky/app/api.js
@@ -32,6 +32,23 @@ function route (app){
function(req, res){
res.json(util.sanitizeUser(res.user))
})
+ app.get("/api/profile/:username",
+ middleware.ensureAuthenticated,
+ bucky.ensureUser,
+ bucky.sanitizeUser,
+ bucky.ensureThreadsForUser,
+ // bucky.ensureTopThreadsForUser,
+ // bucky.ensureCommentsForUser,
+ bucky.ensureFilesForUser,
+ function(req, res) {
+ res.json({
+ user: res.user,
+ threads: res.threads,
+ // topThreads: res.topThreads,
+ files: res.files,
+ // comments: res.comments,
+ })
+ })
app.put("/api/checkUsernames",
middleware.ensureAuthenticated,
bucky.checkUsernames,
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js
index 76c543a..2a362b5 100644
--- a/bucky/app/bucky.js
+++ b/bucky/app/bucky.js
@@ -312,6 +312,46 @@ var bucky = module.exports = {
next()
})
},
+ ensureThreadsForUser: function (req, res, next){
+ var username = res.user.username
+ var limit = parseInt(req.params.limit) || 10
+ var offset = parseInt(req.params.offset) || 0
+ if (! username) {
+ res.sendStatus(404)
+ }
+ db.getThreadsForUser(username, limit, offset).then(function(threads){
+ res.threads = threads
+ res.threads_ids = res.threads.pluck("id").sort()
+ res.keywords = _.uniq(res.threads.pluck("keyword"))
+ next()
+ })
+ },
+ ensureTopThreadsForUser: function (req, res, next){
+ var username = res.user.username
+ var limit = parseInt(req.params.limit) || 10
+ var offset = parseInt(req.params.offset) || 0
+ if (! username) {
+ res.sendStatus(404)
+ }
+ db.getTopThreadsForUser(username, limit, offset).then(function(top_threads){
+ res.topThreads = top_threads
+ res.topThreads_ids = res.topThreads.pluck("id").sort()
+ res.topKeywords = _.uniq(res.topThreads.pluck("keyword"))
+ next()
+ })
+ },
+ ensureCommentsForUser: function (req, res, next){
+ db.getCommentsForUser(res.user.username).then(function(comments){
+ res.comments = comments || []
+ next()
+ })
+ },
+ ensureFilesForUser: function (req, res, next){
+ db.getFilesForUser(res.user.username).then(function(files){
+ res.files = files || []
+ next()
+ })
+ },
createKeyword: function (req, res, next){
if (! req.body.keyword || ! req.body.keyword.length) {
res.json({ error: "no keyword" })