diff --git a/src/api/client.ts b/src/api/client.ts index c67bb56..c899780 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -18,6 +18,8 @@ export type ModelSummary = { authorName?: string createdAt?: string updatedAt?: string + avgRating?: number | null + ratingCount?: number } export type ModelDetail = ModelSummary & { @@ -25,6 +27,15 @@ export type ModelDetail = ModelSummary & { desc: string } +export type CommentItem = { + id: string + content: string + authorId: string + authorName?: string + createdAt: string + updatedAt?: string +} + export type ListModelsQuery = { q?: string authorId?: string @@ -135,6 +146,44 @@ export const api = { previewUrl(id: string) { return `${API_BASE}/models/${encodeURIComponent(id)}/preview` }, + + // Ratings + async setRating(id: string, value: number, basicToken?: string) { + const res = await fetch(`${API_BASE}/models/${encodeURIComponent(id)}/rating`, { + method: 'POST', + headers: { 'content-type': 'application/json', ...buildAuthHeader(basicToken) }, + body: JSON.stringify({ value }) + }) + return handle<{ id: string; value: number }>(res) + }, + async getMyRating(id: string, basicToken?: string) { + const res = await fetch(`${API_BASE}/models/${encodeURIComponent(id)}/my-rating`, { + headers: { ...buildAuthHeader(basicToken) } + }) + return handle<{ myRating: number | null }>(res) + }, + + // Comments + async listComments(id: string, page = 1, pageSize = 20) { + const usp = new URLSearchParams({ page: String(page), pageSize: String(pageSize) }) + const res = await fetch(`${API_BASE}/models/${encodeURIComponent(id)}/comments?${usp}`) + return handle<{ items: CommentItem[]; total: number; page: number; pageSize: number }>(res) + }, + async addComment(id: string, content: string, basicToken?: string) { + const res = await fetch(`${API_BASE}/models/${encodeURIComponent(id)}/comments`, { + method: 'POST', + headers: { 'content-type': 'application/json', ...buildAuthHeader(basicToken) }, + body: JSON.stringify({ content }) + }) + return handle<{ id: string }>(res) + }, + async deleteComment(id: string, commentId: string, basicToken?: string) { + const res = await fetch(`${API_BASE}/models/${encodeURIComponent(id)}/comments/${encodeURIComponent(commentId)}`, { + method: 'DELETE', + headers: { ...buildAuthHeader(basicToken) } + }) + return handle(res) + }, } export type BasicCredential = { username: string; password: string } diff --git a/src/views/ModelDetail.vue b/src/views/ModelDetail.vue index 19c5d6d..a9d9d08 100644 --- a/src/views/ModelDetail.vue +++ b/src/views/ModelDetail.vue @@ -1,10 +1,10 @@