Skip to content

Commit 9fbc871

Browse files
committed
add learnpath.js
1 parent bb9fc41 commit 9fbc871

File tree

4 files changed

+110
-131
lines changed

4 files changed

+110
-131
lines changed

app.js

Lines changed: 12 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
var express = require('express')
66
, routes = require('./routes')
7+
, learnpath = require('./routes/learnpath.js')
78
, tutorial = require('./routes/tutorial')
89
, user = require('./routes/user')
9-
, tutorial = require('./routes/tutorial')
1010
, search = require('./routes/search')
1111
, http = require('http')
1212
, path = require('path')
1313
, passport = require('passport')
1414
, LocalStrategy = require('passport-local').Strategy;
1515

16+
console.log
1617
var app = express();
17-
var ModelProvider = require('./models/model').ModelProvider;
1818

1919
app.configure(function(){
2020
app.set('port', process.env.PORT || 3000);
@@ -46,56 +46,6 @@ app.get('/topic', function(req, res){
4646
});
4747
})
4848

49-
app.get('/tut/new', function(req, res) {
50-
res.render('new_tut.jade', {
51-
title: 'New Post'
52-
53-
});
54-
});
55-
56-
app.post('/tut/new', function(req, res){
57-
var tut = {};
58-
tut.name = req.body.title;
59-
tut.description = req.body.description;
60-
tut.author = req.body.author;
61-
tut.content = req.body.url;
62-
tut.imageUrl = req.body.imageUrl;
63-
tut.enableTopics = req.body.acquires;
64-
tut.requiredTopics = req.body.requires;
65-
modelProvider.createTutorial(tut, function(err, tut_id) {
66-
var title;
67-
if (err)
68-
title = err;
69-
else
70-
title = tut_id;
71-
console.log(title);
72-
res.render('topic_show.jade', {
73-
title: title,
74-
topic: []
75-
});
76-
});
77-
});
78-
79-
app.get('/blog/:id', function(req, res) {
80-
articleProvider.findById(req.params.id, function(error, article) {
81-
res.render('blog_show.jade',
82-
{
83-
title: article.title,
84-
article:article
85-
});
86-
});
87-
});
88-
89-
app.post('/blog/addComment', function(req, res) {
90-
articleProvider.addCommentToArticle(req.param('_id'), {
91-
person: req.param('person'),
92-
comment: req.param('comment'),
93-
created_at: new Date()
94-
} , function( error, docs) {
95-
res.redirect('/blog/' + req.param('_id'))
96-
});
97-
});
98-
9949
// to use persistent login session
10050
passport.serializeUser(function(user, done) {
10151
console.log('serialize ', user);
@@ -118,36 +68,27 @@ passport.use(new LocalStrategy(
11868
));
11969

12070
app.get('/', routes.index);
121-
122-
app.get('/tutorial/new', tutorial.newTutorial);
123-
124-
// TESTING DATABASE, ENABLE IT LATER
125-
app.post('/tutorial/new', tutorial.postNewTutorial);
126-
127-
app.get('/learnpath/new', routes.newLearnpath);
128-
app.post('/learnpath/new', routes.postNewLearnpath);
129-
130-
13171
app.get('/login', routes.login);
13272
app.post('/login', routes.postLogin);
133-
13473
app.get('/users/:uid/profile', routes.profile);
135-
app.get('/learnpath/:lid', routes.learnpath);
136-
app.get('/tutorial/:tid', tutorial.tutorial);
13774
app.get('/profile/:uid', user.profile);
138-
app.get('/search', search.list);
139-
14075

76+
app.get('/tutorial/new', tutorial.newTutorial);
77+
app.get('/tutorial/:tid', tutorial.tutorial);
78+
app.post('/tutorial/new', tutorial.postNewTutorial);
14179
app.post('/tutorial/:tid/comment',tutorial.postTutorialComment);
14280
app.post('/tutorial/:tid/like',tutorial.postTutorialLike);
14381
app.post('/tutorial/:tid/share',tutorial.postTutorialShare);
14482

145-
app.post('/learnpath/:lid/comment',routes.postLearnpathComment);
146-
app.post('/learnpath/:lid/like',routes.postLearnpathLike);
147-
app.post('/learnpath/:lid/share',routes.postLearnpathShare);
83+
app.get('/learnpath/new', learnpath.newLearnpath);
84+
app.get('/learnpath/:lid', learnpath.learnpath);
85+
app.post('/learnpath/new', learnpath.postNewLearnpath);
86+
app.post('/learnpath/:lid/comment',learnpath.postLearnpathComment);
87+
app.post('/learnpath/:lid/like',learnpath.postLearnpathLike);
88+
app.post('/learnpath/:lid/share',learnpath.postLearnpathShare);
14889

90+
app.get('/search', search.list);
14991
app.get('/topic_hint', routes.topic_hint);
150-
15192
app.get('/auth',
15293
passport.authenticate('local', {failureRedirect: '/login'}),
15394
function(req, res) {

routes/index.js

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,6 @@ exports.index = function(req, res) {
1212
};
1313

1414

15-
16-
exports.learnpath = function(req, res) {
17-
console.log(req.params);
18-
var pathId = req.params.lid;
19-
if (!pathId) {
20-
res.send("path Id not defined");
21-
} else {
22-
// fetch tutorial based on id
23-
var path = {
24-
id: pathId,
25-
title: 'NodeJS path',
26-
createdBy: 'Hung Doan',
27-
star: 5,
28-
desc: "In this path I will run you through the process setting up an Express.js app and making it do what a basic website might do. You will learn the basics of routes, views, Jade templates, Stylus CSS engine, handling POST and GET requests.",
29-
url: 'http://www.hacksparrow.com/express-js-tutorial.html',
30-
stat: {
31-
likes: 103,
32-
shares: 50,
33-
views: 1042
34-
},
35-
comments: [
36-
{poster: {name: 'Hung Doan',
37-
profile_url: 'https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/371019_697811725_247259128_q.jpg'},
38-
content: 'Hello world!'}
39-
]
40-
};
41-
res.render('learnpath', {
42-
title: path.title,
43-
path: path
44-
});
45-
}
46-
}
47-
4815
/*
4916
* GET login page.
5017
*/
@@ -60,31 +27,6 @@ exports.postLogin = function(req, res){
6027
};
6128

6229

63-
64-
65-
exports.newLearnpath = function(req, res){
66-
console.log("new path ");
67-
res.render('new_path', {});
68-
};
69-
70-
exports.postNewLearnpath = function(req, res){
71-
console.log(req.body);
72-
var title = req.body.title;
73-
};
74-
75-
/*
76-
* POST tut comment
77-
*/
78-
79-
80-
exports.postLearnpathComment = function(req, res){
81-
82-
var comment = req.body.comment;
83-
var learnpathId = req.params.lid;
84-
console.log("comment " + comment + " learnpath id " +learnpathId);
85-
res.send("respond with a resource");
86-
};
87-
8830
exports.profile = function(req, res){
8931
var uid = req.params.uid;
9032
var user = {

routes/learnpath.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
var modelProvider = require('../models/model').instance;
2+
3+
exports.learnpath = function(req, res) {
4+
console.log(req.params);
5+
var pathId = req.params.lid;
6+
if (!pathId) {
7+
res.send("path Id not defined");
8+
} else {
9+
// fetch tutorial based on id
10+
var path = {
11+
id: pathId,
12+
title: 'NodeJS path',
13+
createdBy: 'Hung Doan',
14+
star: 5,
15+
desc: "In this path I will run you through the process setting up an Express.js app and making it do what a basic website might do. You will learn the basics of routes, views, Jade templates, Stylus CSS engine, handling POST and GET requests.",
16+
url: 'http://www.hacksparrow.com/express-js-tutorial.html',
17+
stat: {
18+
likes: 103,
19+
shares: 50,
20+
views: 1042
21+
},
22+
comments: [
23+
{poster: {name: 'Hung Doan',
24+
profile_url: 'https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/371019_697811725_247259128_q.jpg'},
25+
content: 'Hello world!'}
26+
]
27+
};
28+
res.render('learnpath', {
29+
title: path.title,
30+
path: path
31+
});
32+
}
33+
}
34+
35+
exports.newLearnpath = function(req, res){
36+
console.log("new path ");
37+
res.render('new_path', {});
38+
};
39+
40+
exports.postNewLearnpath = function(req, res){
41+
console.log(req.body);
42+
var title = req.body.title;
43+
};
44+
45+
exports.postLearnpathComment = function(req, res){
46+
47+
var comment = req.body.comment;
48+
var learnpathId = req.params.lid;
49+
console.log("comment " + comment + " learnpath id " +learnpathId);
50+
res.send("respond with a resource");
51+
};
52+
53+
exports.postLearnpathLike = function(req, res){
54+
55+
var comment = req.body.comment;
56+
var learnpathId = req.params.lid;
57+
console.log("comment " + comment + " learnpath id " +learnpathId);
58+
res.send("respond with a resource");
59+
};
60+
61+
exports.postLearnpathShare = function(req, res){
62+
63+
var comment = req.body.comment;
64+
var learnpathId = req.params.lid;
65+
console.log("comment " + comment + " learnpath id " +learnpathId);
66+
res.send("respond with a resource");
67+
};

routes/tutorial.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
11
var modelProvider = require('../models/model').instance;
2-
3-
2+
exports.learnpath = function(req, res) {
3+
console.log(req.params);
4+
var pathId = req.params.lid;
5+
if (!pathId) {
6+
res.send("path Id not defined");
7+
} else {
8+
// fetch tutorial based on id
9+
var path = {
10+
id: pathId,
11+
title: 'NodeJS path',
12+
createdBy: 'Hung Doan',
13+
star: 5,
14+
desc: "In this path I will run you through the process setting up an Express.js app and making it do what a basic website might do. You will learn the basics of routes, views, Jade templates, Stylus CSS engine, handling POST and GET requests.",
15+
url: 'http://www.hacksparrow.com/express-js-tutorial.html',
16+
stat: {
17+
likes: 103,
18+
shares: 50,
19+
views: 1042
20+
},
21+
comments: [
22+
{poster: {name: 'Hung Doan',
23+
profile_url: 'https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/371019_697811725_247259128_q.jpg'},
24+
content: 'Hello world!'}
25+
]
26+
};
27+
res.render('learnpath', {
28+
title: path.title,
29+
path: path
30+
});
31+
}
32+
}
433
exports.tutorial = function(req, res) {
534
var tutorialId = req.params.tid;
635

0 commit comments

Comments
 (0)