From 34b3fefaddd165b649c53e140f6b749c18943d26 Mon Sep 17 00:00:00 2001 From: Mateja Date: Mon, 3 May 2021 17:44:38 +0200 Subject: Add delete option on every post. --- controllers/post.js | 4 ++++ public/css/style.css | 3 +++ routes/web.js | 1 + views/home.handlebars | 3 ++- 4 files changed, 10 insertions(+), 1 deletion(-) 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 @@

Posts

{{#each posts}} -
+
{{this.title}}
@@ -10,6 +10,7 @@
{{this.text}}
+ Remove
{{/each}} -- cgit v1.2.3