feat: 更新项目 API 客户端对接真实后端
- 实现 listProjects getProject createProject 等真实 API 调用 - 移除 mock 实现,直接调用后端接口
This commit is contained in:
+25
-29
@@ -1,64 +1,60 @@
|
|||||||
import type { Project, Task } from './types'
|
import type { Project, Task } from './types'
|
||||||
import {
|
import { get, post, put, del } from './client'
|
||||||
mockListProjects,
|
|
||||||
mockGetProject,
|
|
||||||
mockCreateProject,
|
|
||||||
mockDeleteProject,
|
|
||||||
mockUpdateProject,
|
|
||||||
mockGetStyle,
|
|
||||||
mockSaveStyle,
|
|
||||||
mockGetTasks,
|
|
||||||
} from './mock'
|
|
||||||
|
|
||||||
const USE_MOCK = true
|
export async function listProjects(
|
||||||
|
page?: number,
|
||||||
|
pageSize?: number
|
||||||
|
): Promise<Project[]> {
|
||||||
|
const params = new URLSearchParams()
|
||||||
|
if (page !== undefined) params.set('page', String(page))
|
||||||
|
if (pageSize !== undefined) params.set('pageSize', String(pageSize))
|
||||||
|
|
||||||
export async function listProjects(): Promise<Project[]> {
|
const url = `/api/v1/projects${params.toString() ? '?' + params : ''}`
|
||||||
if (USE_MOCK) return mockListProjects()
|
const resp = await get<{
|
||||||
throw new Error('Not implemented')
|
total: number
|
||||||
|
projects: Project[]
|
||||||
|
}>(url)
|
||||||
|
return resp.projects
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getProject(projectId: string): Promise<Project> {
|
export async function getProject(projectId: string): Promise<Project> {
|
||||||
if (USE_MOCK) return mockGetProject(projectId)
|
return get<Project>(`/api/v1/projects/${projectId}`)
|
||||||
throw new Error('Not implemented')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createProject(
|
export async function createProject(
|
||||||
name: string,
|
name: string,
|
||||||
style?: Record<string, string>
|
style?: Record<string, string>
|
||||||
): Promise<Project> {
|
): Promise<Project> {
|
||||||
if (USE_MOCK) return mockCreateProject(name, style)
|
return post<Project>('/api/v1/projects', { name, style })
|
||||||
throw new Error('Not implemented')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteProject(projectId: string): Promise<void> {
|
export async function deleteProject(projectId: string): Promise<void> {
|
||||||
if (USE_MOCK) return mockDeleteProject(projectId)
|
return del<void>(`/api/v1/projects/${projectId}`)
|
||||||
throw new Error('Not implemented')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateProject(
|
export async function updateProject(
|
||||||
projectId: string,
|
projectId: string,
|
||||||
data: { name?: string }
|
data: { name: string }
|
||||||
): Promise<Project> {
|
): Promise<Project> {
|
||||||
if (USE_MOCK) return mockUpdateProject(projectId, data)
|
return put<Project>(`/api/v1/projects/${projectId}`, data)
|
||||||
throw new Error('Not implemented')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getStyle(
|
export async function getStyle(
|
||||||
projectId: string
|
projectId: string
|
||||||
): Promise<Record<string, string>> {
|
): Promise<Record<string, string>> {
|
||||||
if (USE_MOCK) return mockGetStyle(projectId)
|
const resp = await get<{ kvPairs: Record<string, string> }>(
|
||||||
throw new Error('Not implemented')
|
`/api/v1/projects/${projectId}/style`
|
||||||
|
)
|
||||||
|
return resp.kvPairs
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveStyle(
|
export async function saveStyle(
|
||||||
projectId: string,
|
projectId: string,
|
||||||
kvPairs: Record<string, string>
|
kvPairs: Record<string, string>
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (USE_MOCK) return mockSaveStyle(projectId, kvPairs)
|
return put<void>(`/api/v1/projects/${projectId}/style`, { kvPairs })
|
||||||
throw new Error('Not implemented')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getTasks(projectId: string): Promise<Task[]> {
|
export async function getTasks(projectId: string): Promise<Task[]> {
|
||||||
if (USE_MOCK) return mockGetTasks(projectId)
|
return get<Task[]>(`/api/v1/projects/${projectId}/tasks`)
|
||||||
throw new Error('Not implemented')
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user