Skip to content
Snippets Groups Projects
Commit ea1b7402 authored by Morris, George (UG - Computer Science)'s avatar Morris, George (UG - Computer Science)
Browse files

Created the getPosts and getPostById functions to handle the requests for all...

Created the getPosts and getPostById functions to handle the requests for all posts and a specific post
parent bc644ad6
No related branches found
No related tags found
2 merge requests!8CI/CD,!2Posts service
......@@ -2,7 +2,12 @@ import mongoose from 'mongoose';
import Post from '../models/Post.js';
export const getPosts = async (req, res) => {
try {
const posts = await Post.find().sort({ createdAt: "desc" });
return res.status(200).json(posts);
} catch (error) {
return res.status(500).json({ message: "Something went wrong" });
}
};
export const createPost = async (req, res) => {
......@@ -10,7 +15,14 @@ export const createPost = async (req, res) => {
}
export const getPostById = async (req, res) => {
const { id } = req.params;
try {
const post = await Post.findById(id);
return res.status(200).json(post);
} catch (error) {
return res.status(500).json({ message: "Something went wrong" });
}
}
export const deletePost = async (req, res) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment