feat: 实现内容管理API及相关功能

refactor(services-section): 重构服务展示组件使用API数据
refactor(news-section): 重构新闻展示组件使用API数据
refactor(products-section): 重构产品展示组件使用API数据

test: 添加API客户端和服务钩子的单元测试
test(e2e): 添加配置验证和API响应格式的端到端测试

ci: 更新Playwright测试配置
This commit is contained in:
张翔
2026-03-13 18:55:25 +08:00
parent 72745456d2
commit ac2672729f
20 changed files with 3934 additions and 153 deletions
+54
View File
@@ -0,0 +1,54 @@
import { NextRequest } from 'next/server';
import { db } from '@/db';
import { content } from '@/db/schema';
import { eq, desc, and, like } from 'drizzle-orm';
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const type = searchParams.get('type');
const status = searchParams.get('status') || 'published';
const search = searchParams.get('search');
const page = parseInt(searchParams.get('page') || '1');
const limit = parseInt(searchParams.get('limit') || '100');
const offset = (page - 1) * limit;
const conditions = [];
if (type) {
conditions.push(eq(content.type, type as 'news' | 'product' | 'service' | 'case'));
}
if (status) {
conditions.push(eq(content.status, status as 'draft' | 'published' | 'archived'));
}
if (search) {
conditions.push(like(content.title, `%${search}%`));
}
const whereClause = conditions.length > 0 ? and(...conditions) : undefined;
const items = await db
.select()
.from(content)
.where(whereClause)
.orderBy(desc(content.publishedAt), desc(content.createdAt))
.limit(limit)
.offset(offset);
return Response.json({
success: true,
data: items,
});
} catch (error) {
console.error('Failed to fetch content:', error);
return Response.json(
{
success: false,
error: 'Failed to fetch content',
},
{ status: 500 }
);
}
}