aboutsummaryrefslogtreecommitdiff
path: root/controllers/post.js
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2021-05-03 15:34:46 +0200
committerMateja <mail@matejamaric.com>2021-05-03 15:34:46 +0200
commit9eeca255cfe41ca4a962422c3703274caa530021 (patch)
tree2353081cf1e2b75535eb4e5c65e418bb3f12cf90 /controllers/post.js
parent3460f9ad874495469cfa8d4aaa42b66f5e427bf2 (diff)
downloadnode-playground-9eeca255cfe41ca4a962422c3703274caa530021.tar.gz
node-playground-9eeca255cfe41ca4a962422c3703274caa530021.zip
Started using controllers.
Diffstat (limited to 'controllers/post.js')
-rw-r--r--controllers/post.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/controllers/post.js b/controllers/post.js
new file mode 100644
index 0000000..7c66dec
--- /dev/null
+++ b/controllers/post.js
@@ -0,0 +1,30 @@
+const Post = require('../models/post');
+
+module.exports = {
+
+ index(req, res) {
+ Post.find().lean().exec((err, posts) => {
+ res.render('home', {
+ title: 'Home Page',
+ home: true,
+ posts: posts
+ });
+ });
+ },
+
+ create(req, res) {
+ res.render('new-post', {
+ title: 'Make A New Post',
+ newPost: true
+ });
+ },
+
+ store(req, res) {
+ const newPost = new Post({
+ 'title': req.body.title,
+ 'text': req.body.text
+ });
+ newPost.save().then(() => res.redirect('/'));
+ }
+
+};