Skip to content

Commit

Permalink
created controller to show blog photo
Browse files Browse the repository at this point in the history
  • Loading branch information
pramit-marattha committed Jan 20, 2021
1 parent 559989d commit 12aee19
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions server/controllers/blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,16 @@ exports.update = (req, res) => {
});
});
};

exports.photo =(req,res)=>{
const slug = req.params.slug.toLowerCase();
Blog.findOne({slug}).select("photo").exec((err,blog)=>{
if (err || !blog) {
return res.status(400).json({
error: errorHandler(err)
})
}
res.set('Content-Type',blog.photo.contentType)
return res.send(blog.photo.data);
})
}
3 changes: 2 additions & 1 deletion server/routes/blog.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require('express');
const router = express.Router();
const {create ,list,bloglistsallCategoriesTags,read,remove,update} = require("../controllers/blog.js");
const {create ,list,bloglistsallCategoriesTags,read,remove,update,photo} = require("../controllers/blog.js");
const {requireLogin,adminAuthenticationMiddleware} = require("../controllers/userAuthentication.js");

router.post('/blog',requireLogin,adminAuthenticationMiddleware,create);
Expand All @@ -9,6 +9,7 @@ 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);
router.get('/blog/photo/:slug',photo);


module.exports = router;

0 comments on commit 12aee19

Please # to comment.