From 52fffed4090dc5a606c52e38365ddcc45a18e937 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sat, 18 Oct 2025 04:39:07 +0000 Subject: [PATCH] Extend communityService with like/unlike/comment methods (replace getUserPosts block) cgen-3e11fed29a164599bed0547c61a91742 --- client/lib/supabase-service.ts | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/client/lib/supabase-service.ts b/client/lib/supabase-service.ts index f728f840..d0910077 100644 --- a/client/lib/supabase-service.ts +++ b/client/lib/supabase-service.ts @@ -306,6 +306,56 @@ export const communityService = { return (Array.isArray(data) ? data : []) as CommunityPost[]; }, + + async likePost(postId: string, userId: string): Promise { + try { + const resp = await fetch(`/api/community/posts/${encodeURIComponent(postId)}/like`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ user_id: userId }), + }); + if (resp.ok) { + const json = await resp.json(); + return typeof json?.likes === "number" ? json.likes : null; + } + } catch {} + return null; + }, + + async unlikePost(postId: string, userId: string): Promise { + try { + const resp = await fetch(`/api/community/posts/${encodeURIComponent(postId)}/unlike`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ user_id: userId }), + }); + if (resp.ok) { + const json = await resp.json(); + return typeof json?.likes === "number" ? json.likes : null; + } + } catch {} + return null; + }, + + async listComments(postId: string): Promise { + try { + const resp = await fetch(`/api/community/posts/${encodeURIComponent(postId)}/comments`); + if (!resp.ok) return []; + return await resp.json(); + } catch { + return []; + } + }, + + async addComment(postId: string, userId: string, content: string): Promise { + const resp = await fetch(`/api/community/posts/${encodeURIComponent(postId)}/comments`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ user_id: userId, content }), + }); + if (!resp.ok) return null; + return await resp.json(); + }, }; // Notification Services