-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathBlogController.js
46 lines (41 loc) · 1.21 KB
/
BlogController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const blogService = require("../services/BlogService");
exports.getAllBlogs = async (req, res) => {
try {
const blogs = await blogService.getAllBlogs();
res.json({ data: blogs, status: "success" });
} catch (err) {
res.status(500).json({ error: err.message });
}
};
exports.createBlog = async (req, res) => {
try {
const blog = await blogService.createBlog(req.body);
res.json({ data: blog, status: "success" });
} catch (err) {
res.status(500).json({ error: err.message });
}
};
exports.getBlogById = async (req, res) => {
try {
const blog = await blogService.getBlogById(req.params.id);
res.json({ data: blog, status: "success" });
} catch (err) {
res.status(500).json({ error: err.message });
}
};
exports.updateBlog = async (req, res) => {
try {
const blog = await blogService.updateBlog(req.params.id, req.body);
res.json({ data: blog, status: "success" });
} catch (err) {
res.status(500).json({ error: err.message });
}
};
exports.deleteBlog = async (req, res) => {
try {
const blog = await blogService.deleteBlog(req.params.id);
res.json({ data: blog, status: "success" });
} catch (err) {
res.status(500).json({ error: err.message });
}
};