From fecec4907f15e29d87e16ce16072d7065ed2f1ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E8=BE=B0=E8=BD=A9?= Date: Thu, 13 Oct 2022 13:35:55 +0800 Subject: [PATCH] * Finish testtask api create method. --- api/v1/entries/testtasks.php | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/api/v1/entries/testtasks.php b/api/v1/entries/testtasks.php index 81e2fb614c..1c77a0d9b1 100644 --- a/api/v1/entries/testtasks.php +++ b/api/v1/entries/testtasks.php @@ -66,4 +66,42 @@ class testtasksEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'testtasks' => $result)); } + + /** + * POST method. + * + * @access public + * @return void + */ + public function post($projectID = 0) + { + if(!$projectID) $projectID = $this->param('project', 0); + + $productID = $this->request('product', 0); + $executionID = $this->request('execution', 0); + $buildID = $this->request('build', 0); + if(empty($productID)) return $this->sendError(400, 'need product id!'); + if(empty($executionID)) return $this->sendError(400, 'need execution id!'); + if(empty($buildID)) return $this->sendError(400, 'need build id!'); + + /* Check whether executionID and buildID is valid. */ + $executions = $this->loadModel('product')->getExecutionPairsByProduct($productID, '', 'id_desc', $projectID); + $builds = $this->loadModel('build')->getBuildPairs($productID, 'all', 'notrunk'); + if(!isset($executions[$executionID])) return $this->sendError(400, 'error execution id!'); + if(!isset($builds[$buildID])) return $this->sendError(400, 'error build id!'); + + $fields = 'product,execution,build,name,begin,end,owner,type,pri,status,desc'; + $this->batchSetPost($fields); + + $control = $this->loadController('testtask', 'create'); + $this->requireFields('name,begin,end'); + $control->create($productID, $executionID, $build, $projectID); + + $data = $this->getData(); + if(!isset($data->id)) return $this->sendError(400, $data->message); + + $testtask = $this->loadModel('testtask')->getByID($data->id); + + $this->send(201, $testtask); + } }