# node-nest **Repository Path**: liu0716/node ## Basic Information - **Project Name**: node-nest - **Description**: 使用 nestjs 开发项目 - **Primary Language**: NodeJS - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-02-25 - **Last Updated**: 2023-05-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 接口文档 ```http http://localhost:3000/api ``` ## 统一说明 以下说明在本套接口中通用。 - URL 动态参数 | 参数 | 默认值 | 说明 | 必传 | | :--: | :----: | :-----: | :--: | | :id | 空 | 用户 id | 是 | - 接口返回数据结构 ```ts interface Response { message: string code: number success: boolean data: {} | null | unknown } ``` - 分页 - URL 参数 | 参数 | 默认值 | 说明 | | :-------: | :----: | :------: | | pageIndex | 1 | 当前页数 | | pageSize | 10 | 数据条数 | - 例子 ```http http://localhost:3000/list?pageIndex=1&pageSize=10 ``` - 授权认证 - headers 头信息参数 | 参数 | 类型 | 说明 | 必传 | | :-----------: | :----: | :------------------: | :--: | | Authorization | string | 用户登录返回的 token | Y | ## 登录相关 ### 登录 => `/auth/login` - 接口类型:【`POST`】 - body | 参数 | 类型 | 说明 | 必传 | | :------: | :----: | :----: | :--: | | username | string | 用户名 | Y | | password | string | 密码 | Y | ### 注册 => `/auth/register` - 接口类型:【`POST`】 - body | 参数 | 类型 | 说明 | 必传 | | :------: | :----: | :----: | :--: | | username | string | 用户名 | Y | | password | string | 密码 | Y | | nickname | string | 昵称 | N | ## 用户相关 ### 获取用户信息 => `/user/:id/get` - 需要验证:【`Authorization`】 - 接口类型:【`GET`】 ### 修改用户信息 => `/user/:id/update` - 需要验证:【`Authorization`】 - 接口类型:【`PUT`】 - body | 参数 | 类型 | 说明 | 必传 | | :---------: | :----: | :----: | :--: | | age | number | 年龄 | N | | sex | number | 性别 | N | | mobile | string | 手机号 | N | | email | string | 邮箱 | N | | nickname | string | 昵称 | N | | avatar | string | 头像 | N | | description | string | 说明 | N | ### 关注用户 => `/user/:id/follow` - 需要验证:【`Authorization`】 - 接口类型:【`GET`】 - 参数 | 参数 | 类型 | 说明 | 必传 | | :--: | :----: | :-----------: | :--: | | :id | string | 关注的用户 id | N | ### 取消关注用户 => `/user/:id/unfollow` - 需要验证:【`Authorization`】 - 接口类型:【`GET`】 - 参数 | 参数 | 类型 | 说明 | 必传 | | :--: | :----: | :-----------: | :--: | | :id | string | 关注的用户 id | N | ### 用户关注列表 => `/user/:id/follows` - 需要验证:【`Authorization`】 - 接口类型:【`GET`】 ### 用户评论列表 => `/user/:id/comments` - 需要验证:【`Authorization`】 - 接口类型:【`GET`】 ### 收藏文章列表 => `/user/:id/star` - 需要验证:【`Authorization`】 - 接口类型:【`GET`】 ## 新闻文章 ### 文章列表 => `/post` - 接口类型:【`GET`】 - 参数 | 参数 | 类型 | 说明 | 必传 | | :------: | :----: | :-----: | :--: | | category | string | 栏目 id | N | - 例子 ```http http://localhost:3000/post/get?pageIndex=1&pageSize=2&category=8 ``` ### 搜索文章 => `/post/search` - 接口类型:【`GET`】 - 参数 | 参数 | 默认值 | 说明 | 必传 | | :-----: | :----: | :--------: | :--: | | keyword | string | 搜索关键字 | N | - 例子 ```http http://localhost:3000/post/search?keyword=美女&pageIndex=1&pageSize=2 ``` ### 搜索推荐 => `/post/search/recommend` - 接口类型:【`GET`】 - 参数 | 参数 | 默认值 | 必传 | 说明 | | ------- | ------ | ---- | ---------- | | keyword | 空 | 否 | 搜索关键字 | - 例子 ```http http://localhost:3000/post/search/recommend?keyword=美女 ``` ### 文章详情 => `/post/:id/get` - 接口类型:【`GET`】 - 参数 | 参数 | 类型 | 说明 | 必传 | | :--: | :----: | :-----: | :--: | | :id | string | 文章 id | N | - 例子 ```http http://localhost:3000/post/1/get ``` ### 评论列表 => `/post/:id/comment` - 接口类型:【`GET`】 - 参数 | 参数 | 类型 | 说明 | 必传 | | ---- | ------ | ------- | ---- | | :id | string | 文章 id | N | - 例子 ```http http://localhost:3000/post/1/comment ``` ### 发布评论 => `/post/:id/comment` - 需要验证:【`Authorization`】 - 接口类型:【`POST`】 - 参数 | 参数 | 类型 | 说明 | 必传 | | :-------: | :----: | :------: | :--: | | :id | string | 文章 id | Y | | content | string | 评论内容 | Y | | parent_id | string | 回复 id | N | ### 收藏文章 => `/post/:id/star` - 需要验证:【`Authorization`】 - 接口类型:【`GET`】 - 参数 | 参数 | 默认值 | 说明 | 必传 | | :--: | :----: | :-----: | :--: | | :id | string | 文章 id | 是 | ### 点赞文章 => `/post/:id/like` - 需要验证:【`Authorization`】 - 接口类型:【`GET`】 - 参数 | 参数 | 默认值 | 说明 | 必传 | | :--: | :----: | :-----: | :--: | | :id | 空 | 文章 id | 是 | ### 发布文章 => `/post` `管理后台使用,该接口栏目和封面图片参数可优化` - 需要验证:【`Authorization`】 - 接口类型:【`POST`】 - 参数 | 参数 | 类型 | 说明 | 必传 | | :------: | :----: | :---------------------------------: | :--: | | title | string | 文章标题 | N | | content | string | 文章内容 | N | | category | Array | 所属栏目 ID 集合 | N | | cover | array | 封面图片 ID 和完整的 url 路径的集合 | N | | type | number | 1 为文章,2 为视频 | N | - 例子 ```js $.ajax({ data: { title: '标题', content: '内容', category: [8, 9, 10], cover: [ 'http://localhost:3000//uploads/image/IMG1581694846074.jpeg', 'http://localhost:3000//uploads/image/IMG1581694846074.jpeg', 'http://localhost:3000//uploads/image/IMG1581694846074.jpeg' ], type: 2 } }) ``` ### 编辑文章 => `/post` `管理后台使用,该接口栏目和封面图片参数可优化` - 需要验证:【`Authorization`】 - 接口类型:【`PUT`】 - 参数 | 参数 | 默认值 | 说明 | 必传 | | :------: | :----: | :----------------: | :--: | | :id | string | 文章 | N | | title | string | 文章标题 | N | | content | string | 文章内容 | N | | category | Array | 所属栏目 ID 集合 | N | | cover | Array | 封面图片 ID 集合 | N | | type | number | 1 为文章,2 为视频 | N | ## 文件上传 => `/post/upload` - 需要验证:【`Authorization`】 - 接口类型:【`POST`】 `tex` - 参数 | 参数 | 类型 | 说明 | 必传 | | :--: | :--: | :------: | :--: | | file | File | 文件资源 | 是 | - 返回 ```json { "data": { "url": "/uploads/image/IMG1568820150584.jpeg", "uid": 11, "id": 11 } } ``` ## 栏目 ### 栏目列表 => `/category` > 该接口**不强制要求登录,但是对于登录的用户,加上验证信息会返回该用户关注的栏目文章** - 验证:【`Authorization`】 - 接口类型:【`GET`】 - 字段说明 | 字段名 | 说明 | | :----: | :------: | | is_top | 是否热门 | - 返回 ```json { "data": [ { "id": 999, "name": "头条", "is_top": 1 }, { "id": 1, "name": "热点", "is_top": 1 }, { "id": 11, "name": "女人", "is_top": 0 } ] } ``` ### 添加栏目 => `/category` - 需要验证:【`Authorization`】 - 接口类型:【`POST`】 - 参数 | 参数 | 默认值 | 说明 | 必传 | | :----: | :----: | :------: | :--: | | name | string | 栏目名字 | Y | | is_top | number | 是否热门 | N |