diff --git a/docs/swagger/docs.go b/docs/swagger/docs.go index 562b7be..6b9e5bc 100644 --- a/docs/swagger/docs.go +++ b/docs/swagger/docs.go @@ -215,7 +215,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "文章分类管理" + "文章分类-管理端" ], "summary": "创建分类", "parameters": [ @@ -276,7 +276,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "文章分类管理" + "文章分类-管理端" ], "summary": "更新分类", "parameters": [ @@ -349,7 +349,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "文章分类管理" + "文章分类-管理端" ], "summary": "删除分类", "parameters": [ @@ -415,7 +415,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "文章标签管理" + "文章标签-管理端" ], "summary": "创建标签", "parameters": [ @@ -476,7 +476,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "文章标签管理" + "文章标签-管理端" ], "summary": "更新标签", "parameters": [ @@ -549,7 +549,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "文章标签管理" + "文章标签-管理端" ], "summary": "删除标签", "parameters": [ @@ -600,6 +600,67 @@ const docTemplate = `{ } } }, + "/api/v1/admin/articles": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "创建新的文章", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "文章管理-管理端" + ], + "summary": "创建文章", + "parameters": [ + { + "description": "创建文章请求", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/commands.CreateArticleCommand" + } + } + ], + "responses": { + "201": { + "description": "文章创建成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "未认证", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, "/api/v1/admin/articles/stats": { "get": { "security": [ @@ -615,7 +676,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "文章管理" + "文章管理-管理端" ], "summary": "获取文章统计", "responses": { @@ -642,6 +703,352 @@ const docTemplate = `{ } } }, + "/api/v1/admin/articles/{id}": { + "put": { + "security": [ + { + "Bearer": [] + } + ], + "description": "更新文章信息", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "文章管理-管理端" + ], + "summary": "更新文章", + "parameters": [ + { + "type": "string", + "description": "文章ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "更新文章请求", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/commands.UpdateArticleCommand" + } + } + ], + "responses": { + "200": { + "description": "文章更新成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "未认证", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "文章不存在", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "删除指定文章", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "文章管理-管理端" + ], + "summary": "删除文章", + "parameters": [ + { + "type": "string", + "description": "文章ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "文章删除成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "未认证", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "文章不存在", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/api/v1/admin/articles/{id}/archive": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "将已发布文章归档", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "文章管理-管理端" + ], + "summary": "归档文章", + "parameters": [ + { + "type": "string", + "description": "文章ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "文章归档成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "未认证", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "文章不存在", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/api/v1/admin/articles/{id}/featured": { + "put": { + "security": [ + { + "Bearer": [] + } + ], + "description": "设置文章的推荐状态", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "文章管理-管理端" + ], + "summary": "设置推荐状态", + "parameters": [ + { + "type": "string", + "description": "文章ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "设置推荐状态请求", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/commands.SetFeaturedCommand" + } + } + ], + "responses": { + "200": { + "description": "设置推荐状态成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "未认证", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "文章不存在", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/api/v1/admin/articles/{id}/publish": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "将草稿文章发布", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "文章管理-管理端" + ], + "summary": "发布文章", + "parameters": [ + { + "type": "string", + "description": "文章ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "文章发布成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "未认证", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "文章不存在", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, "/api/v1/admin/articles/{id}/schedule-publish": { "post": { "security": [ @@ -657,7 +1064,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "文章管理" + "文章管理-管理端" ], "summary": "定时发布文章", "parameters": [ @@ -3148,7 +3555,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "文章分类" + "文章分类-用户端" ], "summary": "获取分类列表", "responses": { @@ -3178,7 +3585,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "文章分类" + "文章分类-用户端" ], "summary": "获取分类详情", "parameters": [ @@ -3231,7 +3638,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "文章标签" + "文章标签-用户端" ], "summary": "获取标签列表", "responses": { @@ -3261,7 +3668,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "文章标签" + "文章标签-用户端" ], "summary": "获取标签详情", "parameters": [ @@ -3314,7 +3721,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "文章管理" + "文章管理-用户端" ], "summary": "获取文章列表", "parameters": [ @@ -3403,74 +3810,10 @@ const docTemplate = `{ } } } - }, - "post": { - "security": [ - { - "Bearer": [] - } - ], - "description": "创建新的文章", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "文章管理" - ], - "summary": "创建文章", - "parameters": [ - { - "description": "创建文章请求", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/commands.CreateArticleCommand" - } - } - ], - "responses": { - "201": { - "description": "文章创建成功", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "400": { - "description": "请求参数错误", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "401": { - "description": "未认证", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "500": { - "description": "服务器内部错误", - "schema": { - "type": "object", - "additionalProperties": true - } - } - } } }, "/api/v1/articles/{id}": { "get": { - "security": [ - { - "Bearer": [] - } - ], "description": "根据ID获取文章详情", "consumes": [ "application/json" @@ -3479,7 +3822,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "文章管理" + "文章管理-用户端" ], "summary": "获取文章详情", "parameters": [ @@ -3505,357 +3848,6 @@ const docTemplate = `{ "additionalProperties": true } }, - "401": { - "description": "未认证", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "404": { - "description": "文章不存在", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "500": { - "description": "服务器内部错误", - "schema": { - "type": "object", - "additionalProperties": true - } - } - } - }, - "put": { - "security": [ - { - "Bearer": [] - } - ], - "description": "更新文章信息", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "文章管理" - ], - "summary": "更新文章", - "parameters": [ - { - "type": "string", - "description": "文章ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "更新文章请求", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/commands.UpdateArticleCommand" - } - } - ], - "responses": { - "200": { - "description": "文章更新成功", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "400": { - "description": "请求参数错误", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "401": { - "description": "未认证", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "404": { - "description": "文章不存在", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "500": { - "description": "服务器内部错误", - "schema": { - "type": "object", - "additionalProperties": true - } - } - } - }, - "delete": { - "security": [ - { - "Bearer": [] - } - ], - "description": "删除指定文章", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "文章管理" - ], - "summary": "删除文章", - "parameters": [ - { - "type": "string", - "description": "文章ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "文章删除成功", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "400": { - "description": "请求参数错误", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "401": { - "description": "未认证", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "404": { - "description": "文章不存在", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "500": { - "description": "服务器内部错误", - "schema": { - "type": "object", - "additionalProperties": true - } - } - } - } - }, - "/api/v1/articles/{id}/archive": { - "post": { - "security": [ - { - "Bearer": [] - } - ], - "description": "将已发布文章归档", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "文章管理" - ], - "summary": "归档文章", - "parameters": [ - { - "type": "string", - "description": "文章ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "文章归档成功", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "400": { - "description": "请求参数错误", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "401": { - "description": "未认证", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "404": { - "description": "文章不存在", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "500": { - "description": "服务器内部错误", - "schema": { - "type": "object", - "additionalProperties": true - } - } - } - } - }, - "/api/v1/articles/{id}/featured": { - "put": { - "security": [ - { - "Bearer": [] - } - ], - "description": "设置文章的推荐状态", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "文章管理" - ], - "summary": "设置推荐状态", - "parameters": [ - { - "type": "string", - "description": "文章ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "设置推荐状态请求", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/commands.SetFeaturedCommand" - } - } - ], - "responses": { - "200": { - "description": "设置推荐状态成功", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "400": { - "description": "请求参数错误", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "401": { - "description": "未认证", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "404": { - "description": "文章不存在", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "500": { - "description": "服务器内部错误", - "schema": { - "type": "object", - "additionalProperties": true - } - } - } - } - }, - "/api/v1/articles/{id}/publish": { - "post": { - "security": [ - { - "Bearer": [] - } - ], - "description": "将草稿文章发布", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "文章管理" - ], - "summary": "发布文章", - "parameters": [ - { - "type": "string", - "description": "文章ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "文章发布成功", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "400": { - "description": "请求参数错误", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "401": { - "description": "未认证", - "schema": { - "type": "object", - "additionalProperties": true - } - }, "404": { "description": "文章不存在", "schema": { @@ -8208,13 +8200,60 @@ const docTemplate = `{ } } }, + "responses.ArticleListItemResponse": { + "type": "object", + "properties": { + "category": { + "$ref": "#/definitions/tyapi-server_internal_application_article_dto_responses.CategoryInfoResponse" + }, + "category_id": { + "type": "string" + }, + "cover_image": { + "type": "string" + }, + "created_at": { + "type": "string" + }, + "id": { + "type": "string" + }, + "is_featured": { + "type": "boolean" + }, + "published_at": { + "type": "string" + }, + "status": { + "type": "string" + }, + "summary": { + "type": "string" + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/definitions/responses.TagInfoResponse" + } + }, + "title": { + "type": "string" + }, + "updated_at": { + "type": "string" + }, + "view_count": { + "type": "integer" + } + } + }, "responses.ArticleListResponse": { "type": "object", "properties": { "items": { "type": "array", "items": { - "$ref": "#/definitions/responses.ArticleInfoResponse" + "$ref": "#/definitions/responses.ArticleListItemResponse" } }, "page": { diff --git a/docs/swagger/swagger.json b/docs/swagger/swagger.json index 08be62b..37cc1c3 100644 --- a/docs/swagger/swagger.json +++ b/docs/swagger/swagger.json @@ -209,7 +209,7 @@ "application/json" ], "tags": [ - "文章分类管理" + "文章分类-管理端" ], "summary": "创建分类", "parameters": [ @@ -270,7 +270,7 @@ "application/json" ], "tags": [ - "文章分类管理" + "文章分类-管理端" ], "summary": "更新分类", "parameters": [ @@ -343,7 +343,7 @@ "application/json" ], "tags": [ - "文章分类管理" + "文章分类-管理端" ], "summary": "删除分类", "parameters": [ @@ -409,7 +409,7 @@ "application/json" ], "tags": [ - "文章标签管理" + "文章标签-管理端" ], "summary": "创建标签", "parameters": [ @@ -470,7 +470,7 @@ "application/json" ], "tags": [ - "文章标签管理" + "文章标签-管理端" ], "summary": "更新标签", "parameters": [ @@ -543,7 +543,7 @@ "application/json" ], "tags": [ - "文章标签管理" + "文章标签-管理端" ], "summary": "删除标签", "parameters": [ @@ -594,6 +594,67 @@ } } }, + "/api/v1/admin/articles": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "创建新的文章", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "文章管理-管理端" + ], + "summary": "创建文章", + "parameters": [ + { + "description": "创建文章请求", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/commands.CreateArticleCommand" + } + } + ], + "responses": { + "201": { + "description": "文章创建成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "未认证", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, "/api/v1/admin/articles/stats": { "get": { "security": [ @@ -609,7 +670,7 @@ "application/json" ], "tags": [ - "文章管理" + "文章管理-管理端" ], "summary": "获取文章统计", "responses": { @@ -636,6 +697,352 @@ } } }, + "/api/v1/admin/articles/{id}": { + "put": { + "security": [ + { + "Bearer": [] + } + ], + "description": "更新文章信息", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "文章管理-管理端" + ], + "summary": "更新文章", + "parameters": [ + { + "type": "string", + "description": "文章ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "更新文章请求", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/commands.UpdateArticleCommand" + } + } + ], + "responses": { + "200": { + "description": "文章更新成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "未认证", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "文章不存在", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "删除指定文章", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "文章管理-管理端" + ], + "summary": "删除文章", + "parameters": [ + { + "type": "string", + "description": "文章ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "文章删除成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "未认证", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "文章不存在", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/api/v1/admin/articles/{id}/archive": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "将已发布文章归档", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "文章管理-管理端" + ], + "summary": "归档文章", + "parameters": [ + { + "type": "string", + "description": "文章ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "文章归档成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "未认证", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "文章不存在", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/api/v1/admin/articles/{id}/featured": { + "put": { + "security": [ + { + "Bearer": [] + } + ], + "description": "设置文章的推荐状态", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "文章管理-管理端" + ], + "summary": "设置推荐状态", + "parameters": [ + { + "type": "string", + "description": "文章ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "设置推荐状态请求", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/commands.SetFeaturedCommand" + } + } + ], + "responses": { + "200": { + "description": "设置推荐状态成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "未认证", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "文章不存在", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/api/v1/admin/articles/{id}/publish": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "将草稿文章发布", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "文章管理-管理端" + ], + "summary": "发布文章", + "parameters": [ + { + "type": "string", + "description": "文章ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "文章发布成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "未认证", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "文章不存在", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "服务器内部错误", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, "/api/v1/admin/articles/{id}/schedule-publish": { "post": { "security": [ @@ -651,7 +1058,7 @@ "application/json" ], "tags": [ - "文章管理" + "文章管理-管理端" ], "summary": "定时发布文章", "parameters": [ @@ -3142,7 +3549,7 @@ "application/json" ], "tags": [ - "文章分类" + "文章分类-用户端" ], "summary": "获取分类列表", "responses": { @@ -3172,7 +3579,7 @@ "application/json" ], "tags": [ - "文章分类" + "文章分类-用户端" ], "summary": "获取分类详情", "parameters": [ @@ -3225,7 +3632,7 @@ "application/json" ], "tags": [ - "文章标签" + "文章标签-用户端" ], "summary": "获取标签列表", "responses": { @@ -3255,7 +3662,7 @@ "application/json" ], "tags": [ - "文章标签" + "文章标签-用户端" ], "summary": "获取标签详情", "parameters": [ @@ -3308,7 +3715,7 @@ "application/json" ], "tags": [ - "文章管理" + "文章管理-用户端" ], "summary": "获取文章列表", "parameters": [ @@ -3397,74 +3804,10 @@ } } } - }, - "post": { - "security": [ - { - "Bearer": [] - } - ], - "description": "创建新的文章", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "文章管理" - ], - "summary": "创建文章", - "parameters": [ - { - "description": "创建文章请求", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/commands.CreateArticleCommand" - } - } - ], - "responses": { - "201": { - "description": "文章创建成功", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "400": { - "description": "请求参数错误", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "401": { - "description": "未认证", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "500": { - "description": "服务器内部错误", - "schema": { - "type": "object", - "additionalProperties": true - } - } - } } }, "/api/v1/articles/{id}": { "get": { - "security": [ - { - "Bearer": [] - } - ], "description": "根据ID获取文章详情", "consumes": [ "application/json" @@ -3473,7 +3816,7 @@ "application/json" ], "tags": [ - "文章管理" + "文章管理-用户端" ], "summary": "获取文章详情", "parameters": [ @@ -3499,357 +3842,6 @@ "additionalProperties": true } }, - "401": { - "description": "未认证", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "404": { - "description": "文章不存在", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "500": { - "description": "服务器内部错误", - "schema": { - "type": "object", - "additionalProperties": true - } - } - } - }, - "put": { - "security": [ - { - "Bearer": [] - } - ], - "description": "更新文章信息", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "文章管理" - ], - "summary": "更新文章", - "parameters": [ - { - "type": "string", - "description": "文章ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "更新文章请求", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/commands.UpdateArticleCommand" - } - } - ], - "responses": { - "200": { - "description": "文章更新成功", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "400": { - "description": "请求参数错误", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "401": { - "description": "未认证", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "404": { - "description": "文章不存在", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "500": { - "description": "服务器内部错误", - "schema": { - "type": "object", - "additionalProperties": true - } - } - } - }, - "delete": { - "security": [ - { - "Bearer": [] - } - ], - "description": "删除指定文章", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "文章管理" - ], - "summary": "删除文章", - "parameters": [ - { - "type": "string", - "description": "文章ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "文章删除成功", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "400": { - "description": "请求参数错误", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "401": { - "description": "未认证", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "404": { - "description": "文章不存在", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "500": { - "description": "服务器内部错误", - "schema": { - "type": "object", - "additionalProperties": true - } - } - } - } - }, - "/api/v1/articles/{id}/archive": { - "post": { - "security": [ - { - "Bearer": [] - } - ], - "description": "将已发布文章归档", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "文章管理" - ], - "summary": "归档文章", - "parameters": [ - { - "type": "string", - "description": "文章ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "文章归档成功", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "400": { - "description": "请求参数错误", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "401": { - "description": "未认证", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "404": { - "description": "文章不存在", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "500": { - "description": "服务器内部错误", - "schema": { - "type": "object", - "additionalProperties": true - } - } - } - } - }, - "/api/v1/articles/{id}/featured": { - "put": { - "security": [ - { - "Bearer": [] - } - ], - "description": "设置文章的推荐状态", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "文章管理" - ], - "summary": "设置推荐状态", - "parameters": [ - { - "type": "string", - "description": "文章ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "设置推荐状态请求", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/commands.SetFeaturedCommand" - } - } - ], - "responses": { - "200": { - "description": "设置推荐状态成功", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "400": { - "description": "请求参数错误", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "401": { - "description": "未认证", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "404": { - "description": "文章不存在", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "500": { - "description": "服务器内部错误", - "schema": { - "type": "object", - "additionalProperties": true - } - } - } - } - }, - "/api/v1/articles/{id}/publish": { - "post": { - "security": [ - { - "Bearer": [] - } - ], - "description": "将草稿文章发布", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "文章管理" - ], - "summary": "发布文章", - "parameters": [ - { - "type": "string", - "description": "文章ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "文章发布成功", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "400": { - "description": "请求参数错误", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "401": { - "description": "未认证", - "schema": { - "type": "object", - "additionalProperties": true - } - }, "404": { "description": "文章不存在", "schema": { @@ -8202,13 +8194,60 @@ } } }, + "responses.ArticleListItemResponse": { + "type": "object", + "properties": { + "category": { + "$ref": "#/definitions/tyapi-server_internal_application_article_dto_responses.CategoryInfoResponse" + }, + "category_id": { + "type": "string" + }, + "cover_image": { + "type": "string" + }, + "created_at": { + "type": "string" + }, + "id": { + "type": "string" + }, + "is_featured": { + "type": "boolean" + }, + "published_at": { + "type": "string" + }, + "status": { + "type": "string" + }, + "summary": { + "type": "string" + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/definitions/responses.TagInfoResponse" + } + }, + "title": { + "type": "string" + }, + "updated_at": { + "type": "string" + }, + "view_count": { + "type": "integer" + } + } + }, "responses.ArticleListResponse": { "type": "object", "properties": { "items": { "type": "array", "items": { - "$ref": "#/definitions/responses.ArticleInfoResponse" + "$ref": "#/definitions/responses.ArticleListItemResponse" } }, "page": { diff --git a/docs/swagger/swagger.yaml b/docs/swagger/swagger.yaml index d8d6951..563918e 100644 --- a/docs/swagger/swagger.yaml +++ b/docs/swagger/swagger.yaml @@ -1035,11 +1035,42 @@ definitions: view_count: type: integer type: object + responses.ArticleListItemResponse: + properties: + category: + $ref: '#/definitions/tyapi-server_internal_application_article_dto_responses.CategoryInfoResponse' + category_id: + type: string + cover_image: + type: string + created_at: + type: string + id: + type: string + is_featured: + type: boolean + published_at: + type: string + status: + type: string + summary: + type: string + tags: + items: + $ref: '#/definitions/responses.TagInfoResponse' + type: array + title: + type: string + updated_at: + type: string + view_count: + type: integer + type: object responses.ArticleListResponse: properties: items: items: - $ref: '#/definitions/responses.ArticleInfoResponse' + $ref: '#/definitions/responses.ArticleListItemResponse' type: array page: type: integer @@ -2320,7 +2351,7 @@ paths: - Bearer: [] summary: 创建分类 tags: - - 文章分类管理 + - 文章分类-管理端 /api/v1/admin/article-categories/{id}: delete: consumes: @@ -2364,7 +2395,7 @@ paths: - Bearer: [] summary: 删除分类 tags: - - 文章分类管理 + - 文章分类-管理端 put: consumes: - application/json @@ -2413,7 +2444,7 @@ paths: - Bearer: [] summary: 更新分类 tags: - - 文章分类管理 + - 文章分类-管理端 /api/v1/admin/article-tags: post: consumes: @@ -2453,7 +2484,7 @@ paths: - Bearer: [] summary: 创建标签 tags: - - 文章标签管理 + - 文章标签-管理端 /api/v1/admin/article-tags/{id}: delete: consumes: @@ -2497,7 +2528,7 @@ paths: - Bearer: [] summary: 删除标签 tags: - - 文章标签管理 + - 文章标签-管理端 put: consumes: - application/json @@ -2546,7 +2577,278 @@ paths: - Bearer: [] summary: 更新标签 tags: - - 文章标签管理 + - 文章标签-管理端 + /api/v1/admin/articles: + post: + consumes: + - application/json + description: 创建新的文章 + parameters: + - description: 创建文章请求 + in: body + name: request + required: true + schema: + $ref: '#/definitions/commands.CreateArticleCommand' + produces: + - application/json + responses: + "201": + description: 文章创建成功 + schema: + additionalProperties: true + type: object + "400": + description: 请求参数错误 + schema: + additionalProperties: true + type: object + "401": + description: 未认证 + schema: + additionalProperties: true + type: object + "500": + description: 服务器内部错误 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 创建文章 + tags: + - 文章管理-管理端 + /api/v1/admin/articles/{id}: + delete: + consumes: + - application/json + description: 删除指定文章 + parameters: + - description: 文章ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: 文章删除成功 + schema: + additionalProperties: true + type: object + "400": + description: 请求参数错误 + schema: + additionalProperties: true + type: object + "401": + description: 未认证 + schema: + additionalProperties: true + type: object + "404": + description: 文章不存在 + schema: + additionalProperties: true + type: object + "500": + description: 服务器内部错误 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 删除文章 + tags: + - 文章管理-管理端 + put: + consumes: + - application/json + description: 更新文章信息 + parameters: + - description: 文章ID + in: path + name: id + required: true + type: string + - description: 更新文章请求 + in: body + name: request + required: true + schema: + $ref: '#/definitions/commands.UpdateArticleCommand' + produces: + - application/json + responses: + "200": + description: 文章更新成功 + schema: + additionalProperties: true + type: object + "400": + description: 请求参数错误 + schema: + additionalProperties: true + type: object + "401": + description: 未认证 + schema: + additionalProperties: true + type: object + "404": + description: 文章不存在 + schema: + additionalProperties: true + type: object + "500": + description: 服务器内部错误 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 更新文章 + tags: + - 文章管理-管理端 + /api/v1/admin/articles/{id}/archive: + post: + consumes: + - application/json + description: 将已发布文章归档 + parameters: + - description: 文章ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: 文章归档成功 + schema: + additionalProperties: true + type: object + "400": + description: 请求参数错误 + schema: + additionalProperties: true + type: object + "401": + description: 未认证 + schema: + additionalProperties: true + type: object + "404": + description: 文章不存在 + schema: + additionalProperties: true + type: object + "500": + description: 服务器内部错误 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 归档文章 + tags: + - 文章管理-管理端 + /api/v1/admin/articles/{id}/featured: + put: + consumes: + - application/json + description: 设置文章的推荐状态 + parameters: + - description: 文章ID + in: path + name: id + required: true + type: string + - description: 设置推荐状态请求 + in: body + name: request + required: true + schema: + $ref: '#/definitions/commands.SetFeaturedCommand' + produces: + - application/json + responses: + "200": + description: 设置推荐状态成功 + schema: + additionalProperties: true + type: object + "400": + description: 请求参数错误 + schema: + additionalProperties: true + type: object + "401": + description: 未认证 + schema: + additionalProperties: true + type: object + "404": + description: 文章不存在 + schema: + additionalProperties: true + type: object + "500": + description: 服务器内部错误 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 设置推荐状态 + tags: + - 文章管理-管理端 + /api/v1/admin/articles/{id}/publish: + post: + consumes: + - application/json + description: 将草稿文章发布 + parameters: + - description: 文章ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: 文章发布成功 + schema: + additionalProperties: true + type: object + "400": + description: 请求参数错误 + schema: + additionalProperties: true + type: object + "401": + description: 未认证 + schema: + additionalProperties: true + type: object + "404": + description: 文章不存在 + schema: + additionalProperties: true + type: object + "500": + description: 服务器内部错误 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 发布文章 + tags: + - 文章管理-管理端 /api/v1/admin/articles/{id}/schedule-publish: post: consumes: @@ -2596,7 +2898,7 @@ paths: - Bearer: [] summary: 定时发布文章 tags: - - 文章管理 + - 文章管理-管理端 /api/v1/admin/articles/stats: get: consumes: @@ -2623,7 +2925,7 @@ paths: - Bearer: [] summary: 获取文章统计 tags: - - 文章管理 + - 文章管理-管理端 /api/v1/admin/invoices/{application_id}/approve: post: consumes: @@ -4256,7 +4558,7 @@ paths: type: object summary: 获取分类列表 tags: - - 文章分类 + - 文章分类-用户端 /api/v1/article-categories/{id}: get: consumes: @@ -4292,7 +4594,7 @@ paths: type: object summary: 获取分类详情 tags: - - 文章分类 + - 文章分类-用户端 /api/v1/article-tags: get: consumes: @@ -4312,7 +4614,7 @@ paths: type: object summary: 获取标签列表 tags: - - 文章标签 + - 文章标签-用户端 /api/v1/article-tags/{id}: get: consumes: @@ -4348,7 +4650,7 @@ paths: type: object summary: 获取标签详情 tags: - - 文章标签 + - 文章标签-用户端 /api/v1/articles: get: consumes: @@ -4416,90 +4718,8 @@ paths: type: object summary: 获取文章列表 tags: - - 文章管理 - post: - consumes: - - application/json - description: 创建新的文章 - parameters: - - description: 创建文章请求 - in: body - name: request - required: true - schema: - $ref: '#/definitions/commands.CreateArticleCommand' - produces: - - application/json - responses: - "201": - description: 文章创建成功 - schema: - additionalProperties: true - type: object - "400": - description: 请求参数错误 - schema: - additionalProperties: true - type: object - "401": - description: 未认证 - schema: - additionalProperties: true - type: object - "500": - description: 服务器内部错误 - schema: - additionalProperties: true - type: object - security: - - Bearer: [] - summary: 创建文章 - tags: - - 文章管理 + - 文章管理-用户端 /api/v1/articles/{id}: - delete: - consumes: - - application/json - description: 删除指定文章 - parameters: - - description: 文章ID - in: path - name: id - required: true - type: string - produces: - - application/json - responses: - "200": - description: 文章删除成功 - schema: - additionalProperties: true - type: object - "400": - description: 请求参数错误 - schema: - additionalProperties: true - type: object - "401": - description: 未认证 - schema: - additionalProperties: true - type: object - "404": - description: 文章不存在 - schema: - additionalProperties: true - type: object - "500": - description: 服务器内部错误 - schema: - additionalProperties: true - type: object - security: - - Bearer: [] - summary: 删除文章 - tags: - - 文章管理 get: consumes: - application/json @@ -4522,11 +4742,6 @@ paths: schema: additionalProperties: true type: object - "401": - description: 未认证 - schema: - additionalProperties: true - type: object "404": description: 文章不存在 schema: @@ -4537,198 +4752,9 @@ paths: schema: additionalProperties: true type: object - security: - - Bearer: [] summary: 获取文章详情 tags: - - 文章管理 - put: - consumes: - - application/json - description: 更新文章信息 - parameters: - - description: 文章ID - in: path - name: id - required: true - type: string - - description: 更新文章请求 - in: body - name: request - required: true - schema: - $ref: '#/definitions/commands.UpdateArticleCommand' - produces: - - application/json - responses: - "200": - description: 文章更新成功 - schema: - additionalProperties: true - type: object - "400": - description: 请求参数错误 - schema: - additionalProperties: true - type: object - "401": - description: 未认证 - schema: - additionalProperties: true - type: object - "404": - description: 文章不存在 - schema: - additionalProperties: true - type: object - "500": - description: 服务器内部错误 - schema: - additionalProperties: true - type: object - security: - - Bearer: [] - summary: 更新文章 - tags: - - 文章管理 - /api/v1/articles/{id}/archive: - post: - consumes: - - application/json - description: 将已发布文章归档 - parameters: - - description: 文章ID - in: path - name: id - required: true - type: string - produces: - - application/json - responses: - "200": - description: 文章归档成功 - schema: - additionalProperties: true - type: object - "400": - description: 请求参数错误 - schema: - additionalProperties: true - type: object - "401": - description: 未认证 - schema: - additionalProperties: true - type: object - "404": - description: 文章不存在 - schema: - additionalProperties: true - type: object - "500": - description: 服务器内部错误 - schema: - additionalProperties: true - type: object - security: - - Bearer: [] - summary: 归档文章 - tags: - - 文章管理 - /api/v1/articles/{id}/featured: - put: - consumes: - - application/json - description: 设置文章的推荐状态 - parameters: - - description: 文章ID - in: path - name: id - required: true - type: string - - description: 设置推荐状态请求 - in: body - name: request - required: true - schema: - $ref: '#/definitions/commands.SetFeaturedCommand' - produces: - - application/json - responses: - "200": - description: 设置推荐状态成功 - schema: - additionalProperties: true - type: object - "400": - description: 请求参数错误 - schema: - additionalProperties: true - type: object - "401": - description: 未认证 - schema: - additionalProperties: true - type: object - "404": - description: 文章不存在 - schema: - additionalProperties: true - type: object - "500": - description: 服务器内部错误 - schema: - additionalProperties: true - type: object - security: - - Bearer: [] - summary: 设置推荐状态 - tags: - - 文章管理 - /api/v1/articles/{id}/publish: - post: - consumes: - - application/json - description: 将草稿文章发布 - parameters: - - description: 文章ID - in: path - name: id - required: true - type: string - produces: - - application/json - responses: - "200": - description: 文章发布成功 - schema: - additionalProperties: true - type: object - "400": - description: 请求参数错误 - schema: - additionalProperties: true - type: object - "401": - description: 未认证 - schema: - additionalProperties: true - type: object - "404": - description: 文章不存在 - schema: - additionalProperties: true - type: object - "500": - description: 服务器内部错误 - schema: - additionalProperties: true - type: object - security: - - Bearer: [] - summary: 发布文章 - tags: - - 文章管理 + - 文章管理-用户端 /api/v1/categories: get: consumes: diff --git a/internal/application/article/article_application_service_impl.go b/internal/application/article/article_application_service_impl.go index 6ef117e..92eb10f 100644 --- a/internal/application/article/article_application_service_impl.go +++ b/internal/application/article/article_application_service_impl.go @@ -210,7 +210,7 @@ func (s *ArticleApplicationServiceImpl) ListArticles(ctx context.Context, query } // 3. 转换为响应对象 - items := responses.FromArticleEntities(articles) + items := responses.FromArticleEntitiesToListItemList(articles) response := &responses.ArticleListResponse{ Total: total, diff --git a/internal/application/article/dto/responses/article_responses.go b/internal/application/article/dto/responses/article_responses.go index 865a801..730ab6b 100644 --- a/internal/application/article/dto/responses/article_responses.go +++ b/internal/application/article/dto/responses/article_responses.go @@ -23,12 +23,29 @@ type ArticleInfoResponse struct { UpdatedAt time.Time `json:"updated_at" comment:"更新时间"` } +// ArticleListItemResponse 文章列表项响应(不包含content) +type ArticleListItemResponse struct { + ID string `json:"id" comment:"文章ID"` + Title string `json:"title" comment:"文章标题"` + Summary string `json:"summary" comment:"文章摘要"` + CoverImage string `json:"cover_image" comment:"封面图片"` + CategoryID string `json:"category_id" comment:"分类ID"` + Category *CategoryInfoResponse `json:"category,omitempty" comment:"分类信息"` + Status string `json:"status" comment:"文章状态"` + IsFeatured bool `json:"is_featured" comment:"是否推荐"` + PublishedAt *time.Time `json:"published_at" comment:"发布时间"` + ViewCount int `json:"view_count" comment:"阅读量"` + Tags []TagInfoResponse `json:"tags" comment:"标签列表"` + CreatedAt time.Time `json:"created_at" comment:"创建时间"` + UpdatedAt time.Time `json:"updated_at" comment:"更新时间"` +} + // ArticleListResponse 文章列表响应 type ArticleListResponse struct { - Total int64 `json:"total" comment:"总数"` - Page int `json:"page" comment:"页码"` - Size int `json:"size" comment:"每页数量"` - Items []ArticleInfoResponse `json:"items" comment:"文章列表"` + Total int64 `json:"total" comment:"总数"` + Page int `json:"page" comment:"页码"` + Size int `json:"size" comment:"每页数量"` + Items []ArticleListItemResponse `json:"items" comment:"文章列表"` } // CategoryInfoResponse 分类信息响应 @@ -118,6 +135,53 @@ func FromArticleEntity(article *entities.Article) *ArticleInfoResponse { return response } +// FromArticleEntityToListItem 从文章实体转换为列表项响应对象(不包含content) +func FromArticleEntityToListItem(article *entities.Article) *ArticleListItemResponse { + if article == nil { + return nil + } + + response := &ArticleListItemResponse{ + ID: article.ID, + Title: article.Title, + Summary: article.Summary, + CoverImage: article.CoverImage, + CategoryID: article.CategoryID, + Status: string(article.Status), + IsFeatured: article.IsFeatured, + PublishedAt: article.PublishedAt, + ViewCount: article.ViewCount, + CreatedAt: article.CreatedAt, + UpdatedAt: article.UpdatedAt, + } + + // 转换分类信息 + if article.Category != nil { + response.Category = &CategoryInfoResponse{ + ID: article.Category.ID, + Name: article.Category.Name, + Description: article.Category.Description, + SortOrder: article.Category.SortOrder, + CreatedAt: article.Category.CreatedAt, + } + } + + // 转换标签信息 + if len(article.Tags) > 0 { + response.Tags = make([]TagInfoResponse, len(article.Tags)) + for i, tag := range article.Tags { + response.Tags[i] = TagInfoResponse{ + ID: tag.ID, + Name: tag.Name, + Color: tag.Color, + CreatedAt: tag.CreatedAt, + } + } + } + + return response +} + // FromArticleEntities 从文章实体列表转换为响应对象列表 func FromArticleEntities(articles []*entities.Article) []ArticleInfoResponse { if len(articles) == 0 { @@ -133,3 +197,19 @@ func FromArticleEntities(articles []*entities.Article) []ArticleInfoResponse { return responses } + +// FromArticleEntitiesToListItemList 从文章实体列表转换为列表项响应对象列表(不包含content) +func FromArticleEntitiesToListItemList(articles []*entities.Article) []ArticleListItemResponse { + if len(articles) == 0 { + return []ArticleListItemResponse{} + } + + responses := make([]ArticleListItemResponse, len(articles)) + for i, article := range articles { + if response := FromArticleEntityToListItem(article); response != nil { + responses[i] = *response + } + } + + return responses +} diff --git a/internal/infrastructure/database/repositories/article/gorm_article_repository.go b/internal/infrastructure/database/repositories/article/gorm_article_repository.go index 7c1798c..8b2ad80 100644 --- a/internal/infrastructure/database/repositories/article/gorm_article_repository.go +++ b/internal/infrastructure/database/repositories/article/gorm_article_repository.go @@ -261,7 +261,8 @@ func (r *GormArticleRepository) ListArticles(ctx context.Context, query *repoQue var articles []entities.Article var total int64 - dbQuery := r.db.WithContext(ctx).Model(&entities.Article{}) + dbQuery := r.db.WithContext(ctx).Model(&entities.Article{}). + Select("id, title, summary, cover_image, category_id, status, is_featured, published_at, view_count, created_at, updated_at, scheduled_at") // 应用筛选条件 if query.Status != "" { diff --git a/internal/infrastructure/http/handlers/article_handler.go b/internal/infrastructure/http/handlers/article_handler.go index a52fb6b..ec69ad1 100644 --- a/internal/infrastructure/http/handlers/article_handler.go +++ b/internal/infrastructure/http/handlers/article_handler.go @@ -38,7 +38,7 @@ func NewArticleHandler( // CreateArticle 创建文章 // @Summary 创建文章 // @Description 创建新的文章 -// @Tags 文章管理 +// @Tags 文章管理-管理端 // @Accept json // @Produce json // @Security Bearer @@ -47,7 +47,7 @@ func NewArticleHandler( // @Failure 400 {object} map[string]interface{} "请求参数错误" // @Failure 401 {object} map[string]interface{} "未认证" // @Failure 500 {object} map[string]interface{} "服务器内部错误" -// @Router /api/v1/articles [post] +// @Router /api/v1/admin/articles [post] func (h *ArticleHandler) CreateArticle(c *gin.Context) { var cmd commands.CreateArticleCommand if err := h.validator.BindAndValidate(c, &cmd); err != nil { @@ -72,14 +72,12 @@ func (h *ArticleHandler) CreateArticle(c *gin.Context) { // GetArticleByID 获取文章详情 // @Summary 获取文章详情 // @Description 根据ID获取文章详情 -// @Tags 文章管理 +// @Tags 文章管理-用户端 // @Accept json // @Produce json -// @Security Bearer // @Param id path string true "文章ID" // @Success 200 {object} responses.ArticleInfoResponse "获取文章详情成功" // @Failure 400 {object} map[string]interface{} "请求参数错误" -// @Failure 401 {object} map[string]interface{} "未认证" // @Failure 404 {object} map[string]interface{} "文章不存在" // @Failure 500 {object} map[string]interface{} "服务器内部错误" // @Router /api/v1/articles/{id} [get] @@ -104,7 +102,7 @@ func (h *ArticleHandler) GetArticleByID(c *gin.Context) { // ListArticles 获取文章列表 // @Summary 获取文章列表 // @Description 分页获取文章列表,支持多种筛选条件 -// @Tags 文章管理 +// @Tags 文章管理-用户端 // @Accept json // @Produce json // @Param page query int false "页码" default(1) @@ -153,7 +151,7 @@ func (h *ArticleHandler) ListArticles(c *gin.Context) { // UpdateArticle 更新文章 // @Summary 更新文章 // @Description 更新文章信息 -// @Tags 文章管理 +// @Tags 文章管理-管理端 // @Accept json // @Produce json // @Security Bearer @@ -164,7 +162,7 @@ func (h *ArticleHandler) ListArticles(c *gin.Context) { // @Failure 401 {object} map[string]interface{} "未认证" // @Failure 404 {object} map[string]interface{} "文章不存在" // @Failure 500 {object} map[string]interface{} "服务器内部错误" -// @Router /api/v1/articles/{id} [put] +// @Router /api/v1/admin/articles/{id} [put] func (h *ArticleHandler) UpdateArticle(c *gin.Context) { var cmd commands.UpdateArticleCommand cmd.ID = c.Param("id") @@ -188,7 +186,7 @@ func (h *ArticleHandler) UpdateArticle(c *gin.Context) { // DeleteArticle 删除文章 // @Summary 删除文章 // @Description 删除指定文章 -// @Tags 文章管理 +// @Tags 文章管理-管理端 // @Accept json // @Produce json // @Security Bearer @@ -198,7 +196,7 @@ func (h *ArticleHandler) UpdateArticle(c *gin.Context) { // @Failure 401 {object} map[string]interface{} "未认证" // @Failure 404 {object} map[string]interface{} "文章不存在" // @Failure 500 {object} map[string]interface{} "服务器内部错误" -// @Router /api/v1/articles/{id} [delete] +// @Router /api/v1/admin/articles/{id} [delete] func (h *ArticleHandler) DeleteArticle(c *gin.Context) { var cmd commands.DeleteArticleCommand if err := h.validator.ValidateParam(c, &cmd); err != nil { @@ -217,7 +215,7 @@ func (h *ArticleHandler) DeleteArticle(c *gin.Context) { // PublishArticle 发布文章 // @Summary 发布文章 // @Description 将草稿文章发布 -// @Tags 文章管理 +// @Tags 文章管理-管理端 // @Accept json // @Produce json // @Security Bearer @@ -227,7 +225,7 @@ func (h *ArticleHandler) DeleteArticle(c *gin.Context) { // @Failure 401 {object} map[string]interface{} "未认证" // @Failure 404 {object} map[string]interface{} "文章不存在" // @Failure 500 {object} map[string]interface{} "服务器内部错误" -// @Router /api/v1/articles/{id}/publish [post] +// @Router /api/v1/admin/articles/{id}/publish [post] func (h *ArticleHandler) PublishArticle(c *gin.Context) { var cmd commands.PublishArticleCommand if err := h.validator.ValidateParam(c, &cmd); err != nil { @@ -246,7 +244,7 @@ func (h *ArticleHandler) PublishArticle(c *gin.Context) { // SchedulePublishArticle 定时发布文章 // @Summary 定时发布文章 // @Description 设置文章的定时发布时间 -// @Tags 文章管理 +// @Tags 文章管理-管理端 // @Accept json // @Produce json // @Security Bearer @@ -279,7 +277,7 @@ func (h *ArticleHandler) SchedulePublishArticle(c *gin.Context) { // ArchiveArticle 归档文章 // @Summary 归档文章 // @Description 将已发布文章归档 -// @Tags 文章管理 +// @Tags 文章管理-管理端 // @Accept json // @Produce json // @Security Bearer @@ -289,7 +287,7 @@ func (h *ArticleHandler) SchedulePublishArticle(c *gin.Context) { // @Failure 401 {object} map[string]interface{} "未认证" // @Failure 404 {object} map[string]interface{} "文章不存在" // @Failure 500 {object} map[string]interface{} "服务器内部错误" -// @Router /api/v1/articles/{id}/archive [post] +// @Router /api/v1/admin/articles/{id}/archive [post] func (h *ArticleHandler) ArchiveArticle(c *gin.Context) { var cmd commands.ArchiveArticleCommand if err := h.validator.ValidateParam(c, &cmd); err != nil { @@ -308,7 +306,7 @@ func (h *ArticleHandler) ArchiveArticle(c *gin.Context) { // SetFeatured 设置推荐状态 // @Summary 设置推荐状态 // @Description 设置文章的推荐状态 -// @Tags 文章管理 +// @Tags 文章管理-管理端 // @Accept json // @Produce json // @Security Bearer @@ -319,7 +317,7 @@ func (h *ArticleHandler) ArchiveArticle(c *gin.Context) { // @Failure 401 {object} map[string]interface{} "未认证" // @Failure 404 {object} map[string]interface{} "文章不存在" // @Failure 500 {object} map[string]interface{} "服务器内部错误" -// @Router /api/v1/articles/{id}/featured [put] +// @Router /api/v1/admin/articles/{id}/featured [put] func (h *ArticleHandler) SetFeatured(c *gin.Context) { var cmd commands.SetFeaturedCommand if err := h.validator.ValidateParam(c, &cmd); err != nil { @@ -341,7 +339,7 @@ func (h *ArticleHandler) SetFeatured(c *gin.Context) { // GetArticleStats 获取文章统计 // @Summary 获取文章统计 // @Description 获取文章相关统计数据 -// @Tags 文章管理 +// @Tags 文章管理-管理端 // @Accept json // @Produce json // @Security Bearer @@ -366,7 +364,7 @@ func (h *ArticleHandler) GetArticleStats(c *gin.Context) { // ListCategories 获取分类列表 // @Summary 获取分类列表 // @Description 获取所有文章分类 -// @Tags 文章分类 +// @Tags 文章分类-用户端 // @Accept json // @Produce json // @Success 200 {object} responses.CategoryListResponse "获取分类列表成功" @@ -386,7 +384,7 @@ func (h *ArticleHandler) ListCategories(c *gin.Context) { // GetCategoryByID 获取分类详情 // @Summary 获取分类详情 // @Description 根据ID获取分类详情 -// @Tags 文章分类 +// @Tags 文章分类-用户端 // @Accept json // @Produce json // @Param id path string true "分类ID" @@ -416,7 +414,7 @@ func (h *ArticleHandler) GetCategoryByID(c *gin.Context) { // CreateCategory 创建分类 // @Summary 创建分类 // @Description 创建新的文章分类 -// @Tags 文章分类管理 +// @Tags 文章分类-管理端 // @Accept json // @Produce json // @Security Bearer @@ -444,7 +442,7 @@ func (h *ArticleHandler) CreateCategory(c *gin.Context) { // UpdateCategory 更新分类 // @Summary 更新分类 // @Description 更新分类信息 -// @Tags 文章分类管理 +// @Tags 文章分类-管理端 // @Accept json // @Produce json // @Security Bearer @@ -479,7 +477,7 @@ func (h *ArticleHandler) UpdateCategory(c *gin.Context) { // DeleteCategory 删除分类 // @Summary 删除分类 // @Description 删除指定分类 -// @Tags 文章分类管理 +// @Tags 文章分类-管理端 // @Accept json // @Produce json // @Security Bearer @@ -510,7 +508,7 @@ func (h *ArticleHandler) DeleteCategory(c *gin.Context) { // ListTags 获取标签列表 // @Summary 获取标签列表 // @Description 获取所有文章标签 -// @Tags 文章标签 +// @Tags 文章标签-用户端 // @Accept json // @Produce json // @Success 200 {object} responses.TagListResponse "获取标签列表成功" @@ -530,7 +528,7 @@ func (h *ArticleHandler) ListTags(c *gin.Context) { // GetTagByID 获取标签详情 // @Summary 获取标签详情 // @Description 根据ID获取标签详情 -// @Tags 文章标签 +// @Tags 文章标签-用户端 // @Accept json // @Produce json // @Param id path string true "标签ID" @@ -560,7 +558,7 @@ func (h *ArticleHandler) GetTagByID(c *gin.Context) { // CreateTag 创建标签 // @Summary 创建标签 // @Description 创建新的文章标签 -// @Tags 文章标签管理 +// @Tags 文章标签-管理端 // @Accept json // @Produce json // @Security Bearer @@ -588,7 +586,7 @@ func (h *ArticleHandler) CreateTag(c *gin.Context) { // UpdateTag 更新标签 // @Summary 更新标签 // @Description 更新标签信息 -// @Tags 文章标签管理 +// @Tags 文章标签-管理端 // @Accept json // @Produce json // @Security Bearer @@ -623,7 +621,7 @@ func (h *ArticleHandler) UpdateTag(c *gin.Context) { // DeleteTag 删除标签 // @Summary 删除标签 // @Description 删除指定标签 -// @Tags 文章标签管理 +// @Tags 文章标签-管理端 // @Accept json // @Produce json // @Security Bearer diff --git a/internal/infrastructure/http/routes/article_routes.go b/internal/infrastructure/http/routes/article_routes.go index 5501376..1e7e6cc 100644 --- a/internal/infrastructure/http/routes/article_routes.go +++ b/internal/infrastructure/http/routes/article_routes.go @@ -66,8 +66,8 @@ func (r *ArticleRoutes) Register(router *sharedhttp.GinRouter) { adminArticleGroup.Use(r.admin.Handle()) { // 统计信息 - adminArticleGroup.GET("/stats", r.handler.GetArticleStats) // 获取文章统计 - + adminArticleGroup.GET("/stats", r.handler.GetArticleStats) // 获取文章统计 + // 文章管理 adminArticleGroup.POST("", r.handler.CreateArticle) // 创建文章 adminArticleGroup.PUT("/:id", r.handler.UpdateArticle) // 更新文章