Feat: Add endpoint for user profiles

This commit is contained in:
2025-10-03 07:47:28 -07:00
parent 49a94f5775
commit 7435c6713c

View File

@@ -0,0 +1,2 @@
const json=(d,o={})=>{const h=new Headers(o.headers);h.set('Content-Type','application/json');return new Response(JSON.stringify(d),{...o,headers:h})};
export async function onRequestGet({env,params}){try{const user=await env.D1_SPCHCAP.prepare('SELECT id,username,created_at FROM users WHERE username=?').bind(params.username).first();if(!user)return json({error:'User not found'},{status:404});const{results:comments}=await env.D1_SPCHCAP.prepare('SELECT c.id,c.content,c.created_at,p.id post_id,p.title post_title,s.name sub_name FROM comments c JOIN posts p ON c.post_id=p.id JOIN subs s ON p.sub_id=s.id WHERE c.user_id=? ORDER BY c.created_at DESC LIMIT 100').bind(user.id).all();return json({user,comments})}catch(e){return json({error:{message:e.message}},{status:500})}}