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:
53
backend/src/routes/projects.ts
Normal file
53
backend/src/routes/projects.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
|
||||
import { projectController } from '../controllers/projectController.js';
|
||||
import { validateProjectCreate, validateProjectUpdate } from '../middleware/validateProject.js';
|
||||
|
||||
interface ProjectParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export async function projectRoutes(fastify: FastifyInstance) {
|
||||
// 获取项目列表
|
||||
fastify.get('/projects', async (request: FastifyRequest, reply: FastifyReply) => {
|
||||
return projectController.getProjects(request, reply);
|
||||
});
|
||||
|
||||
// 获取单个项目详情
|
||||
fastify.get<{ Params: ProjectParams }>(
|
||||
'/projects/:id',
|
||||
async (request: FastifyRequest<{ Params: ProjectParams }>, reply: FastifyReply) => {
|
||||
return projectController.getProjectById(request, reply);
|
||||
}
|
||||
);
|
||||
|
||||
// 创建项目
|
||||
fastify.post(
|
||||
'/projects',
|
||||
{
|
||||
preHandler: validateProjectCreate,
|
||||
},
|
||||
async (request: FastifyRequest, reply: FastifyReply) => {
|
||||
return projectController.createProject(request, reply);
|
||||
}
|
||||
);
|
||||
|
||||
// 更新项目
|
||||
fastify.put<{ Params: ProjectParams }>(
|
||||
'/projects/:id',
|
||||
{
|
||||
preHandler: validateProjectUpdate,
|
||||
},
|
||||
async (request: FastifyRequest<{ Params: ProjectParams }>, reply: FastifyReply) => {
|
||||
return projectController.updateProject(request, reply);
|
||||
}
|
||||
);
|
||||
|
||||
// 删除项目
|
||||
fastify.delete<{ Params: ProjectParams }>(
|
||||
'/projects/:id',
|
||||
async (request: FastifyRequest<{ Params: ProjectParams }>, reply: FastifyReply) => {
|
||||
return projectController.deleteProject(request, reply);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user