Skip to content

Commit

Permalink
feat:Add GET and POST endpoints for user posts
Browse files Browse the repository at this point in the history
  • Loading branch information
aseelkp committed Oct 4, 2023
1 parent f36ad33 commit 44d17a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 10 additions & 2 deletions controllers/posts.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PostMessage from "../models/postMessage.js";

export const getPosts = async (req,res) => {
try{
Expand All @@ -9,6 +10,13 @@ export const getPosts = async (req,res) => {
}
}

export const createPost = (req,res) => {
res.send('Post Creation')
export const createPost = async (req,res) => {
const post = req.body;
const newPost = new PostMessage(post);
try {
await newPost.save();
res.status(201).json(newPost)
} catch (error) {
res.status(409).json({message: error.message})
}
}
7 changes: 4 additions & 3 deletions routes/posts.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import express from "express";
import { createPost, getPosts } from "../controllers/posts";
import { createPost, getPosts } from "../controllers/posts.js";

const router = express.Router();

router.get('/' , getPosts )
router.post('/create' , createPost )
router.get('/' , getPosts)
router.post('/create' , createPost)

export default router;

0 comments on commit 44d17a0

Please sign in to comment.