From be7f957ca45cd4e85afe99c5acbc118fee29405b Mon Sep 17 00:00:00 2001 From: zetaloop Date: Sat, 25 Apr 2026 14:55:30 +0800 Subject: [PATCH] feat(api): add post creation client --- lib/api/index.ts | 2 +- lib/api/posts.ts | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/api/index.ts b/lib/api/index.ts index 91c5c20..c74877a 100644 --- a/lib/api/index.ts +++ b/lib/api/index.ts @@ -11,7 +11,7 @@ export { getGameById, listGames } from "./games" export { listNotifications, markNotificationAsRead } from "./notifications" export { getOrderById, listOrders, listOrdersByConsumer } from "./orders" export { getPlayerById, listPlayers, listPlayersByShop } from "./players" -export { getPostById, listPosts, listPostsByAuthor, togglePostLike } from "./posts" +export { createPost, getPostById, listPosts, listPostsByAuthor, togglePostLike } from "./posts" export { listReviews, listReviewsByOrder, listReviewsByTargetUser } from "./reviews" export { createPlayerService, diff --git a/lib/api/posts.ts b/lib/api/posts.ts index cd30bd5..55ecffc 100644 --- a/lib/api/posts.ts +++ b/lib/api/posts.ts @@ -17,6 +17,14 @@ type ListOptions = { limit?: number } +export type CreatePostInput = { + title: string + content: string + images: string[] + tags: string[] + linkedOrderId?: string +} + function withOffsetLimit(path: string, options?: ListOptions): string { const offset = options?.offset ?? 0 const limit = options?.limit ?? 100 @@ -51,6 +59,20 @@ export async function getPostById(postId: string): Promise { } } +export async function createPost(input: CreatePostInput): Promise { + return httpJson("/api/v1/posts", { + method: "POST", + cache: "no-store", + json: { + title: input.title, + content: input.content, + images: input.images, + tags: input.tags, + ...(input.linkedOrderId ? { linkedOrderId: input.linkedOrderId } : {}), + }, + }) +} + export async function listPostsByAuthor(userId: string, options?: ListOptions): Promise { const res = await httpJson>( withOffsetLimit(`/api/v1/users/${encodeURIComponent(userId)}/posts`, options),