Update application code and dependencies
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { NextRequest, NextResponse } from "next/server"
|
||||
import { prisma } from "@//app/lib/prisma"
|
||||
|
||||
// 更新智能体
|
||||
export async function PUT(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const data = await request.json()
|
||||
const agent = await prisma.agent.update({
|
||||
where: { id: parseInt(id) },
|
||||
data: {
|
||||
name: data.name,
|
||||
slug: data.slug,
|
||||
description: data.description,
|
||||
icon: data.icon || null,
|
||||
categoryId: data.categoryId ? parseInt(data.categoryId) : null,
|
||||
features: data.features || "",
|
||||
status: data.status || "active",
|
||||
},
|
||||
})
|
||||
return NextResponse.json(agent)
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: "更新失败" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// 删除智能体
|
||||
export async function DELETE(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params
|
||||
await prisma.agent.delete({
|
||||
where: { id: parseInt(id) },
|
||||
})
|
||||
return NextResponse.json({ success: true })
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: "删除失败" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { NextRequest, NextResponse } from "next/server"
|
||||
import { prisma } from "@//app/lib/prisma"
|
||||
|
||||
// 创建智能体
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const data = await request.json()
|
||||
const agent = await prisma.agent.create({
|
||||
data: {
|
||||
name: data.name,
|
||||
slug: data.slug,
|
||||
description: data.description,
|
||||
icon: data.icon || null,
|
||||
categoryId: data.categoryId ? parseInt(data.categoryId) : null,
|
||||
features: data.features || "",
|
||||
status: data.status || "active",
|
||||
},
|
||||
})
|
||||
return NextResponse.json(agent)
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: "创建失败" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// 获取所有智能体
|
||||
export async function GET() {
|
||||
try {
|
||||
const agents = await prisma.agent.findMany({
|
||||
include: { category: true },
|
||||
})
|
||||
return NextResponse.json(agents)
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: "获取失败" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user