-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3e4c3e5
Showing
30 changed files
with
1,614 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
write: true, | ||
prefix: '^', | ||
plugin: 'autod-egg', | ||
test: [ | ||
'test', | ||
'benchmark', | ||
], | ||
dep: [ | ||
'egg', | ||
'egg-scripts', | ||
], | ||
devdep: [ | ||
'egg-ci', | ||
'egg-bin', | ||
'egg-mock', | ||
'autod', | ||
'autod-egg', | ||
'eslint', | ||
'eslint-config-egg', | ||
'webstorm-disable-index', | ||
], | ||
exclude: [ | ||
'./test/fixtures', | ||
'./dist', | ||
], | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "eslint-config-egg", | ||
"rules": { | ||
"linebreak-style": [0, "error", "windows"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
logs/ | ||
npm-debug.log | ||
yarn-error.log | ||
node_modules/ | ||
package-lock.json | ||
yarn.lock | ||
coverage/ | ||
.idea/ | ||
run/ | ||
.DS_Store | ||
*.sw* | ||
*.un~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- '8' | ||
install: | ||
- npm i npminstall && npminstall | ||
script: | ||
- npm run ci | ||
after_script: | ||
- npminstall codecov && codecov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# restfulapi | ||
|
||
|
||
|
||
## QuickStart | ||
|
||
<!-- add docs here for user --> | ||
|
||
see [egg docs][egg] for more detail. | ||
|
||
### Development | ||
|
||
```bash | ||
$ npm i | ||
$ npm run dev | ||
$ open http://localhost:7001/ | ||
``` | ||
|
||
### Deploy | ||
|
||
```bash | ||
$ npm start | ||
$ npm stop | ||
``` | ||
|
||
### npm scripts | ||
|
||
- Use `npm run lint` to check code style. | ||
- Use `npm test` to run unit test. | ||
- Use `npm run autod` to auto detect dependencies upgrade, see [autod](https://www.npmjs.com/package/autod) for more detail. | ||
|
||
|
||
[egg]: https://eggjs.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
## RESTful API | ||
|
||
以下 api 路径均以 http://127.0.0.1:7001/api 为前缀 | ||
|
||
### role 昵称 && 权限 😊 | ||
|
||
| Method | Path | Controller.Action | | ||
| :----- | :-------- | :-------------------------- | | ||
| GET | /role | app.controller.role.index | | ||
| GET | /role/:id | app.controller.role.show | | ||
| POST | /role | app.controller.role.create | | ||
| PUT | /role/:id | app.controller.role.update | | ||
| DELETE | /role/:id | app.controller.role.destroy | | ||
| DELETE | /role | app.controller.role.removes | | ||
|
||
#### `GET /role` 用户管理首页 | ||
|
||
接受 get 参数 | ||
|
||
- pageSize Number 每一页数量 | ||
- currentPage Number 当前页数 | ||
- isPaging Boolean 是否分页 | ||
- search String 检索内容 | ||
实例:/api/role | ||
|
||
#### `GET /role/:id` 查看特定用户 | ||
|
||
接受 URL 参数 | ||
|
||
#### `POST /role` 新建昵称 | ||
|
||
接受 post 参数 | ||
|
||
- name String | ||
- access String | ||
- extra (可选项) 额外说明 | ||
|
||
#### `PUT /role/:id` 更新信息 | ||
|
||
接受 put 参数 | ||
|
||
- name | ||
- access | ||
|
||
### userAccess 用户登入/登出 😊 | ||
|
||
| Method | Path | Controller.Action | | ||
| :----- | :-------------------- | :--------------------------------- | | ||
| GET | /user/access/current | app.controller.userAccess.current | | ||
| GET | /user/access/logout | app.controller.userAccess.logout | | ||
| POST | /user/access/login | app.controller.userAccess.login | | ||
| PUT | /user/access/resetPwd | app.controller.userAccess.resetPwd | | ||
|
||
> Token Authorization: Bearer token / OAuth 2.0 | ||
#### `GET /user/access/current` 用户详情 | ||
|
||
示例:/api/user/access/current | ||
|
||
#### `GET /user/access/logout` 退出登录 | ||
|
||
#### `POST /user/access/login` 用户登入 | ||
|
||
接受 post 参数 | ||
|
||
- mobile 手机号 required | ||
- password 密码 required | ||
- realName 用户真实姓名 | ||
- avatar 用户头像 | ||
- role 权限、昵称信息 | ||
- extra | ||
|
||
> 暂未提供更换 avatar 接口 | ||
### user 用户管理 CRUD 😊 | ||
|
||
| Method | Path | Controller.Action | | ||
| :----- | :-------- | :-------------------------- | | ||
| GET | /user | app.controller.user.index | | ||
| GET | /user/:id | app.controller.user.show | | ||
| POST | /user | app.controller.user.create | | ||
| PUT | /user/:id | app.controller.user.update | | ||
| DELETE | /user/:id | app.controller.user.destroy | | ||
| DELETE | /user | app.controller.user.removes | | ||
|
||
### upload 文件上传 (🙃 暂无测试) | ||
|
||
| Method | Path | Controller.Action | | ||
| :----- | :---------------- | :----------------------------- | | ||
| GET | /upload | app.controller.upload.index | | ||
| GET | /upload/:id | app.controller.upload.show | | ||
| POST | /upload | app.controller.upload.create | | ||
| POST | /upload/url | app.controller.upload.url | | ||
| POST | /uploads | app.controller.upload.multiple | | ||
| PUT | /upload/:id | app.controller.upload.update | | ||
| PUT | /upload/:id/extra | app.controller.upload.extrs | | ||
| DELETE | /upload/:id | app.controller.upload.destroy | | ||
| DELETE | /upload | app.controller.upload.removes | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
const Controller = require('egg').Controller; | ||
|
||
class HomeController extends Controller { | ||
async index() { | ||
this.ctx.body = 'hi, egg'; | ||
} | ||
} | ||
|
||
module.exports = HomeController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use strict'; | ||
|
||
const Controller = require('egg').Controller; | ||
|
||
class RoleController extends Controller { | ||
constructor(ctx) { | ||
super(ctx); | ||
this.createRule = { | ||
name: { | ||
type: 'string', | ||
required: true, | ||
allowEmpty: false, | ||
}, | ||
access: { | ||
type: 'string', | ||
required: true, | ||
allowEmpty: false, | ||
}, | ||
}; | ||
} | ||
|
||
async create() { | ||
const { ctx, service } = this; | ||
ctx.validate(this.createRule); | ||
const payload = ctx.request.body || {}; | ||
|
||
const res = await service.role.create(payload); | ||
ctx.helper.success({ ctx, res }); | ||
} | ||
|
||
async destroy() { | ||
const { ctx, service } = this; | ||
const { id } = ctx.params; | ||
await service.role.destroy(id); | ||
ctx.helper.success({ ctx }); | ||
} | ||
|
||
async update() { | ||
const { ctx, service } = this; | ||
ctx.validate(this.createRule); | ||
const { id } = ctx.params; | ||
const payload = ctx.request.body || {}; | ||
|
||
await service.role.update(id, payload); | ||
ctx.helper.success({ ctx }); | ||
} | ||
|
||
async show() { | ||
const { ctx, service } = this; | ||
const { id } = ctx.params; | ||
const res = await service.role.show(id); | ||
|
||
ctx.helper.success({ ctx, res }); | ||
} | ||
|
||
async index() { | ||
const { ctx, service } = this; | ||
const payload = ctx.query; | ||
const res = await service.role.index(payload); | ||
|
||
ctx.helper.success({ ctx, res }); | ||
} | ||
|
||
async removes() { | ||
const { ctx, service } = this; | ||
// {id: '5a452a44ab122b16a0231b42,5a452a3bab122b16a0231b41'} | ||
const { id } = ctx.request.body; | ||
const payload = id.split(',') || []; | ||
await service.role.removes(payload); | ||
|
||
ctx.helper.success({ ctx }); | ||
} | ||
} | ||
|
||
module.exports = RoleController; |
Oops, something went wrong.