+ my question api task#41820
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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'));
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user