Skip to content
This repository has been archived by the owner on May 4, 2020. It is now read-only.
/ scenic Public archive

Commit

Permalink
Add a handler to get picture lists in the channel.
Browse files Browse the repository at this point in the history
The handler returns a picture id list sorted by
descending order of the uploaded date as JSON format.
  • Loading branch information
HyeonJe Jun committed Nov 19, 2012
1 parent 5d5155a commit 82cf086
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
21 changes: 20 additions & 1 deletion server/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ var settings = require('../settings'),
path = require('path'),
fs = require('fs'),
gm = require('gm'),
mongoose = require('mongoose');
mongoose = require('mongoose'),
_ = require('underscore')._;

// mongoose models
var ChannelModel = mongoose.model('Channel'),
Expand Down Expand Up @@ -141,6 +142,24 @@ function Handlers(web) {
});
});
});
},
pictures: function(req, res) {
var name = req.params.name;
ChannelModel.findOne({name: name}, function(err, channel) {
if(err) {
res.send('Error in finding channel...:'+err);
return;
}

var sorted_pictures = _.sortBy(channel.pictures, function(picture) { return -1 * picture.uploaded; }),
pid_list = [];

_.each(sorted_pictures, function(picture) {
pid_list.push(picture._id);
});

res.json(pid_list);
});
}
};

Expand Down
2 changes: 1 addition & 1 deletion server/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = function() {
channel: String,
width: Number,
height: Number,
uploaded: Date
uploaded: {type: Date, default: Date.now }
});

var Channels = new Schema({
Expand Down
3 changes: 3 additions & 0 deletions server/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ function Web() {
'/:name': {
'/upload': {
post: route_handlers.channel.upload
},
'/pictures': {
get: route_handlers.channel.pictures
}
}
},
Expand Down

0 comments on commit 82cf086

Please sign in to comment.