* Finish task#42101

This commit is contained in:
zenggang
2021-09-08 11:14:30 +08:00
parent 00a0484612
commit f5e33aee87
4 changed files with 112 additions and 1 deletions
+51
View File
@@ -0,0 +1,51 @@
<?php
/**
* 禅道API的build资源类
* 版本V1
*
* The build entry point of zentaopms
* Version 1
*/
class buildEntry extends Entry
{
public function get($buildID)
{
$control = $this->loadController('build', 'view');
$control->view($buildID);
$data = $this->getData();
if(!$data or (isset($data->status) and $data->message == '404 Not found')) return $this->send404();
if(isset($data->status) and $data->status == 'success') return $this->send(200, $data->data->build);
if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message);
$this->sendError(400, 'error');
}
public function put($buildID)
{
$old = $this->loadModel('build')->getByID($buildID);
/* Set $_POST variables. */
$fields = 'type,title,severity,pri,assignedTo,deadline,desc';
$this->batchSetPost($fields, $oldBuild);
$control = $this->loadController('build', 'edit');
$control->edit($buildID);
$data = $this->getData();
if(!$data or (isset($data->message) and $data->message == '404 Not found')) return $this->send404();
if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
$build = $this->build->getByID($buildID);
$this->send(200, $this->format($build, 'createdDate:time,editedDate:time,assignedDate:time'));
}
public function delete($buildID)
{
$control = $this->loadController('build', 'delete');
$control->delete($buildID, 'true');
$this->getData();
$this->sendSuccess(200, 'success');
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php
/**
* 禅道API的builds资源类
* 版本V1
*
* The builds entry point of zentaopms
* Version 1
*/
class buildsEntry extends entry
{
public function get($projectID = 0)
{
$control = $this->loadController('project', 'build');
$control->build($projectID, $this->param('type', 'all'), $this->param('param', 0));
$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);
$result = array();
foreach($data->data->projectBuilds as $productID => $builds)
{
foreach($builds as $build)
{
$result[] = $build;
}
}
return $this->send(200, $result);
}
public function post($projectID = 0)
{
$project = $this->loadModel('project')->getByID($projectID);
if(!$project) return $this->send404();
$fields = 'type,title,severity,pri,assignedTo,deadline,desc';
$this->batchSetPost($fields);
$control = $this->loadController('build', 'create');
$this->requireFields('type,title,severity');
$control->create($projectID);
$data = $this->getData();
if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
if(isset($data->result) and!isset($data->id)) return $this->sendError(400, $data->message);
$build = $this->loadModel('build')->getByID($data->id);
$this->send(201, $this->format($build, 'createdDate:time,editedDate:time,assignedDate:time'));
}
}
+4
View File
@@ -51,6 +51,10 @@ $routes['/issues/:issueID'] = 'issue';
$routes['/todos'] = 'todos';
$routes['/todos/:id'] = 'todo';
$routes['/projects/:projectID/builds'] = 'builds';
$routes['/builds'] = 'builds';
$routes['/builds/:id'] = 'build';
$routes['/testcases'] = 'testcases';
$routes['/testcases/:id'] = 'testcase';
+5 -1
View File
@@ -185,7 +185,11 @@ class build extends control
{
$buildID = (int)$buildID;
$build = $this->build->getByID($buildID, true);
if(!$build) die(js::error($this->lang->notFound) . js::locate('back'));
if(!$build)
{
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'));
}
$this->session->project = $build->project;
$this->loadModel('story');