passing off hacker news clone to Nathan and his pair
This commit is contained in:
20
controllers/story.js
Normal file
20
controllers/story.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
var R = require('ramda'),
|
||||||
|
debug = require('debug')('freecc:cntr:post'),
|
||||||
|
Post = require('./../models/Post'),
|
||||||
|
Comment = require('./../models/Comment'),
|
||||||
|
User = require('./../models/User'),
|
||||||
|
resources = require('./resources');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post Controller
|
||||||
|
*/
|
||||||
|
|
||||||
|
exports.index = function(req, res, next) {
|
||||||
|
var posts = Post.find({}).sort({'rank': -1});
|
||||||
|
posts.exec(function(err, listings) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
res.json(listing);
|
||||||
|
});
|
||||||
|
};
|
@ -2,19 +2,10 @@ var mongoose = require('mongoose');
|
|||||||
var secrets = require('../config/secrets');
|
var secrets = require('../config/secrets');
|
||||||
|
|
||||||
var commentSchema = new mongoose.Schema({
|
var commentSchema = new mongoose.Schema({
|
||||||
rank: Number,
|
rank: { type: Number, default: -Infinity },
|
||||||
upVotes: [
|
upVotes: { type: Array, default: [] },
|
||||||
{
|
author: {},
|
||||||
upVotedBy: ObjectId,
|
comments: { type: Array, default: [] }
|
||||||
upVotedTime: Number
|
|
||||||
}
|
|
||||||
],
|
|
||||||
author: {
|
|
||||||
username: String,
|
|
||||||
id: ObjectId,
|
|
||||||
picture: String
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = mongoose.model('BonfireCompletion', bonfireCompletionSchema);
|
module.exports = mongoose.model('Comment', commentSchema);
|
||||||
|
|
@ -1,23 +0,0 @@
|
|||||||
var mongoose = require('mongoose');
|
|
||||||
var secrets = require('../config/secrets');
|
|
||||||
|
|
||||||
var postSchema = new mongoose.Schema({
|
|
||||||
headline: String,
|
|
||||||
link: String,
|
|
||||||
body: String,
|
|
||||||
rank: Number,
|
|
||||||
upVotes: [
|
|
||||||
{
|
|
||||||
upVotedBy: ObjectId,
|
|
||||||
upVotedTime: Number
|
|
||||||
}
|
|
||||||
],
|
|
||||||
author: {
|
|
||||||
username: String,
|
|
||||||
id: ObjectId,
|
|
||||||
picture: String
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = mongoose.model('BonfireCompletion', bonfireCompletionSchema);
|
|
||||||
|
|
15
models/Story.js
Normal file
15
models/Story.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
var mongoose = require('mongoose');
|
||||||
|
var secrets = require('../config/secrets');
|
||||||
|
|
||||||
|
var storySchema = new mongoose.Schema({
|
||||||
|
headline: String,
|
||||||
|
link: String,
|
||||||
|
body: String,
|
||||||
|
rank: { type: Number, default: -Infinity },
|
||||||
|
upVotes: { type: Array, default: [] },
|
||||||
|
author: {},
|
||||||
|
comments: { type: Array, default: [] }
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = mongoose.model('Story', storySchema);
|
||||||
|
|
@ -1,17 +1,20 @@
|
|||||||
require('dotenv').load();
|
require('dotenv').load();
|
||||||
var Challenge = require('../models/Challenge.js'),
|
var Challenge = require('../models/Challenge.js'),
|
||||||
Bonfire = require('../models/Bonfire.js'),
|
Bonfire = require('../models/Bonfire.js'),
|
||||||
|
Comment = require('../models/Comment.js'),
|
||||||
|
Story = require('../models/Story.js'),
|
||||||
Courseware = require('../models/Courseware.js'),
|
Courseware = require('../models/Courseware.js'),
|
||||||
mongoose = require('mongoose'),
|
mongoose = require('mongoose'),
|
||||||
secrets = require('../config/secrets'),
|
secrets = require('../config/secrets'),
|
||||||
challenges = require('./challenges.json'),
|
challenges = require('./challenges.json'),
|
||||||
coursewares = require('./coursewares.json'),
|
coursewares = require('./coursewares.json'),
|
||||||
|
stories = require('./stories.json'),
|
||||||
bonfires = require('./bonfires.json');
|
bonfires = require('./bonfires.json');
|
||||||
|
|
||||||
mongoose.connect(secrets.db);
|
mongoose.connect(secrets.db);
|
||||||
|
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
var offerings = 3;
|
var offerings = 4;
|
||||||
|
|
||||||
var CompletionMonitor = function() {
|
var CompletionMonitor = function() {
|
||||||
counter++;
|
counter++;
|
||||||
@ -73,4 +76,21 @@ Courseware.remove({}, function(err, data) {
|
|||||||
CompletionMonitor();
|
CompletionMonitor();
|
||||||
});
|
});
|
||||||
console.log('coursewares');
|
console.log('coursewares');
|
||||||
|
});
|
||||||
|
|
||||||
|
Story.remove({}, function(err, data) {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
} else {
|
||||||
|
console.log('Deleted ', data);
|
||||||
|
}
|
||||||
|
Story.create(coursewares, function(err, data) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
} else {
|
||||||
|
console.log('Saved ', data);
|
||||||
|
}
|
||||||
|
CompletionMonitor();
|
||||||
|
});
|
||||||
|
console.log('stories');
|
||||||
});
|
});
|
67
seed_data/stories.json
Normal file
67
seed_data/stories.json
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"headline": "Cat sits on keyboard 0",
|
||||||
|
"link": "http://kotaku.com/5991046/why-cats-love-sitting-on-keyboards",
|
||||||
|
"body": "cats love keyboards you know",
|
||||||
|
"rank": 0,
|
||||||
|
"upVotes": [],
|
||||||
|
"author": {
|
||||||
|
"username": "terakilobyte",
|
||||||
|
"id": "a2ad135e2aa27c14fc73ee11",
|
||||||
|
"picture": "https://www.google.com/search?q=cat+photo+google+images&tbm=isch&imgil=7dFgV4OZlJObjM%253A%253BDGoqtUgH7IKDWM%253Bhttp%25253A%25252F%25252Fwww.wired.co.uk%25252Fnews%25252Farchive%25252F2012-06%25252F26%25252Fgoogle-brain-recognises-cats&source=iu&pf=m&fir=7dFgV4OZlJObjM%253A%252CDGoqtUgH7IKDWM%252C_&usg=__yxi54C0GOssHCOLnh1StLAH7KNk%3D&biw=1920&bih=981&ved=0CDYQyjc&ei=n3n1VL6ENcHZoATjvYDABQ#imgrc=7dFgV4OZlJObjM%253A%3BDGoqtUgH7IKDWM%3Bhttp%253A%252F%252Fcdni.wired.co.uk%252F620x413%252Fs_v%252Fshutterstock_65735200.jpg%3Bhttp%253A%252F%252Fwww.wired.co.uk%252Fnews%252Farchive%252F2012-06%252F26%252Fgoogle-brain-recognises-cats%3B620%3B413"
|
||||||
|
},
|
||||||
|
"comments": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"headline": "Cat sits on keyboard 1",
|
||||||
|
"link": "http://kotaku.com/5991046/why-cats-love-sitting-on-keyboards",
|
||||||
|
"body": "cats love keyboards you know",
|
||||||
|
"rank": 1,
|
||||||
|
"upVotes": [],
|
||||||
|
"author": {
|
||||||
|
"username": "terakilobyte",
|
||||||
|
"id": "a2ad135e2aa27c14fc73ee11",
|
||||||
|
"picture": "https://www.google.com/search?q=cat+photo+google+images&tbm=isch&imgil=7dFgV4OZlJObjM%253A%253BDGoqtUgH7IKDWM%253Bhttp%25253A%25252F%25252Fwww.wired.co.uk%25252Fnews%25252Farchive%25252F2012-06%25252F26%25252Fgoogle-brain-recognises-cats&source=iu&pf=m&fir=7dFgV4OZlJObjM%253A%252CDGoqtUgH7IKDWM%252C_&usg=__yxi54C0GOssHCOLnh1StLAH7KNk%3D&biw=1920&bih=981&ved=0CDYQyjc&ei=n3n1VL6ENcHZoATjvYDABQ#imgrc=7dFgV4OZlJObjM%253A%3BDGoqtUgH7IKDWM%3Bhttp%253A%252F%252Fcdni.wired.co.uk%252F620x413%252Fs_v%252Fshutterstock_65735200.jpg%3Bhttp%253A%252F%252Fwww.wired.co.uk%252Fnews%252Farchive%252F2012-06%252F26%252Fgoogle-brain-recognises-cats%3B620%3B413"
|
||||||
|
},
|
||||||
|
"comments": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"headline": "Cat sits on keyboard 3",
|
||||||
|
"link": "http://kotaku.com/5991046/why-cats-love-sitting-on-keyboards",
|
||||||
|
"body": "cats love keyboards you know",
|
||||||
|
"rank": 3,
|
||||||
|
"upVotes": [],
|
||||||
|
"author": {
|
||||||
|
"username": "terakilobyte",
|
||||||
|
"id": "a2ad135e2aa27c14fc73ee11",
|
||||||
|
"picture": "https://www.google.com/search?q=cat+photo+google+images&tbm=isch&imgil=7dFgV4OZlJObjM%253A%253BDGoqtUgH7IKDWM%253Bhttp%25253A%25252F%25252Fwww.wired.co.uk%25252Fnews%25252Farchive%25252F2012-06%25252F26%25252Fgoogle-brain-recognises-cats&source=iu&pf=m&fir=7dFgV4OZlJObjM%253A%252CDGoqtUgH7IKDWM%252C_&usg=__yxi54C0GOssHCOLnh1StLAH7KNk%3D&biw=1920&bih=981&ved=0CDYQyjc&ei=n3n1VL6ENcHZoATjvYDABQ#imgrc=7dFgV4OZlJObjM%253A%3BDGoqtUgH7IKDWM%3Bhttp%253A%252F%252Fcdni.wired.co.uk%252F620x413%252Fs_v%252Fshutterstock_65735200.jpg%3Bhttp%253A%252F%252Fwww.wired.co.uk%252Fnews%252Farchive%252F2012-06%252F26%252Fgoogle-brain-recognises-cats%3B620%3B413"
|
||||||
|
},
|
||||||
|
"comments": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"headline": "Cat sits on keyboard 20",
|
||||||
|
"link": "http://kotaku.com/5991046/why-cats-love-sitting-on-keyboards",
|
||||||
|
"body": "cats love keyboards you know",
|
||||||
|
"rank": 20,
|
||||||
|
"upVotes": [],
|
||||||
|
"author": {
|
||||||
|
"username": "terakilobyte",
|
||||||
|
"id": "a2ad135e2aa27c14fc73ee11",
|
||||||
|
"picture": "https://www.google.com/search?q=cat+photo+google+images&tbm=isch&imgil=7dFgV4OZlJObjM%253A%253BDGoqtUgH7IKDWM%253Bhttp%25253A%25252F%25252Fwww.wired.co.uk%25252Fnews%25252Farchive%25252F2012-06%25252F26%25252Fgoogle-brain-recognises-cats&source=iu&pf=m&fir=7dFgV4OZlJObjM%253A%252CDGoqtUgH7IKDWM%252C_&usg=__yxi54C0GOssHCOLnh1StLAH7KNk%3D&biw=1920&bih=981&ved=0CDYQyjc&ei=n3n1VL6ENcHZoATjvYDABQ#imgrc=7dFgV4OZlJObjM%253A%3BDGoqtUgH7IKDWM%3Bhttp%253A%252F%252Fcdni.wired.co.uk%252F620x413%252Fs_v%252Fshutterstock_65735200.jpg%3Bhttp%253A%252F%252Fwww.wired.co.uk%252Fnews%252Farchive%252F2012-06%252F26%252Fgoogle-brain-recognises-cats%3B620%3B413"
|
||||||
|
},
|
||||||
|
"comments": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"headline": "Cat sits on keyboard 2",
|
||||||
|
"link": "http://kotaku.com/5991046/why-cats-love-sitting-on-keyboards",
|
||||||
|
"body": "cats love keyboards you know",
|
||||||
|
"rank": 2,
|
||||||
|
"upVotes": [],
|
||||||
|
"author": {
|
||||||
|
"username": "terakilobyte",
|
||||||
|
"id": "a2ad135e2aa27c14fc73ee11",
|
||||||
|
"picture": "https://www.google.com/search?q=cat+photo+google+images&tbm=isch&imgil=7dFgV4OZlJObjM%253A%253BDGoqtUgH7IKDWM%253Bhttp%25253A%25252F%25252Fwww.wired.co.uk%25252Fnews%25252Farchive%25252F2012-06%25252F26%25252Fgoogle-brain-recognises-cats&source=iu&pf=m&fir=7dFgV4OZlJObjM%253A%252CDGoqtUgH7IKDWM%252C_&usg=__yxi54C0GOssHCOLnh1StLAH7KNk%3D&biw=1920&bih=981&ved=0CDYQyjc&ei=n3n1VL6ENcHZoATjvYDABQ#imgrc=7dFgV4OZlJObjM%253A%3BDGoqtUgH7IKDWM%3Bhttp%253A%252F%252Fcdni.wired.co.uk%252F620x413%252Fs_v%252Fshutterstock_65735200.jpg%3Bhttp%253A%252F%252Fwww.wired.co.uk%252Fnews%252Farchive%252F2012-06%252F26%252Fgoogle-brain-recognises-cats%3B620%3B413"
|
||||||
|
},
|
||||||
|
"comments": []
|
||||||
|
}
|
||||||
|
]
|
5
views/post/index.jade
Normal file
5
views/post/index.jade
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
extends ../layout
|
||||||
|
block content
|
||||||
|
.panel.text-center
|
||||||
|
h1.hug-top Camper News
|
||||||
|
include parials/post
|
24
views/post/posts.jade
Normal file
24
views/post/posts.jade
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
h3
|
||||||
|
ol#bonfireList Test!
|
||||||
|
|
||||||
|
//script(src="https://cdn.jsdelivr.net/ramda/0.10.0/ramda.min.js")
|
||||||
|
//script.
|
||||||
|
// var getLinkedName = function getLinkedName(name) {
|
||||||
|
// return name.toLowerCase().replace(/\s/g, '-');
|
||||||
|
// }
|
||||||
|
// $.ajax({
|
||||||
|
// url: '/bonfires/getBonfireList',
|
||||||
|
// type: 'GET'
|
||||||
|
// })
|
||||||
|
// .success(
|
||||||
|
// function(data) {
|
||||||
|
// for (var i = 0; i < data.bonfireList.length; i++) {
|
||||||
|
// var li = document.createElement('li');
|
||||||
|
// var linkedName = getLinkedName(data.bonfireList[i].name);
|
||||||
|
// if (R.contains(data.bonfireList[i].id, data.completedList)) {
|
||||||
|
// $(li).addClass('strikethrough');
|
||||||
|
// }
|
||||||
|
// $(li).html("<a href='/bonfires/" + linkedName + "'>" + data.bonfireList[i].name + "</a></li>");
|
||||||
|
// $(li).appendTo($('#bonfireList'));
|
||||||
|
// }
|
||||||
|
// });
|
Reference in New Issue
Block a user