feat: Day 8-9 - Project Management API completed
Backend: - Create project routes (GET, POST, PUT, DELETE) - Implement projectController with CRUD operations - Create projectService for database operations - Add validation middleware for request validation - Update Prisma schema (add background, researchType, deletedAt fields) - Implement soft delete for projects Frontend: - Create projectApi service module - Update useProjectStore with fetchProjects and loading state - Connect ProjectSelector to real API with loading indicator - Connect CreateProjectDialog to real API with error handling - Connect EditProjectDialog to real API with loading state - Add comprehensive error handling and user feedback Build: Both frontend and backend build successfully
This commit is contained in:
57
frontend/src/api/projectApi.ts
Normal file
57
frontend/src/api/projectApi.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import request from './request';
|
||||
import type { Project } from '../stores/useProjectStore';
|
||||
|
||||
export interface ApiResponse<T = any> {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
message?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface CreateProjectRequest {
|
||||
name: string;
|
||||
background: string;
|
||||
researchType: 'observational' | 'interventional';
|
||||
}
|
||||
|
||||
export interface UpdateProjectRequest {
|
||||
name?: string;
|
||||
background?: string;
|
||||
researchType?: 'observational' | 'interventional';
|
||||
}
|
||||
|
||||
export const projectApi = {
|
||||
// 获取项目列表
|
||||
getProjects: async (): Promise<ApiResponse<Project[]>> => {
|
||||
const response = await request.get('/projects');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// 获取单个项目详情
|
||||
getProjectById: async (id: string): Promise<ApiResponse<Project>> => {
|
||||
const response = await request.get(`/projects/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// 创建项目
|
||||
createProject: async (data: CreateProjectRequest): Promise<ApiResponse<Project>> => {
|
||||
const response = await request.post('/projects', data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// 更新项目
|
||||
updateProject: async (
|
||||
id: string,
|
||||
data: UpdateProjectRequest
|
||||
): Promise<ApiResponse<Project>> => {
|
||||
const response = await request.put(`/projects/${id}`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// 删除项目
|
||||
deleteProject: async (id: string): Promise<ApiResponse> => {
|
||||
const response = await request.delete(`/projects/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user