diff options
Diffstat (limited to 'part4/blog/controllers')
-rw-r--r-- | part4/blog/controllers/blogs.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/part4/blog/controllers/blogs.js b/part4/blog/controllers/blogs.js new file mode 100644 index 0000000..78540c8 --- /dev/null +++ b/part4/blog/controllers/blogs.js @@ -0,0 +1,25 @@ +const blogsRouter = require('express').Router() +const Blog = require('../models/blog') + +blogsRouter.get('/', (request, response) => { + Blog + .find({}) + .then(blogs => { + response.json(blogs) + }) + .catch((error) => { + console.log(error.message) + }) +}) + +blogsRouter.post('/', (request, response) => { + const blog = new Blog(request.body) + + blog + .save() + .then(result => { + response.status(201).json(result) + }) +}) + +module.exports = blogsRouter |