From 198530a475dd81dcebc5a524a09ae3cd5049419c Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sat, 8 Nov 2025 01:33:05 +0000 Subject: [PATCH] Creator API client for frontend cgen-528cee3da0d54ede8ff0b6e11d55e101 --- client/api/creators.ts | 164 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 client/api/creators.ts diff --git a/client/api/creators.ts b/client/api/creators.ts new file mode 100644 index 00000000..9eadccef --- /dev/null +++ b/client/api/creators.ts @@ -0,0 +1,164 @@ +export interface Creator { + id: string; + username: string; + bio: string; + skills: string[]; + avatar_url: string; + experience_level: string; + arm_affiliations: string[]; + primary_arm: string; + created_at: string; + is_discoverable: boolean; + allow_recommendations: boolean; + devconnect_linked: boolean; + aethex_projects?: Project[]; + aethex_skill_endorsements?: SkillEndorsement[]; + devconnect_link?: DevConnectLink; +} + +export interface Project { + id: string; + creator_id: string; + title: string; + description: string; + url: string; + image_url: string; + tags: string[]; + is_featured: boolean; + created_at: string; +} + +export interface SkillEndorsement { + skill: string; + count: number; +} + +export interface DevConnectLink { + id: string; + devconnect_username: string; + devconnect_profile_url: string; + verified: boolean; +} + +export interface CreatorsResponse { + data: Creator[]; + pagination: { + page: number; + limit: number; + total: number; + pages: number; + }; +} + +const API_BASE = process.env.VITE_API_BASE || ""; + +export async function getCreators(filters?: { + arm?: string; + search?: string; + page?: number; + limit?: number; +}): Promise { + const params = new URLSearchParams(); + if (filters?.arm) params.append("arm", filters.arm); + if (filters?.search) params.append("search", filters.search); + if (filters?.page) params.append("page", String(filters.page)); + if (filters?.limit) params.append("limit", String(filters.limit)); + + const response = await fetch(`${API_BASE}/api/creators?${params}`); + if (!response.ok) throw new Error("Failed to fetch creators"); + return response.json(); +} + +export async function getCreatorByUsername(username: string): Promise { + const response = await fetch(`${API_BASE}/api/creators/${username}`); + if (!response.ok) throw new Error("Creator not found"); + return response.json(); +} + +export async function createCreatorProfile(data: { + username: string; + bio: string; + skills: string[]; + avatar_url: string; + experience_level: string; + primary_arm: string; + arm_affiliations: string[]; +}): Promise { + const response = await fetch(`${API_BASE}/api/creators`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(data), + }); + if (!response.ok) throw new Error("Failed to create creator profile"); + return response.json(); +} + +export async function updateCreatorProfile(data: { + username?: string; + bio?: string; + skills?: string[]; + avatar_url?: string; + experience_level?: string; + primary_arm?: string; + arm_affiliations?: string[]; + is_discoverable?: boolean; + allow_recommendations?: boolean; +}): Promise { + const response = await fetch(`${API_BASE}/api/creators/me`, { + method: "PUT", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(data), + }); + if (!response.ok) throw new Error("Failed to update creator profile"); + return response.json(); +} + +export async function addProject(data: { + title: string; + description: string; + url: string; + image_url: string; + tags: string[]; + is_featured?: boolean; +}): Promise { + const response = await fetch(`${API_BASE}/api/creators/me/projects`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(data), + }); + if (!response.ok) throw new Error("Failed to add project"); + return response.json(); +} + +export async function updateProject(projectId: string, data: { + title?: string; + description?: string; + url?: string; + image_url?: string; + tags?: string[]; + is_featured?: boolean; +}): Promise { + const response = await fetch(`${API_BASE}/api/creators/me/projects/${projectId}`, { + method: "PUT", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(data), + }); + if (!response.ok) throw new Error("Failed to update project"); + return response.json(); +} + +export async function deleteProject(projectId: string): Promise { + const response = await fetch(`${API_BASE}/api/creators/me/projects/${projectId}`, { + method: "DELETE", + }); + if (!response.ok) throw new Error("Failed to delete project"); +} + +export async function endorseSkill(creatorId: string, skill: string): Promise { + const response = await fetch(`${API_BASE}/api/creators/${creatorId}/endorse`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ skill }), + }); + if (!response.ok) throw new Error("Failed to endorse skill"); +}