My personal site. theclashfruit.me
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: user, posts, comments get routes

+111 -1
+1 -1
app/(main)/links/page.tsx
··· 106 106 ))} 107 107 </div> 108 108 109 - <p>The 88x31 buttons are the property of their respective owners, check their websites out!</p> 109 + <p>Check out these cool people!</p> 110 110 </> 111 111 ); 112 112 }
+35
app/api/v1/post/[slug]/comment/route.ts
··· 1 + import { db } from '@/lib/db/drizzle'; 2 + import { commentsTable, postsTable } from '@/lib/db/schema'; 3 + import { eq } from 'drizzle-orm'; 4 + import { NextRequest } from 'next/server'; 5 + 6 + export async function GET( 7 + req: NextRequest, 8 + ctx: RouteContext<'/api/v1/post/[slug]'> 9 + ) { 10 + const { slug } = await ctx.params; 11 + 12 + const post = await db 13 + .select() 14 + .from(postsTable) 15 + .where(eq(postsTable.slug, slug)) 16 + .limit(1); 17 + 18 + if (post.length < 1) 19 + return Response.json( 20 + { 21 + error: 404, 22 + message: `Post with slug \`${slug}\` not found.` 23 + }, 24 + { 25 + status: 404 26 + } 27 + ); 28 + 29 + const comments = await db 30 + .select() 31 + .from(commentsTable) 32 + .where(eq(commentsTable.post, post[0].id)); 33 + 34 + return Response.json(comments); 35 + }
+30
app/api/v1/post/[slug]/route.ts
··· 1 + import { db } from '@/lib/db/drizzle'; 2 + import { postsTable } from '@/lib/db/schema'; 3 + import { eq } from 'drizzle-orm'; 4 + import { NextRequest } from 'next/server'; 5 + 6 + export async function GET( 7 + req: NextRequest, 8 + ctx: RouteContext<'/api/v1/post/[slug]'> 9 + ) { 10 + const { slug } = await ctx.params; 11 + 12 + const post = await db 13 + .select() 14 + .from(postsTable) 15 + .where(eq(postsTable.slug, slug)) 16 + .limit(1); 17 + 18 + if (post.length < 1) 19 + return Response.json( 20 + { 21 + error: 404, 22 + message: `Post with slug \`${slug}\` not found.` 23 + }, 24 + { 25 + status: 404 26 + } 27 + ); 28 + 29 + return Response.json(post[0]); 30 + }
+45
app/api/v1/user/[id]/route.ts
··· 1 + import { db } from '@/lib/db/drizzle'; 2 + import { usersTable } from '@/lib/db/schema'; 3 + import { eq, getTableColumns } from 'drizzle-orm'; 4 + import { NextRequest } from 'next/server'; 5 + 6 + export async function GET( 7 + req: NextRequest, 8 + ctx: RouteContext<'/api/v1/user/[id]'> 9 + ) { 10 + const { id } = await ctx.params; 11 + 12 + try { 13 + BigInt(id); 14 + } catch (e: unknown) { 15 + return Response.json( 16 + { 17 + error: 400, 18 + message: `\`id\` was not a BigInt.` 19 + }, 20 + { 21 + status: 400 22 + } 23 + ); 24 + } 25 + 26 + const { password, email, ...rest } = getTableColumns(usersTable); 27 + const user = await db 28 + .select({ ...rest }) 29 + .from(usersTable) 30 + .where(eq(usersTable.id, BigInt(id))) 31 + .limit(1); 32 + 33 + if (user.length < 1) 34 + return Response.json( 35 + { 36 + error: 404, 37 + message: `User with id \`${id}\` not found.` 38 + }, 39 + { 40 + status: 404 41 + } 42 + ); 43 + 44 + return Response.json(user[0]); 45 + }