Skip to content

Latest commit

 

History

History
943 lines (781 loc) · 21 KB

接口文档.md

File metadata and controls

943 lines (781 loc) · 21 KB

阿里百秀

基础URL:http://localhost:3000

1. 用户管理

1.1 创建用户

请求地址 请求方式
/users POST
参数名称 是否必选 参数说明
nickName 用户昵称
email 邮件地址
password 登录密码
role 角色 [admin 超级管理员] [normal 普通用户]
avatar 头像
status 状态 [0 未激活] [1 激活]
{
    "_id": "6231fc8a875361a58cd8691b", 		// 用户id
    "email": "[email protected]",        	// 邮箱地址
    "nickName": "Vogadero",              	// 昵称
    "role": "admin",                   		// 角色
    "avatar": null,                    		// 头像
     "createTime": {
        "$date": "2022-03-16T15:04:42.872Z"
    	}, 									// 创建时间
    "status": 1                        		// 状态
}

1.2 用户登录

请求地址 请求方式
/login POST
参数名称 是否必选 参数说明
email 邮箱地址
password 登录密码
{
    "nickName": "Vogadero",
    "email": "[email protected]",
    "password": "$2b$10$1eOkBNZRW8n3NfkmDxCsZu7vC/t7RDisd/WByDx.C6GhLGsVXkcaS",
    "role": "admin",
    "avatar": null,
    "createTime": {
        "$date": "2022-03-16T15:04:42.872Z"
    	},
    "status": 1
}

1.3 退出登录

请求地址 请求方式
/logout POST
{
    "message": "退出成功"
}

1.4 操作用户

1.4.1 获取用户登录状态

请求地址 请求方式
/login/status GET
var isLogin = true;
var userId = "5c8d0bd652ae3d26686b8601";

1.4.2 获取用户列表

请求地址 请求方式
/users GET
[
    {
        "role": "admin",
        "avatar": null,
        "status": 1,
        "_id": "6231fc8a875361a58cd8691b",
        "nickName": "Vogadero",
        "email": "[email protected]",
        "createTime": "2022-03-16T15:04:42.872Z"
    }
]

1.4.3 根据 id 查询用户

请求地址 请求方式
/users/:id GET
{
	"role": "admin",
	"avatar": null,
	"status": 1,
	"_id": "6231fc8a875361a58cd8691b",
	"nickName": "Vogadero",
	"email": "[email protected]",
	"createTime": "2022-03-16T15:04:42.872Z"
}

1.4.4 根据 id 修改用户

请求地址 请求方式
/users/:id PUT
参数名称 是否必选 参数说明
nickName 用户昵称
status 用户状态
role 用户角色
avatar 用户头像
{
	"role": "admin",
	"avatar": null,
	"status": 1,
	"_id": "6231fc8a875361a58cd8691b",
	"nickName": "Vogadero",
	"email": "[email protected]",
	"createTime": "2022-03-16T15:04:42.872Z"
}

1.4.5 根据 id 删除用户

请求地址 请求方式 说明
/users/:id DELETE 批量删除,多个id用-隔开,例如:/users/:id-id-id
{
	"role": "admin",
	"avatar": null,
	"status": 1,
	"_id": "6231fc8a875361a58cd8691b",
	"nickName": "Vogadero",
    "password":"$2b$10$1eOkBNZRW8n3NfkmDxCsZu7vC/t7RDisd/WByDx.C6GhLGsVXkcaS",
	"email": "[email protected]",
	"createTime": "2022-03-16T15:04:42.872Z"
}
[
	{
		"role": "admin",
		"avatar": null,
		"status": 1,
		"_id": "6231fc8a875361a58cd8691b",
		"nickName": "Vogadero",
    	"password":"$2b$10$1eOkBNZRW8n3NfkmDxCsZu7vC/t7RDisd/WByDx.C6GhLGsVXkcaS",
		"email": "[email protected]",
		"createTime": "2022-03-16T15:04:42.872Z"
	}
]

1.4.6 修改用户密码

请求地址 请求方式
/users/password PUT
参数名称 是否必选 参数说明
userPass 原密码
newPass 新密码
confirmPass 确认新密码
{
    message: '密码修改成功'
}

2. 分类管理

2.1 添加分类

请求地址 请求方式
/categories POST
参数名称 是否必选 参数说明
title 分类名称
className 分类图标类名
{
    "className": "fa-car",
    "_id": "6239dfae7daef8ded4720e19",
    "title": "在路上",
    "createAt": "2022-03-22T14:39:42.890+00:00"
}

2.2 查询分类

2.2.1 根据 id 查询分类

请求地址 请求方式
/categories/:id GET
{
    "className": "fa-car",
    "_id": "6239dfae7daef8ded4720e19",
    "title": "在路上",
    "createAt": "2022-03-22T14:39:42.890+00:00"
}

2.2.2 查询分类列表

请求地址 请求方式
/categories GET
[
    {
        "className": "fa-car",
        "_id": "6239dfae7daef8ded4720e19",
        "title": "在路上",
        "createAt": "2022-03-22T14:39:42.890+00:00"
    },
    {
        "className": "fa-cloud",
        "_id": "6239e2a37daef8ded4720e1c",
        "title": "阿里云",
        "createAt": "2022-03-22T14:52:19.775+00:00"
    }
]

2.2.3 查询分类数量

请求地址 请求方式
/categories/count GET
{
    "categoryCount": 6
}

2.5 根据 id 修改分类

请求地址 请求方式
/categories/:id PUT
参数名称 是否必选 参数说明
title 分类名称
className 分类图标类名
{
    "className": "fa-car",
    "_id": "6239dfae7daef8ded4720e19",
    "title": "在路上",
    "createAt": "2022-03-22T14:39:42.890+00:00"
}

2.6 根据 id 删除分类

请求地址 请求方式 说明
/categories/:id DELETE 批量删除,多个id用-隔开,例如:/categories/:id-id-id
{
    "className": "fa-car",
    "_id": "6239dfae7daef8ded4720e19",
    "title": "在路上",
    "createAt": "2022-03-22T14:39:42.890+00:00"
}
[
    {
        "className": "fa-car",
   		"_id": "6239dfae7daef8ded4720e19",
    	"title": "在路上",
    	"createAt": "2022-03-22T14:39:42.890+00:00"
    }
]

3. 文章管理

3.1 创建文章

请求地址 请求方式
/posts POST
参数名称 是否必选 参数说明
title 文章标题
state 文章状态 [0 草稿] [1 发布]
content 文章内容
category 文章所属分类
thumbnail 文章封面
createAt 文章发布时间
{
    "meta": {
        "views": 0,
        "likes": 0,
        "comments": 0
    },
    "state": 1,
    "content": "测试内容",
    "thumbnail": "\\uploads\\upload_ac37048704b9a9624f15017debe70932.jpg",
    "_id": "623d7baa00b63554ddbf9a99",
    "title": "测试文章",
    "category": "623ad94f2117f699fb85bb6c",
    "author": "6231fc8a875361a58cd8691b",
    "createAt": "2022-03-25T08:21:00.000Z",
    "updateAt": "2022-03-25T08:22:02.600Z"
}

3.2 查询文章

3.2.1 根据 id 获取文章

请求地址 请求方式
/posts/:id GET
{
    "meta": {
        "views": 0,
        "likes": 0,
        "comments": 0
    },
    "state": 1,
    "content": "测试内容",
    "thumbnail": "\\uploads\\upload_ac37048704b9a9624f15017debe70932.jpg",
    "_id": "623d7baa00b63554ddbf9a99",
    "title": "测试文章",
    "category": "623ad94f2117f699fb85bb6c",
    "author": "6231fc8a875361a58cd8691b",
    "createAt": "2022-03-25T08:21:00.000Z",
    "updateAt": "2022-03-25T08:22:02.600Z"
}

3.2.2 查询文章列表

请求地址 请求方式
/posts GET
参数名称 是否必选 参数说明
category 文章所属分类
state 文章状态 [0 草稿] [1 发布]
page 文章页码
{
    "page": 1,
    "size": 10,
    "total": 4,
    "records": [
        {
            "state": 1,
            "thumbnail": "\\uploads\\upload_ac37048704b9a9624f15017debe70932.jpg",
            "_id": "623d7baa00b63554ddbf9a99",
            "title": "测试文章",
            "category": {
                "className": "fa-cloud",
                "_id": "623ad94f2117f699fb85bb6c",
                "title": "阿里云",
                "createAt": "2022-03-25T08:21:00.000Z"
            },
            "author": {
                "role": "admin",
                "avatar": "\\uploads\\upload_125e963dc59d8535cdbb8b4fb72044d3.jpg",
                "status": 1,
                "_id": "6231fc8a875361a58cd8691b",
                "nickName": "Vogadero",
                "email": "[email protected]",
                "createTime": "2022-03-16T15:04:42.872Z"
            },
            "createAt": "2022-03-25T08:21:00.000Z",
            "updateAt": "2022-03-25T08:22:02.600Z"
        }
    ],
    "pages": 1,
    "display": [
        1
    ]
}

3.2.3 根据分类获取文章列表

请求地址 请求方式
/posts/category/:id GET
[
    {
        "meta": {
            "views": 0,
            "likes": 0,
            "comments": 0
        },
        "state": 1,
        "content": "测试内容",
        "thumbnail": null,
        "_id": "5c8dcf3a5fcbf1100c276648",
        "title": "是单独发顺丰",
        "category": "5c8dbc2ded67612f8837e0db",
        "author": "5c8dcd072346ad087cf957be",
        "createAt": "2019-03-17T04:29:46.212Z",
        "updateAt": "2019-03-17T04:29:46.212Z"
    }
]

3.2.4 查询文章数量

请求地址 请求方式
/posts/count GET
{
    "postCount": 4,
    "draftCount": 11
}

3.2.5 获取最新发布文章

请求地址 请求方式
/posts/lasted GET
[
    {
        "state": 1,
        "thumbnail": null,
        "_id": "5c8dcf415fcbf1100c27664b",
        "title": "测试文章",
        "category": {
            "className": "fa-glass",
            "_id": "5c8dbc2ded67612f8837e0db",
            "title": "奇趣事",
            "createAt": "2019-03-17T03:17:01.733Z"
        },
        "author": {
            "role": "admin",
            "avatar": null,
            "status": 1,
            "_id": "5c8dcd072346ad087cf957be",
            "nickName": "coder",
            "email": "[email protected]",
            "createTime": "2019-03-17T04:28:55.780Z"
        },
        "createAt": "2019-03-20T04:29:46.212Z",
        "updateAt": "2019-03-20T04:29:46.212Z"
    }
]

3.2.6 获取热门推荐

请求地址 请求方式
/posts/recommend GET
[
    {
        "meta": {
            "views": 0,
            "likes": 0,
            "comments": 3
        },
        "state": 1,
        "thumbnail": null,
        "_id": "5c8dcf3f5fcbf1100c27664a",
        "title": "测试文章",
        "category": "5c8dbc2ded67612f8837e0db",
        "author": "5c8dcd072346ad087cf957be",
        "createAt": "2019-03-19T04:29:46.212Z",
        "updateAt": "2019-03-19T04:29:46.212Z"
    }
]

3.2.7 获取随机推荐

请求地址 请求方式
/posts/random GET
[
    {
        "meta": {
            "views": 0,
            "likes": 0,
            "comments": 0
        },
        "state": 1,
        "content": "测试内容",
        "thumbnail": null,
        "_id": "5c8dcf3a5fcbf1100c276648",
        "title": "是单独发顺丰",
        "category": "5c8dbc2ded67612f8837e0db",
        "author": "5c8dcd072346ad087cf957be",
        "createAt": "2019-03-17T04:29:46.212Z",
        "updateAt": "2019-03-17T04:29:46.212Z"
    }
]

3.3 根据 id 修改文章

请求地址 请求方式
/posts/:id PUT
参数名称 是否必选 参数说明
title 文章标题
state 文章状态 [0 草稿] [1 发布]
content 文章内容
category 文章所属分类
thumbnail 文章缩略图
{
    "meta": {
        "views": 0,
        "likes": 0,
        "comments": 0
    },
    "state": 1,
    "content": "测试内容",
    "thumbnail": "\\uploads\\upload_ac37048704b9a9624f15017debe70932.jpg",
    "_id": "623d7baa00b63554ddbf9a99",
    "title": "测试文章",
    "category": "623ad94f2117f699fb85bb6c",
    "author": "6231fc8a875361a58cd8691b",
    "createAt": "2022-03-25T08:21:00.000Z",
    "updateAt": "2022-03-25T08:22:02.600Z"
}

3.4 根据 id 删除文章

请求地址 请求方式
/posts/:id DELETE
{
    "meta": {
        "views": 0,
        "likes": 0,
        "comments": 0
    },
    "state": 1,
    "content": "测试内容",
    "thumbnail": "\\uploads\\upload_ac37048704b9a9624f15017debe70932.jpg",
    "_id": "623d7baa00b63554ddbf9a99",
    "title": "测试文章",
    "category": "623ad94f2117f699fb85bb6c",
    "author": "6231fc8a875361a58cd8691b",
    "createAt": "2022-03-25T08:21:00.000Z",
    "updateAt": "2022-03-25T08:22:02.600Z"
}

3.5 文章点赞

请求地址 请求方式
/posts/fabulous/:id POST
{
    "meta": {
        "views": 0,
        "likes": 4,
        "comments": 0
    },
    "_id": "5c8dcf3a5fcbf1100c276648"
}

3.6 文章搜索

请求地址 请求方式
/posts/search/:key GET
[
    {
    	"meta": {
    	    "views": 0,
    	    "likes": 0,
    	    "comments": 0
    	},
    	"state": 1,
    	"content": "测试内容",
    	"thumbnail": "\\uploads\\upload_ac37048704b9a9624f15017debe70932.jpg",
    	"_id": "623d7baa00b63554ddbf9a99",
    	"title": "测试文章",
    	"category": "623ad94f2117f699fb85bb6c",
    	"author": "6231fc8a875361a58cd8691b",
    	"createAt": "2022-03-25T08:21:00.000Z",
    	"updateAt": "2022-03-25T08:22:02.600Z"
	}
]

4. 评论管理

4.1 创建评论

请求地址 请求方式
/comments POST
参数名称 是否必选 参数说明
content 评论内容
post 评论文章id
state 评论状态
{
    "state": 0,
    "_id": "5c8dee68f4ce931c2c4a0cc3",
    "author": "5c8dcd072346ad087cf957be",
    "content": "文章很精彩",
    "post": "5c8dcf3a5fcbf1100c276648",
    "createAt": "2019-03-17T06:51:20.552Z"
}

4.2 获取评论列表

请求地址 请求方式
/comments GET
参数名称 是否必选 参数说明
page 页码
{
    "page": 1,
    "size": 10,
    "total": 1,
    "records": [
        {
            "state": 1,
            "_id": "5c8deda9481a8a3070377305",
            "author": {
                "role": "admin",
                "avatar": null,
                "status": 1,
                "_id": "5c8dcd072346ad087cf957be",
                "nickName": "coder",
                "email": "[email protected]",
                "createTime": "2019-03-17T04:28:55.780Z"
            },
            "content": "文章很精彩",
            "post": {
                "state": 1,
                "thumbnail": null,
                "_id": "5c8dcf3a5fcbf1100c276648",
                "title": "是单独发顺丰",
                "category": "5c8dbc2ded67612f8837e0db",
                "author": "5c8dcd072346ad087cf957be",
                "createAt": "2019-03-17T04:29:46.212Z",
                "updateAt": "2019-03-17T04:29:46.212Z"
            },
            "createAt": "2019-03-17T06:48:09.954Z"
        }
    ],
    "pages": 1,
    "display": [
        1
    ]
}

4.3 更改评论状态

请求地址 请求方式
/comments/:id PUT
参数名称 是否必选 参数说明
state 0或1
{
    "state": 0,
    "_id": "5c8deda9481a8a3070377305",
    "author": "5c8dcd072346ad087cf957be",
    "content": "文章很精彩",
    "post": "5c8dcf3a5fcbf1100c276648",
    "createAt": "2019-03-17T06:48:09.954Z"
}

4.4 查询评论数量

请求地址 请求方式
/comments/count GET
{
    "commentCount": 1
}

4.5 获取最新评论

请求地址 请求方式
/comments/lasted GET
[
    {
        "state": 0,
        "_id": "5c8f2e5f5cd7da32e093c506",
        "author": {
            "role": "admin",
            "avatar": null,
            "status": 1,
            "_id": "5c8dcd072346ad087cf957be",
            "nickName": "coder",
            "email": "[email protected]",
            "createTime": "2019-03-17T04:28:55.780Z"
        },
        "content": "万分精彩!!!!",
        "post": "5c8dcf3f5fcbf1100c27664a",
        "createAt": "2019-03-19T05:36:31.187Z"
    }
]

4.6 根据 id 删除评论

请求地址 请求方式
/comments/:id DELETE
{
    "state": 0,
    "_id": "5c8dee68f4ce931c2c4a0cc3",
    "author": "5c8dcd072346ad087cf957be",
    "content": "文章很精彩",
    "post": "5c8dcf3a5fcbf1100c276648",
    "createAt": "2019-03-17T06:51:20.552Z"
}

5. 网站设置

5.1 添加轮播图片

请求地址 请求方式
/slides POST
参数名称 是否必选 参数说明
title 轮播图标题
image 轮播图片
link 图片链接
{
    "image": "\\uploads\\upload_569f9bc4b04b4979c98a0264fbcff4de.jpg",
    "link": "#",
    "_id": "5c8e5b459a03f139683b3f53",
    "title": "测试标题"
}

5.2 获取轮播图列表

请求地址 请求方式
/slides GET
[
    {
        "image": "null",
        "link": "#",
        "_id": "5c8f1a16b332631efc6fc310",
        "title": "轮播图测试标题"
    }
]

5.3 删除轮播图片

请求地址 请求方式
/slides/:id DELETE
{
    "image": "/uploads/upload_5c84659382fdbe2cc505ff1c3ef0c134.jpg",
    "link": "#",
    "_id": "5c8e5e33ba71a93314d3c1eb",
    "title": "测试标题"
}

5.4 网站配置

请求地址 请求方式
/settings POST
参数名称 是否必选 参数说明
title 站点名称
comment 是否开启评论功能
review 评论必须经过人工审核
logo 网站图标
{
    "logo": null,
    "comment": true,
    "review": true,
    "_id": "5c8ed3e7c7f0701c34a63589",
    "title": "测试站点标题"
}

5.5 获取网站配置

请求地址 请求方式
/settings GET
{
    "logo": null,
    "comment": true,
    "review": true,
    "_id": "5c8ed3e7c7f0701c34a63589",
    "title": "测试站点标题"
}

6. 其他功能

图片文件上传

请求地址 请求方式
/upload POST
参数名称 是否必选 参数说明
avatar 图片文件
[
    {
        "avatar": "\\uploads\\upload_0f6e4b7e68007f2af2737ed873f6574e.png"
    }
]