+ my question api task#41820

This commit is contained in:
zenggang
2021-08-25 14:49:11 +08:00
parent c45e3985d9
commit 6af6ae1ce0
3 changed files with 105 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
<?php
/**
* 禅道API的issue资源类
* 版本V1
*
* The issue entry point of zentaopms
* Version 1
*/
class issueEntry extends Entry
{
public function get($issueID)
{
$control = $this->loadController('issue', 'view');
$control->view($issueID);
$data = $this->getData();
if(!$data or (isset($data->message) and $data->message == '404 Not found')) return $this->send404();
if(isset($data->status) and $data->status == 'success') $this->send(200, $this->format($data->data->issue, 'createdDate:time,editedDate:time,assignedDate:time'));
if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message);
$this->sendError(400, 'error');
}
public function put($issueID)
{
$oldIssue = $this->loadModel('issue')->getByID($issueID);
/* Set $_POST variables. */
$fields = 'type,title,severity,pri,assignedTo,deadline,desc';
$this->batchSetPost($fields, $oldIssue);
$control = $this->loadController('issue', 'edit');
$control->edit($issueID);
$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);
$issue = $this->issue->getByID($issueID);
$this->send(200, $this->format($issue, 'createdDate:time,editedDate:time,assignedDate:time'));
}
public function delete($issueID)
{
$control = $this->loadController('issue', 'delete');
$control->delete($issueID, 'true');
$this->getData();
$this->sendSuccess(200, 'success');
}
}
+50
View File
@@ -0,0 +1,50 @@
<?php
/**
* 禅道API的issues资源类
* 版本V1
*
* The issues entry point of zentaopms
* Version 1
*/
class issuesEntry extends entry
{
public function get()
{
$control = $this->loadController('my', 'issue');
$control->issue($this->param('type', 'assignedTo'), $this->param('order', 'id_desc'), $this->param('total', 0), $this->param('limit', 20), $this->param('page', 1));
$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->issues as $issue)
{
$result[] = $this->format($issue, 'createdDate:time,editedDate:time,assignedDate:time');
}
return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'issues' => $result));
}
public function post($projectID = 0)
{
if((int) $projectID <= 0) $this->sendError(400, 'The id of project is wrong.');
$fields = 'type,title,severity,pri,assignedTo,deadline,desc';
$this->batchSetPost($fields);
$control = $this->loadController('issue', '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);
$issue = $this->loadModel('issue')->getByID($data->id);
$this->send(201, $this->format($issue, 'createdDate:time,editedDate:time,assignedDate:time'));
}
}
+4
View File
@@ -55,4 +55,8 @@ $routes['/projects/:project/risks'] = 'risks';
$routes['/risks'] = 'risks';
$routes['/risks/:id'] = 'risk';
$routes['/projects/:project/questions'] = 'issues';
$routes['/questions'] = 'issues';
$routes['/questions/:id'] = 'issue';
$config->routes = $routes;