mirror of
https://github.com/spchcap/speech.capital.git
synced 2026-01-13 16:18:06 +00:00
Feat: Add endpoint for user profiles
This commit is contained in:
2
functions/api/users/[username].js
Normal file
2
functions/api/users/[username].js
Normal 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})}}
|
||||
Reference in New Issue
Block a user