route.ts

route.ts

基本信息

  • 类型: API 路由
  • 路径: ./src/app/api/admin/prompts/route.ts
  • 路由: /api/admin/prompts

概述

管理员 Prompt 管理接口。支持分页获取 Prompt 列表,支持搜索、筛选和排序。

HTTP 方法

  • GET: 获取 Prompt 列表

GET - 获取 Prompt 列表

Query 参数

参数类型必填说明
pagenumber页码,默认 1
limitnumber每页数量,默认 20,最大 100
searchstring搜索关键词(标题或内容)
sortBystring排序字段: createdAt, updatedAt, title, viewCount
sortOrderstring排序方向: asc, desc,默认 desc
filterstring筛选条件

筛选选项

筛选值说明
all全部(默认)
unlisted已下架
private私有
featured精选
deleted已删除
reported被举报
public公开的

响应

成功 (200)

{
  "prompts": [
    {
      "id": "prompt_id",
      "title": "Prompt 标题",
      "slug": "prompt-title",
      "type": "TEXT",
      "isPrivate": false,
      "isUnlisted": false,
      "isFeatured": true,
      "viewCount": 100,
      "createdAt": "2024-01-01T00:00:00Z",
      "updatedAt": "2024-01-01T00:00:00Z",
      "deletedAt": null,
      "author": {
        "id": "user_id",
        "username": "username",
        "name": "用户名称",
        "avatar": "https://..."
      },
      "category": {
        "id": "cat_id",
        "name": "分类名称",
        "slug": "category-slug"
      },
      "_count": {
        "votes": 50,
        "reports": 0
      }
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 100,
    "totalPages": 5
  }
}

错误

未授权 (401)
{
  "error": "unauthorized",
  "message": "Authentication required"
}
无权限 (403)
{
  "error": "forbidden",
  "message": "Admin access required"
}
服务器错误 (500)
{
  "error": "server_error",
  "message": "Failed to fetch prompts"
}

依赖

  • next/server - Next.js 服务器组件
  • @/lib/auth - 认证
  • @/lib/db - Prisma 数据库客户端

权限

  • 需要管理员角色 (role === "ADMIN")

返回字段说明

  • isPrivate: 是否为私有 Prompt
  • isUnlisted: 是否已下架
  • isFeatured: 是否为精选 Prompt
  • deletedAt: 软删除时间戳
  • _count.votes: 投票数
  • _count.reports: 被举报次数
← 返回目录