diff --git a/api/v1/entries/testtask.php b/api/v1/entries/testtask.php new file mode 100644 index 0000000000..c1af138a25 --- /dev/null +++ b/api/v1/entries/testtask.php @@ -0,0 +1,32 @@ +loadController('testtask', 'view'); + $control->view($testtaskID); + + $data = $this->getData(); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(!isset($data->data->task)) $this->sendError(400, 'error'); + + $testtask = $data->data->task; + $this->send(200, $this->format($testtask, 'realFinishedDate:time')); + } + + public function delete($testtaskID) + { + $control = $this->loadController('testtask', 'delete'); + $control->delete($testtaskID, 'yes'); + + $this->getData(); + $this->sendSuccess(200, 'success'); + } +} diff --git a/api/v1/entries/testtasks.php b/api/v1/entries/testtasks.php new file mode 100644 index 0000000000..45ccf7ec10 --- /dev/null +++ b/api/v1/entries/testtasks.php @@ -0,0 +1,28 @@ +loadController('testtask', 'browse'); + $control->browse($this->param('productID', 0), $this->param('branch', ''), ($this->param('productID', 0) > 0 ? 'local' : 'all') . ',' . $this->param('status', 'totalStatus'), $this->param('order', 'date_desc'), $this->param('total', 0), $this->param('limit', 20), $this->param('page', 1), $this->param('begin', ''), $this->param('end', '')); + $data = $this->getData(); + + if(!isset($data->status)) return $this->sendError(400, 'error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + + $pager = $data->data->pager; + $result = array(); + foreach($data->data->tasks as $testtask) + { + $result[] = $this->format($testtask, 'realFinishedDate:time'); + } + return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'testtasks' => $result)); + } +} diff --git a/config/routes.php b/config/routes.php index 32ddd1ee81..5d6cd0301c 100644 --- a/config/routes.php +++ b/config/routes.php @@ -48,4 +48,7 @@ $routes['/products/:productID/issues'] = 'productIssues'; $routes['/todos'] = 'todos'; $routes['/todos/:id'] = 'todo'; +$routes['/testtasks'] = 'testtasks'; +$routes['/testtasks/:id'] = 'testtask'; + $config->routes = $routes; diff --git a/module/testtask/control.php b/module/testtask/control.php index a7e2f92673..d0bee2406a 100644 --- a/module/testtask/control.php +++ b/module/testtask/control.php @@ -285,7 +285,11 @@ class testtask extends control /* Get test task, and set menu. */ $taskID = (int)$taskID; $task = $this->testtask->getById($taskID, true); - if(!$task) die(js::error($this->lang->notFound) . js::locate('back')); + if(!$task) + { + if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'fail', 'message' => '404 Not found')); + die(js::error($this->lang->notFound) . js::locate('back')); + } /* When the session changes, you need to query the related products again. */ if($this->session->project != $task->project) $this->view->products = $this->products = $this->product->getProductPairsByProject($task->project); @@ -981,6 +985,7 @@ class testtask extends control $browseList = $this->createLink('testtask', 'browse', "productID=$task->product"); if($this->app->openApp == 'execution') $browseList = $this->createLink('execution', 'testtask', "executionID=$task->execution"); if($this->app->openApp == 'project') $browseList = $this->createLink('project', 'testtask', "projectID=$task->project"); + if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'success')); die(js::locate($browseList, 'parent')); } }