* Optimize api getListByModuleID function and finish unit test script.
This commit is contained in:
@@ -83,7 +83,7 @@ class api extends control
|
||||
$this->view->objectID = $objectID;
|
||||
$this->view->moduleID = $moduleID;
|
||||
$this->view->version = $version;
|
||||
$this->view->apiList = $browseType == 'bySearch' ? $this->api->getApiListBySearch($libID, $queryID, '', array_keys($libs)) : $this->api->getListByModuleId($libID, $moduleID, $release);
|
||||
$this->view->apiList = $browseType == 'bySearch' ? $this->api->getApiListBySearch($libID, $queryID, '', array_keys($libs)) : $this->api->getListByModuleID($libID, $moduleID, $release);
|
||||
$this->view->libTree = $this->doc->getLibTree($libID, $libs, 'api', $moduleID, $objectID, $browseType, (int)$param);
|
||||
$this->view->objectDropdown = isset($libs[$libID]) ? $this->apiZen->generateLibsDropMenu($libs[$libID], $release) : '';
|
||||
$this->view->spaceType = 'api';
|
||||
|
||||
+20
-20
@@ -375,33 +375,35 @@ class apiModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* Get api doc list by module id.
|
||||
* 根据发布ID或者模块ID获取接口列表。
|
||||
* Get api doc list by module id or release id.
|
||||
*
|
||||
* @param int $libID
|
||||
* @param int $moduleID
|
||||
* @param int $release
|
||||
* @param int $releaseID
|
||||
* @param object $pager
|
||||
* @return array $list
|
||||
* @return array
|
||||
*/
|
||||
public function getListByModuleId($libID = 0, $moduleID = 0, $release = 0, $pager = null)
|
||||
public function getListByModuleID(int $libID = 0, int $moduleID = 0, int $releaseID = 0, object $pager = null): array
|
||||
{
|
||||
/* Get release info. */
|
||||
if($release > 0)
|
||||
if($releaseID > 0)
|
||||
{
|
||||
$rel = $this->getRelease(0, 'byID', $release);
|
||||
/* 根据发布ID获取发信息。 */
|
||||
$release = $this->getRelease(0, 'byID', $releaseID);
|
||||
|
||||
$where = "1=1 and lib = $libID ";
|
||||
if($moduleID > 0 and isset($rel->snap['modules']))
|
||||
$where = "1 = 1 and lib = $libID ";
|
||||
if($moduleID > 0 && isset($release->snap['modules']))
|
||||
{
|
||||
$sub = array();
|
||||
foreach($rel->snap['modules'] as $module)
|
||||
foreach($release->snap['modules'] as $module)
|
||||
{
|
||||
$tmp = explode(',', $module['path']);
|
||||
if(in_array($moduleID, $tmp)) $sub[] = $module['id'];
|
||||
}
|
||||
if($sub) $where .= 'and module in (' . implode(',', $sub) . ')';
|
||||
}
|
||||
$list = $this->getApiListByRelease($rel, $where);
|
||||
$apiList = $this->getApiListByRelease($release, $where);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -414,17 +416,15 @@ class apiModel extends model
|
||||
{
|
||||
$where = 'lib = ' . $libID;
|
||||
}
|
||||
$list = $this->dao->select('*')->from(TABLE_API)->where($where)
|
||||
->andWhere('deleted')->eq(0)
|
||||
->page($pager)
|
||||
->fetchAll();
|
||||
$apiList = $this->dao->select('*')->from(TABLE_API)->where($where)->andWhere('deleted')->eq(0)->page($pager)->fetchAll();
|
||||
}
|
||||
array_map(function ($item) {
|
||||
$item->params = json_decode($item->params, true);
|
||||
$item->response = json_decode($item->response, true);
|
||||
return $item;
|
||||
}, $list);
|
||||
return $list;
|
||||
|
||||
foreach($apiList as $api)
|
||||
{
|
||||
$api->params = json_decode($api->params, true);
|
||||
$api->response = json_decode($api->response, true);
|
||||
}
|
||||
return $apiList;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,25 +1,43 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/api.class.php';
|
||||
su('admin');
|
||||
|
||||
zdTable('module')->config('module')->gen(10);
|
||||
zdTable('api')->config('api')->gen(50);
|
||||
zdTable('apispec')->gen(100);
|
||||
zdTable('api_lib_release')->gen(10);
|
||||
|
||||
/**
|
||||
|
||||
title=测试 apiModel->getListByModuleId();
|
||||
title=测试 apiModel->getListByModuleID();
|
||||
timeout=0
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
通过正常的libID、moduleID、releaseID查询api信息 >> 获取反馈列表
|
||||
通过正常的libID、moduleID,不传releaseID,查询api信息 >> 0
|
||||
通过正常的libID,不传moduleID、releaseID查询api信息 >> 0
|
||||
通过不存在的libID,moduleID,releaseID查询api信息 >> 0
|
||||
- 测试不传参数时获取的文档列表。 @0
|
||||
- 测试获取文档库ID为1的文档列表。
|
||||
- 第0条的id属性 @1
|
||||
- 第0条的title属性 @BUG接口1
|
||||
- 第0条的path属性 @bug-getList
|
||||
- 第0条的status属性 @doing
|
||||
- 测试获取文档库ID为1并且模块ID为1的文档列表。
|
||||
- 第0条的id属性 @1
|
||||
- 第0条的title属性 @BUG接口1
|
||||
- 第0条的path属性 @bug-getList
|
||||
- 第0条的status属性 @doing
|
||||
- 测试获取文档库ID为1并且发布ID为1的文档列表。
|
||||
- 第0条的id属性 @1
|
||||
- 第0条的title属性 @BUG接口1
|
||||
- 第0条的path属性 @bug-getList
|
||||
- 第0条的status属性 @doing
|
||||
|
||||
*/
|
||||
|
||||
$api = new apiTest();
|
||||
global $tester;
|
||||
$tester->loadModel('api');
|
||||
|
||||
r($api->getListByModuleIdTest(1950, 6392, 1)) && p('title') && e('获取反馈列表'); //通过正常的libID、moduleID、releaseID查询api信息
|
||||
r($api->getListByModuleIdTest(1950, 6396, 0)) && p('title') && e('0'); //通过正常的libID、moduleID,不传releaseID,查询api信息
|
||||
r($api->getListByModuleIdTest(1, 0, 0)) && p('title') && e('0'); //通过正常的libID,不传moduleID、releaseID查询api信息
|
||||
r($api->getListByModuleIdTest(0, 0, 0)) && p('title') && e('0'); //通过不存在的libID,moduleID,releaseID查询api信息
|
||||
$release = new stdclass();
|
||||
r($tester->api->getListByModuleID()) && p() && e('0'); // 测试不传参数时获取的文档列表。
|
||||
r($tester->api->getListByModuleID(1)) && p('0:id,title,path,status') && e('1,BUG接口1,bug-getList,doing'); // 测试获取文档库ID为1的文档列表。
|
||||
r($tester->api->getListByModuleID(1, 1)) && p('0:id,title,path,status') && e('1,BUG接口1,bug-getList,doing'); // 测试获取文档库ID为1并且模块ID为1的文档列表。
|
||||
r($tester->api->getListByModuleID(1, 1, 1)) && p('0:id,title,path,status') && e('1,BUG接口1,bug-getList,doing'); // 测试获取文档库ID为1并且发布ID为1的文档列表。
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
title: zt_api
|
||||
author: Yuting Wang
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: module
|
||||
note: "所属模块"
|
||||
range: 1{1}, 0{99}
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
Reference in New Issue
Block a user