mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-09 05:00:30 +08:00
add example code
This commit is contained in:
parent
6343355b66
commit
832f58baef
43
doc/build/api.html
vendored
43
doc/build/api.html
vendored
@ -71,6 +71,10 @@
|
||||
<li >
|
||||
<a href="#-group-add">/group/add</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#-group-list">/group/list</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
@ -148,16 +152,35 @@
|
||||
|
||||
|
||||
<div>返回示例:</div>
|
||||
<pre class="ydoc-example" data-foldnumber=10><code> <span class="token punctuation">{</span>
|
||||
<span class="token string">"errcode"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"errmsg"</span><span class="token punctuation">:</span> <span class="token string">'success'</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"data"</span><span class="token punctuation">:</span><span class="token punctuation">{</span>
|
||||
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"group_name"</span><span class="token punctuation">:</span> <span class="token string">"大数据4"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"group_desc"</span><span class="token punctuation">:</span> <span class="token string">"大数据4"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token string">"0"</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">}</span></code></pre>
|
||||
<pre class="ydoc-example" data-foldnumber=10><code><span class="token punctuation">{</span>
|
||||
<span class="token string">"errcode"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"errmsg"</span><span class="token punctuation">:</span> <span class="token string">"success"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"data"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
|
||||
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"group_name"</span><span class="token punctuation">:</span> <span class="token string">"大数据5"</span><span class="token punctuation">,</span>
|
||||
<span class="token string">"group_desc"</span><span class="token punctuation">:</span> <span class="token string">"大数据5"</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">}</span></code></pre>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="con-list-item">
|
||||
<blockquote class="api">
|
||||
<h3 id="-group-list" class="page-header subject">
|
||||
/group/list
|
||||
|
||||
<span class="ui-badge">get</span>
|
||||
|
||||
|
||||
<a class="hashlink" href="#-group-list">#</a>
|
||||
</h3>
|
||||
</blockquote>
|
||||
<p>
|
||||
<small class="text-muted">描述:</small>
|
||||
添加项目分组
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
@ -29,7 +29,7 @@
|
||||
import yapi from '../yapi.js'
|
||||
import baseController from './base.js'
|
||||
|
||||
|
||||
//
|
||||
class groupController extends baseController{
|
||||
constructor(ctx){
|
||||
super(ctx)
|
||||
@ -46,18 +46,7 @@ class groupController extends baseController{
|
||||
* @param {String} group_name 项目分组名称,不能为空
|
||||
* @param {String} [group_desc] 项目分组描述
|
||||
* @returns {Object}
|
||||
* @example
|
||||
* {
|
||||
* "errcode": 0,
|
||||
* "errmsg": 'success',
|
||||
* "data":{
|
||||
* "_id": 3,
|
||||
* "group_name": "大数据4",
|
||||
* "group_desc": "大数据4",
|
||||
* "uid": "0"
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @example ./api/group/add.json
|
||||
*/
|
||||
async add(ctx) {
|
||||
let params = ctx.request.body;
|
||||
@ -87,6 +76,16 @@ class groupController extends baseController{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
* @interface /group/list
|
||||
* @method get
|
||||
* @category group
|
||||
* @foldnumber 10
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
async list(ctx) {
|
||||
try{
|
||||
var groupInst = yapi.getInst(groupModel);
|
||||
|
@ -162,11 +162,12 @@ class projectController extends baseController {
|
||||
}
|
||||
|
||||
async list(ctx) {
|
||||
if(!ctx.request.query.group_id){
|
||||
let group_id = ctx.request.query.group_id;
|
||||
if(!group_id){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
|
||||
}
|
||||
try{
|
||||
let result = await this.Model.list();
|
||||
let result = await this.Model.list(group_id);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
}catch(err){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
@ -189,14 +190,43 @@ class projectController extends baseController {
|
||||
async up(ctx){
|
||||
try{
|
||||
let id = ctx.request.body.id;
|
||||
let params = ctx.request.body;
|
||||
|
||||
if(this.jungeMemberAuth(id, this.getUid()) !== true){
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
|
||||
}
|
||||
let data = {};
|
||||
ctx.request.body.project_name && (data.project_name = ctx.request.body.project_name)
|
||||
ctx.request.body.project_desc && (data.project_desc = ctx.request.body.project_desc)
|
||||
if(Object.keys(data).length ===0){
|
||||
ctx.body = yapi.commons.resReturn(null, 404, '分组名和分组描述都为空');
|
||||
|
||||
if(!params.name){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目名不能为空');
|
||||
}
|
||||
|
||||
let checkRepeat = await this.Model.checkNameRepeat(params.name);
|
||||
if(checkRepeat > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的项目名');
|
||||
}
|
||||
|
||||
if(!params.basepath){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目basepath不能为空');
|
||||
}
|
||||
if(!params.prd_host){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目domain不能为空');
|
||||
}
|
||||
|
||||
let checkRepeatDomain = await this.Model.checkDomainRepeat(params.prd_host, params.basepath);
|
||||
if(checkRepeatDomain > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在domain和basepath');
|
||||
}
|
||||
|
||||
|
||||
|
||||
let data= {
|
||||
name: params.name,
|
||||
desc: params.desc,
|
||||
prd_host: params.prd_host,
|
||||
basepath: params.basepath,
|
||||
uid: this.getUid(),
|
||||
up_time: yapi.commons.time(),
|
||||
env: params.env
|
||||
}
|
||||
let result = await this.Model.up(id, data);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
|
9
exampleCode/api/group/add.json
Normal file
9
exampleCode/api/group/add.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"errcode": 0,
|
||||
"errmsg": "success",
|
||||
"data": {
|
||||
"_id": 4,
|
||||
"group_name": "大数据5",
|
||||
"group_desc": "大数据5"
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ import groupModel from '../models/group.js'
|
||||
import yapi from '../yapi.js'
|
||||
import baseController from './base.js'
|
||||
|
||||
|
||||
//
|
||||
class groupController extends baseController{
|
||||
constructor(ctx){
|
||||
super(ctx)
|
||||
@ -19,18 +19,7 @@ class groupController extends baseController{
|
||||
* @param {String} group_name 项目分组名称,不能为空
|
||||
* @param {String} [group_desc] 项目分组描述
|
||||
* @returns {Object}
|
||||
* @example
|
||||
* {
|
||||
* "errcode": 0,
|
||||
* "errmsg": 'success',
|
||||
* "data":{
|
||||
* "_id": 3,
|
||||
* "group_name": "大数据4",
|
||||
* "group_desc": "大数据4",
|
||||
* "uid": "0"
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @example ./api/group/add.json
|
||||
*/
|
||||
async add(ctx) {
|
||||
let params = ctx.request.body;
|
||||
@ -60,6 +49,16 @@ class groupController extends baseController{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
* @interface /group/list
|
||||
* @method get
|
||||
* @category group
|
||||
* @foldnumber 10
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
async list(ctx) {
|
||||
try{
|
||||
var groupInst = yapi.getInst(groupModel);
|
||||
|
@ -135,11 +135,12 @@ class projectController extends baseController {
|
||||
}
|
||||
|
||||
async list(ctx) {
|
||||
if(!ctx.request.query.group_id){
|
||||
let group_id = ctx.request.query.group_id;
|
||||
if(!group_id){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
|
||||
}
|
||||
try{
|
||||
let result = await this.Model.list();
|
||||
let result = await this.Model.list(group_id);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
}catch(err){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
@ -162,14 +163,43 @@ class projectController extends baseController {
|
||||
async up(ctx){
|
||||
try{
|
||||
let id = ctx.request.body.id;
|
||||
let params = ctx.request.body;
|
||||
|
||||
if(this.jungeMemberAuth(id, this.getUid()) !== true){
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
|
||||
}
|
||||
let data = {};
|
||||
ctx.request.body.project_name && (data.project_name = ctx.request.body.project_name)
|
||||
ctx.request.body.project_desc && (data.project_desc = ctx.request.body.project_desc)
|
||||
if(Object.keys(data).length ===0){
|
||||
ctx.body = yapi.commons.resReturn(null, 404, '分组名和分组描述都为空');
|
||||
|
||||
if(!params.name){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目名不能为空');
|
||||
}
|
||||
|
||||
let checkRepeat = await this.Model.checkNameRepeat(params.name);
|
||||
if(checkRepeat > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的项目名');
|
||||
}
|
||||
|
||||
if(!params.basepath){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目basepath不能为空');
|
||||
}
|
||||
if(!params.prd_host){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目domain不能为空');
|
||||
}
|
||||
|
||||
let checkRepeatDomain = await this.Model.checkDomainRepeat(params.prd_host, params.basepath);
|
||||
if(checkRepeatDomain > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在domain和basepath');
|
||||
}
|
||||
|
||||
|
||||
|
||||
let data= {
|
||||
name: params.name,
|
||||
desc: params.desc,
|
||||
prd_host: params.prd_host,
|
||||
basepath: params.basepath,
|
||||
uid: this.getUid(),
|
||||
up_time: yapi.commons.time(),
|
||||
env: params.env
|
||||
}
|
||||
let result = await this.Model.up(id, data);
|
||||
ctx.body = yapi.commons.resReturn(result)
|
||||
|
@ -15,7 +15,7 @@ class projectModel extends baseModel{
|
||||
group_id: {type: Number, required: true},
|
||||
members: Array,
|
||||
prd_host: {type: String, required: true},
|
||||
env: Array,
|
||||
env: Object,
|
||||
add_time: Number,
|
||||
up_time: Number
|
||||
}
|
||||
@ -62,7 +62,7 @@ class projectModel extends baseModel{
|
||||
data.up_time = yapi.commons.time();
|
||||
return this.model.update({
|
||||
_id: id,
|
||||
}, data)
|
||||
}, data, { runValidators: true })
|
||||
}
|
||||
|
||||
addMember(id, uid){
|
||||
|
@ -46,6 +46,7 @@ var _base2 = _interopRequireDefault(_base);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
//
|
||||
var groupController = function (_baseController) {
|
||||
(0, _inherits3.default)(groupController, _baseController);
|
||||
|
||||
@ -67,18 +68,7 @@ var groupController = function (_baseController) {
|
||||
* @param {String} group_name 项目分组名称,不能为空
|
||||
* @param {String} [group_desc] 项目分组描述
|
||||
* @returns {Object}
|
||||
* @example
|
||||
* {
|
||||
* "errcode": 0,
|
||||
* "errmsg": 'success',
|
||||
* "data":{
|
||||
* "_id": 3,
|
||||
* "group_name": "大数据4",
|
||||
* "group_desc": "大数据4",
|
||||
* "uid": "0"
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @example ./api/group/add.json
|
||||
*/
|
||||
|
||||
|
||||
@ -155,6 +145,17 @@ var groupController = function (_baseController) {
|
||||
|
||||
return add;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
* @interface /group/list
|
||||
* @method get
|
||||
* @category group
|
||||
* @foldnumber 10
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'list',
|
||||
value: function () {
|
||||
|
@ -1,9 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var _keys = require('babel-runtime/core-js/object/keys');
|
||||
|
||||
var _keys2 = _interopRequireDefault(_keys);
|
||||
|
||||
var _regenerator = require('babel-runtime/regenerator');
|
||||
|
||||
var _regenerator2 = _interopRequireDefault(_regenerator);
|
||||
@ -479,42 +475,44 @@ var projectController = function (_baseController) {
|
||||
key: 'list',
|
||||
value: function () {
|
||||
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
|
||||
var result;
|
||||
var group_id, result;
|
||||
return _regenerator2.default.wrap(function _callee7$(_context7) {
|
||||
while (1) {
|
||||
switch (_context7.prev = _context7.next) {
|
||||
case 0:
|
||||
if (ctx.request.query.group_id) {
|
||||
_context7.next = 2;
|
||||
group_id = ctx.request.query.group_id;
|
||||
|
||||
if (group_id) {
|
||||
_context7.next = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组id不能为空'));
|
||||
|
||||
case 2:
|
||||
_context7.prev = 2;
|
||||
_context7.next = 5;
|
||||
return this.Model.list();
|
||||
case 3:
|
||||
_context7.prev = 3;
|
||||
_context7.next = 6;
|
||||
return this.Model.list(group_id);
|
||||
|
||||
case 5:
|
||||
case 6:
|
||||
result = _context7.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context7.next = 12;
|
||||
_context7.next = 13;
|
||||
break;
|
||||
|
||||
case 9:
|
||||
_context7.prev = 9;
|
||||
_context7.t0 = _context7['catch'](2);
|
||||
case 10:
|
||||
_context7.prev = 10;
|
||||
_context7.t0 = _context7['catch'](3);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
|
||||
|
||||
case 12:
|
||||
case 13:
|
||||
case 'end':
|
||||
return _context7.stop();
|
||||
}
|
||||
}
|
||||
}, _callee7, this, [[2, 9]]);
|
||||
}, _callee7, this, [[3, 10]]);
|
||||
}));
|
||||
|
||||
function list(_x8) {
|
||||
@ -577,51 +575,107 @@ var projectController = function (_baseController) {
|
||||
key: 'up',
|
||||
value: function () {
|
||||
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
|
||||
var id, data, result;
|
||||
var id, _params, checkRepeat, checkRepeatDomain, data, result;
|
||||
|
||||
return _regenerator2.default.wrap(function _callee9$(_context9) {
|
||||
while (1) {
|
||||
switch (_context9.prev = _context9.next) {
|
||||
case 0:
|
||||
_context9.prev = 0;
|
||||
id = ctx.request.body.id;
|
||||
_params = ctx.request.body;
|
||||
|
||||
if (!(this.jungeMemberAuth(id, this.getUid()) !== true)) {
|
||||
_context9.next = 4;
|
||||
_context9.next = 5;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
||||
|
||||
case 4:
|
||||
data = {};
|
||||
|
||||
ctx.request.body.project_name && (data.project_name = ctx.request.body.project_name);
|
||||
ctx.request.body.project_desc && (data.project_desc = ctx.request.body.project_desc);
|
||||
if ((0, _keys2.default)(data).length === 0) {
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 404, '分组名和分组描述都为空');
|
||||
case 5:
|
||||
if (_params.name) {
|
||||
_context9.next = 7;
|
||||
break;
|
||||
}
|
||||
_context9.next = 10;
|
||||
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目名不能为空'));
|
||||
|
||||
case 7:
|
||||
_context9.next = 9;
|
||||
return this.Model.checkNameRepeat(_params.name);
|
||||
|
||||
case 9:
|
||||
checkRepeat = _context9.sent;
|
||||
|
||||
if (!(checkRepeat > 0)) {
|
||||
_context9.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
|
||||
|
||||
case 12:
|
||||
if (_params.basepath) {
|
||||
_context9.next = 14;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目basepath不能为空'));
|
||||
|
||||
case 14:
|
||||
if (_params.prd_host) {
|
||||
_context9.next = 16;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目domain不能为空'));
|
||||
|
||||
case 16:
|
||||
_context9.next = 18;
|
||||
return this.Model.checkDomainRepeat(_params.prd_host, _params.basepath);
|
||||
|
||||
case 18:
|
||||
checkRepeatDomain = _context9.sent;
|
||||
|
||||
if (!(checkRepeatDomain > 0)) {
|
||||
_context9.next = 21;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
|
||||
|
||||
case 21:
|
||||
data = {
|
||||
name: _params.name,
|
||||
desc: _params.desc,
|
||||
prd_host: _params.prd_host,
|
||||
basepath: _params.basepath,
|
||||
uid: this.getUid(),
|
||||
up_time: _yapi2.default.commons.time(),
|
||||
env: _params.env
|
||||
};
|
||||
_context9.next = 24;
|
||||
return this.Model.up(id, data);
|
||||
|
||||
case 10:
|
||||
case 24:
|
||||
result = _context9.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context9.next = 17;
|
||||
_context9.next = 31;
|
||||
break;
|
||||
|
||||
case 14:
|
||||
_context9.prev = 14;
|
||||
case 28:
|
||||
_context9.prev = 28;
|
||||
_context9.t0 = _context9['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
|
||||
|
||||
case 17:
|
||||
case 31:
|
||||
case 'end':
|
||||
return _context9.stop();
|
||||
}
|
||||
}
|
||||
}, _callee9, this, [[0, 14]]);
|
||||
}, _callee9, this, [[0, 28]]);
|
||||
}));
|
||||
|
||||
function up(_x10) {
|
||||
|
@ -54,7 +54,7 @@ var projectModel = function (_baseModel) {
|
||||
group_id: { type: Number, required: true },
|
||||
members: Array,
|
||||
prd_host: { type: String, required: true },
|
||||
env: Array,
|
||||
env: Object,
|
||||
add_time: Number,
|
||||
up_time: Number
|
||||
};
|
||||
@ -107,7 +107,7 @@ var projectModel = function (_baseModel) {
|
||||
data.up_time = _yapi2.default.commons.time();
|
||||
return this.model.update({
|
||||
_id: id
|
||||
}, data);
|
||||
}, data, { runValidators: true });
|
||||
}
|
||||
}, {
|
||||
key: 'addMember',
|
||||
|
Loading…
Reference in New Issue
Block a user