feat: 添加获取季度列表 API

This commit is contained in:
2026-01-27 19:34:58 +08:00
parent 7c9f7ad018
commit 1c248a18fa
@@ -0,0 +1,47 @@
import { NextResponse } from 'next/server';
import { getAllQuarters } from '@/hooks/useKeywordCloud';
export const dynamic = 'force-dynamic';
/**
* GET /api/keyword-cloud/quarters
* 获取季度列表
*/
export async function GET(request: Request) {
try {
const { searchParams } = new URL(request.url);
const isActive = searchParams.get('isActive');
const quarters = await getAllQuarters(
isActive !== null ? { isActive: isActive === 'true' } : undefined
);
// 为每个季度添加关键词计数
const { prisma } = await import('@/lib/prisma');
const quartersWithCount = await Promise.all(
quarters.map(async (q) => {
const count = await prisma.keyword.count({
where: { quarterId: q.id },
});
return {
...q,
keywordCount: count,
};
})
);
return NextResponse.json({
success: true,
quarters: quartersWithCount,
});
} catch (error) {
console.error('Error fetching quarters:', error);
return NextResponse.json(
{
success: false,
error: 'Failed to fetch quarters',
},
{ status: 500 }
);
}
}