get all posts
This commit is contained in:
parent
b7966be9ea
commit
5bcd23b3d3
|
|
@ -1,9 +1,16 @@
|
|||
import { Router } from 'express';
|
||||
import { Post } from '@prisma/client';
|
||||
import { getAllPosts } from '@/controller/PostController';
|
||||
|
||||
const posts = Router();
|
||||
|
||||
posts.get('/', (req, res) => {
|
||||
res.send('Hello World!');
|
||||
posts.get('/', async (req, res) => {
|
||||
try {
|
||||
const postList: Post[] = await getAllPosts();
|
||||
return res.status(200).send(postList);
|
||||
} catch (error) {
|
||||
res.status(500).send(error);
|
||||
}
|
||||
});
|
||||
|
||||
export default posts;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
const getAllPosts = () => prisma.post.findMany();
|
||||
|
||||
export { getAllPosts };
|
||||
Loading…
Reference in New Issue