POST /posts
描述:创建一条帖子
请求头
Content-Type: application/json
请求体
{ "user_id": 1, "topic_id": 1, // 可选,必须是已存在 topic 的 ID "title": "帖子标题", "content": "正文内容", "media_urls": [ // 可选,字符串数组 "https://example.com/img1.jpg", "https://example.com/vid1.mp4" ], "status": "published" // draft|pending|published|deleted|rejected }
成功响应
状态:201 Created
Body
{ "id": 42 }
错误
GET /posts
描述:拉取所有 status=published
的帖子
响应
状态:200 OK
Body
[ { "id": 42, "title": "帖子标题", "heat": 5, "created_at": "2025-06-12T16:00:00" }, ... ]
GET /posts/{post_id}
描述:查看单条帖子完整信息
路径参数
参数 | 描述 |
---|---|
post_id | 帖子 ID |
响应
状态:200 OK
Body
{ "id": 42, "user_id": 1, "topic_id": 1, "title": "帖子标题", "content": "正文内容", "media_urls": ["…"], "status": "published", "heat": 5, "created_at": "2025-06-12T16:00:00", "updated_at": "2025-06-12T16:05:00" }
错误
PUT /posts/{post_id}
描述:更新帖子字段
路径参数
参数 | 描述 |
---|---|
post_id | 帖子 ID |
请求头
Content-Type: application/json
请求体(所有字段可选,依需更新)
{ "title": "新标题", "content": "新内容", "topic_id": 2, "media_urls": ["…"], "status": "draft" }
响应
错误
DELETE /posts/{post_id}
描述:删除帖子及其关联行为、评论
路径参数
参数 | 描述 |
---|---|
post_id | 帖子 ID |
响应
错误
支持四种操作:
like
、favorite
、view
、share
。其中like
和favorite
限制每人每帖最多一次,可撤销;view
/share
不限次数,不提供撤销。
POST /posts/{post_id}/like
描述:用户点赞,热度 +1
请求头
Content-Type: application/json
请求体
{ "user_id": 1 }
响应
错误
{"error":"already liked"}
DELETE /posts/{post_id}/like
描述:撤销点赞,热度 -1(底线 0)
请求头
Content-Type: application/json
请求体
{ "user_id": 1 }
响应
错误
{"error":"not liked yet"}
POST /posts/{post_id}/favorite
like
换成 favorite
,错误信息为 already favorited
/ not favorited yet
。DELETE /posts/{post_id}/favorite
POST /posts/{post_id}/view
描述:记录一次浏览,热度 +1
请求体
{ "user_id": 1 }
响应
不支持撤销;不做去重检查。
POST /posts/{post_id}/share
POST /posts/{post_id}/comments
描述:为帖子添加评论或回复
请求头
Content-Type: application/json
请求体
{ "user_id": 2, "content": "这是评论内容", "parent_id": 1 // 可选:回复某条评论时填,一级评论则省略 }
响应
状态:201 Created
Body
{ "id": 7 }
错误
GET /posts/{post_id}/comments
描述:拉取该帖所有一级评论及其完整回复树
响应
状态:200 OK
Body
[ { "id": 1, "user_id": 1, "content": "一级评论", "created_at": "…", "replies": [ { "id": 2, "user_id": 2, "content": "回复评论", "created_at": "…", "replies": [ … ] } ] }, … ]
错误
通用错误响应格式
{ "error": "描述信息" }