From e193d58112afd5311aef52d6e8a7bfeca821e4f5 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 27 Feb 2014 16:39:34 -0500 Subject: [PATCH] unreadTotal route --- src/controllers/categories.js | 16 ++++++++++++++++ src/webserver.js | 7 +++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/controllers/categories.js b/src/controllers/categories.js index 84fe6833f0..82a4c0d135 100644 --- a/src/controllers/categories.js +++ b/src/controllers/categories.js @@ -57,6 +57,22 @@ categoriesController.unread = function(req, res, next) { }); }; +categoriesController.unreadTotal = function(req, res, next) { + var uid = req.user.uid; + + topics.getTotalUnread(uid, function (err, data) { + if(err) { + return next(err); + } + + if (res.locals.isAPI) { + res.json(data); + } else { + res.render('unread', data); + } + }); +}; + categoriesController.get = function(req, res, next) { var cid = req.params.category_id, page = req.query.page || 1, diff --git a/src/webserver.js b/src/webserver.js index d00e11ec0c..7316bb5f5b 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -629,8 +629,11 @@ process.on('uncaughtException', function(err) { app.get('/recent/:term?', app.buildHeader, controllers.categories.recent); app.get('/api/recent/:term?', app.prepareAPI, controllers.categories.recent); - app.get('/unread/:term?', app.buildHeader, app.authenticate, controllers.categories.unread); - app.get('/api/unread/:term?', app.prepareAPI, app.authenticate, controllers.categories.unread); + app.get('/unread/', app.buildHeader, app.authenticate, controllers.categories.unread); + app.get('/api/unread/', app.prepareAPI, app.authenticate, controllers.categories.unread); + + app.get('/unread/total', app.buildHeader, app.authenticate, controllers.categories.unreadTotal); + app.get('/api/unread/total', app.prepareAPI, app.authenticate, controllers.categories.unreadTotal); app.get('/category/:category_id/:slug?', app.buildHeader, controllers.categories.get); app.get('/api/category/:category_id/:slug?', app.prepareAPI, controllers.categories.get);