diff options
-rw-r--r-- | controllers/post.js | 4 | ||||
-rw-r--r-- | public/css/style.css | 3 | ||||
-rw-r--r-- | routes/web.js | 1 | ||||
-rw-r--r-- | views/home.handlebars | 3 |
4 files changed, 10 insertions, 1 deletions
diff --git a/controllers/post.js b/controllers/post.js index 7c66dec..d879fcc 100644 --- a/controllers/post.js +++ b/controllers/post.js @@ -25,6 +25,10 @@ module.exports = { 'text': req.body.text }); newPost.save().then(() => res.redirect('/')); + }, + + destroy(req, res) { + Post.findByIdAndRemove(req.params.id).then(() => res.redirect('/')); } }; diff --git a/public/css/style.css b/public/css/style.css index d3a017d..d8fb0d5 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -20,6 +20,9 @@ footer, nav { padding: 1rem; border-radius: 0 35%; } +a.badge { text-decoration: none; } +a.badge:hover { color: white; } + .btn { background: #002147; color: white; } diff --git a/routes/web.js b/routes/web.js index 732c87c..ee07d85 100644 --- a/routes/web.js +++ b/routes/web.js @@ -5,5 +5,6 @@ const postController = require('../controllers/post'); router.get('/', postController.index); router.get('/new-post', postController.create); router.post('/new-post', postController.store); +router.get('/remove-post/:id', postController.destroy); module.exports = router; diff --git a/views/home.handlebars b/views/home.handlebars index 768b62d..6061e4e 100644 --- a/views/home.handlebars +++ b/views/home.handlebars @@ -2,7 +2,7 @@ <h1 class="mt-2">Posts</h1> {{#each posts}} - <div class="card mt-3"> + <div class="card mb-3"> <div class="card-header"> {{this.title}} </div> @@ -10,6 +10,7 @@ <div class="card-text"> {{this.text}} </div> + <a href="/remove-post/{{this._id}}" class="badge float-end">Remove</a> </div> </div> {{/each}} |