feat(api): add post creation client

This commit is contained in:
zetaloop
2026-04-25 14:55:30 +08:00
parent 65db255e20
commit be7f957ca4
2 changed files with 23 additions and 1 deletions
+1 -1
View File
@@ -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,
+22
View File
@@ -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<Post | undefined> {
}
}
export async function createPost(input: CreatePostInput): Promise<Post> {
return httpJson<Post>("/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<Post[]> {
const res = await httpJson<Paginated<Post>>(
withOffsetLimit(`/api/v1/users/${encodeURIComponent(userId)}/posts`, options),