Skip to content

Commit

Permalink
created boglists route to list all the blogs in the backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
pramit-marattha committed Jan 20, 2021
1 parent 1fa60b6 commit 34453a5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
29 changes: 29 additions & 0 deletions server/controllers/blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,32 @@ exports.create = (req, res) => {
});
});
};

//list,bloglistsallCategoriesTags,read,remove,update

exports.list =(req,res)=>{
Blog.find({}).populate("categories","_id name slug").populate("taglists","_id name slug").populate("postedBy","_id name username") // second arguments is for particularly pupulating that specific field
.select("_id title slug excerpt categories taglists postedBy createdAt updatedAt").exec((err,data)=>{
if (err){
return res.json({
error: errorHandler(err)
})
}
})
}

exports.bloglistsallCategoriesTags =(req,res)=>{

}

exports.read =(req,res)=>{

}

exports.remove =(req,res)=>{

}

exports.update =(req,res)=>{

}
8 changes: 7 additions & 1 deletion server/routes/blog.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
const express = require('express');
const router = express.Router();
const {create} = require("../controllers/blog.js");
const {create ,list,bloglistsallCategoriesTags,read,remove,update} = require("../controllers/blog.js");
const {requireLogin,adminAuthenticationMiddleware} = require("../controllers/userAuthentication.js");

router.post('/blog',requireLogin,adminAuthenticationMiddleware,create);
router.get('/bloglists',list);
router.post('/bloglists-categories-taglists',bloglistsallCategoriesTags);
router.get('/blog/:slug',read);
router.delete('/blog/:slug',requireLogin,adminAuthenticationMiddleware,remove);
router.put('/blog/:slug',requireLogin,adminAuthenticationMiddleware,update);


module.exports = router;

0 comments on commit 34453a5

Please sign in to comment.