Start to improve task Api operations and doc

This commit is contained in:
Frédéric Guillot
2014-09-05 18:57:58 -07:00
parent a0dcfc9e4c
commit 532ea3b868
6 changed files with 347 additions and 38 deletions

View File

@@ -428,7 +428,7 @@ class Task extends Base
// Fetch original task // Fetch original task
$original_task = $this->getById($values['id']); $original_task = $this->getById($values['id']);
if ($original_task === false) { if (! $original_task) {
return false; return false;
} }
@@ -730,14 +730,10 @@ class Task extends Base
$v = new Validator($values, array( $v = new Validator($values, array(
new Validators\Required('id', t('The id is required')), new Validators\Required('id', t('The id is required')),
new Validators\Integer('id', t('This value must be an integer')), new Validators\Integer('id', t('This value must be an integer')),
new Validators\Required('color_id', t('The color is required')),
new Validators\Required('project_id', t('The project is required')),
new Validators\Integer('project_id', t('This value must be an integer')), new Validators\Integer('project_id', t('This value must be an integer')),
new Validators\Required('column_id', t('The column is required')),
new Validators\Integer('column_id', t('This value must be an integer')), new Validators\Integer('column_id', t('This value must be an integer')),
new Validators\Integer('owner_id', t('This value must be an integer')), new Validators\Integer('owner_id', t('This value must be an integer')),
new Validators\Integer('score', t('This value must be an integer')), new Validators\Integer('score', t('This value must be an integer')),
new Validators\Required('title', t('The title is required')),
new Validators\MaxLength('title', t('The maximum length is %d characters', 200), 200), new Validators\MaxLength('title', t('The maximum length is %d characters', 200), 200),
new Validators\Date('date_due', t('Invalid date'), $this->getDateFormats()), new Validators\Date('date_due', t('Invalid date'), $this->getDateFormats()),
)); ));

View File

@@ -211,60 +211,344 @@ Procedures
### createTask ### createTask
- Purpose: **Create a new task** - Purpose: **Create a new task**
- Parameters: Key/value pair composed of the **title** (string), **description** (string, optional), **color_id** (string), **project_id** (integer), **column_id** (integer), **owner_id** (integer, optional), **score** (integer, optional), **date_due** (integer, optional), **category_id** (integer, optional) - Parameters:
- **title** (string, required)
- **color_id** (string, required)
- **project_id** (integer, required)
- **column_id** (integer, required)
- **description** (string, optional)
- **owner_id** (integer, optional)
- **creator_id** (integer, optional)
- **score** (integer, optional)
- **date_due**: ISO8601 format (string, optional)
- **category_id** (integer, optional)
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
{
"jsonrpc": "2.0",
"method": "createTask",
"id": 1176509098,
"params": {
"owner_id": 1,
"creator_id": 0,
"date_due": "",
"description": "",
"category_id": 0,
"score": 0,
"title": "Test",
"project_id": 1,
"color_id": "green",
"column_id": 2
}
}
```
Response example:
```json
{
"jsonrpc": "2.0",
"id": 1176509098,
"result": true
}
```
### getTask ### getTask
- Purpose: **Get task information** - Purpose: **Get task information**
- Parameters: **task_id** (integer) - Parameters:
- **task_id** (integer, required)
- Result on success: **task properties** - Result on success: **task properties**
- Result on failure: **null** - Result on failure: **null**
Request example:
```json
{
"jsonrpc": "2.0",
"method": "getTask",
"id": 700738119,
"params": {
"task_id": 1
}
}
```
Response example:
```json
{
"jsonrpc": "2.0",
"id": 700738119,
"result": {
"id": "1",
"title": "Task #1",
"description": "",
"date_creation": "1409963206",
"color_id": "blue",
"project_id": "1",
"column_id": "2",
"owner_id": "1",
"position": "1",
"is_active": "1",
"date_completed": null,
"score": "0",
"date_due": "0",
"category_id": "0",
"creator_id": "0",
"date_modification": "1409963206"
}
}
```
### getAllTasks ### getAllTasks
- Purpose: **Get all available tasks** - Purpose: **Get all available tasks**
- Parameters: **project_id** (integer) - Parameters:
- **project_id** (integer, required)
- **status**: List of status id, the value 1 for active tasks and 0 for inactive (list, required)
- Result on success: **List of tasks** - Result on success: **List of tasks**
- Result on failure: **false** - Result on failure: **false**
Request example to fetch all tasks on the board:
```json
{
"jsonrpc": "2.0",
"method": "getAllTasks",
"id": 133280317,
"params": {
"project_id": 1,
"status": [
1
]
}
}
```
Response example:
```json
{
"jsonrpc": "2.0",
"id": 133280317,
"result": [
{
"id": "1",
"title": "Task #1",
"description": "",
"date_creation": "1409961789",
"color_id": "blue",
"project_id": "1",
"column_id": "2",
"owner_id": "1",
"position": "1",
"is_active": "1",
"date_completed": null,
"score": "0",
"date_due": "0",
"category_id": "0",
"creator_id": "0",
"date_modification": "1409961789"
},
{
"id": "2",
"title": "Test",
"description": "",
"date_creation": "1409962115",
"color_id": "green",
"project_id": "1",
"column_id": "2",
"owner_id": "1",
"position": "2",
"is_active": "1",
"date_completed": null,
"score": "0",
"date_due": "0",
"category_id": "0",
"creator_id": "0",
"date_modification": "1409962115"
},
...
]
}
```
### updateTask ### updateTask
- Purpose: **Update a task** - Purpose: **Update a task**
- Parameters: Key/value pair composed of the **id** (integer), **title** (string), **description** (string, optional), **color_id** (string), **project_id** (integer), **column_id** (integer), **owner_id** (integer, optional), **score** (integer, optional), **date_due** (integer, optional), **category_id** (integer, optional) - Parameters:
- **id** (integer, required)
- **title** (string, optional)
- **color_id** (string, optional)
- **project_id** (integer, optional)
- **column_id** (integer, optional)
- **description** (string, optional)
- **owner_id** (integer, optional)
- **creator_id** (integer, optional)
- **score** (integer, optional)
- **date_due**: ISO8601 format (string, optional)
- **category_id** (integer, optional)
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example to change the task color:
```json
{
"jsonrpc": "2.0",
"method": "updateTask",
"id": 1406803059,
"params": {
"id": 1,
"color_id": "blue"
}
}
```
Response example:
```json
{
"jsonrpc": "2.0",
"id": 1406803059,
"result": true
}
```
### openTask ### openTask
- Purpose: **Set a task to the status open** - Purpose: **Set a task to the status open**
- Parameters: **task_id** (integer) - Parameters:
- **task_id** (integer, required)
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
{
"jsonrpc": "2.0",
"method": "openTask",
"id": 1888531925,
"params": {
"task_id": 1
}
}
```
Response example:
```json
{
"jsonrpc": "2.0",
"id": 1888531925,
"result": true
}
```
### closeTask ### closeTask
- Purpose: **Set a task to the status close** - Purpose: **Set a task to the status close**
- Parameters: **task_id** (integer) - Parameters:
- **task_id** (integer, required)
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
{
"jsonrpc": "2.0",
"method": "closeTask",
"id": 1654396960,
"params": {
"task_id": 1
}
}
```
Response example:
```json
{
"jsonrpc": "2.0",
"id": 1654396960,
"result": true
}
```
### removeTask ### removeTask
- Purpose: **Remove a task** - Purpose: **Remove a task**
- Parameters: **task_id** (integer) - Parameters:
- **task_id** (integer, required)
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
{
"jsonrpc": "2.0",
"method": "removeTask",
"id": 1423501287,
"params": {
"task_id": 1
}
}
```
Response example:
```json
{
"jsonrpc": "2.0",
"id": 1423501287,
"result": true
}
```
### moveTaskPosition ### moveTaskPosition
- Purpose: **Move a task to another column or another position** - Purpose: **Move a task to another column or another position**
- Parameters: **project_id** (integer), **task_id** (integer), **column_id** (integer), **position** (integer) - Parameters:
- **project_id** (integer, required)
- **task_id** (integer, required)
- **column_id** (integer, required)
- **position** (integer, required)
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
{
"jsonrpc": "2.0",
"method": "moveTaskPosition",
"id": 117211800,
"params": {
"project_id": 1,
"task_id": 1,
"column_id": 2,
"position": 1
}
}
```
Response example:
```json
{
"jsonrpc": "2.0",
"id": 117211800,
"result": true
}
```
### createUser ### createUser

View File

@@ -116,7 +116,21 @@ $server->register('allowUser', function($project_id, $user_id) use ($project) {
/** /**
* Task procedures * Task procedures
*/ */
$server->register('createTask', function(array $values) use ($task) { $server->register('createTask', function($title, $project_id, $color_id, $column_id, $owner_id = 0, $creator_id = 0, $date_due = '', $description = '', $category_id = 0, $score = 0) use ($task) {
$values = array(
'title' => $title,
'project_id' => $project_id,
'color_id' => $color_id,
'column_id' => $column_id,
'owner_id' => $owner_id,
'creator_id' => $creator_id,
'date_due' => $date_due,
'description' => $description,
'category_id' => $category_id,
'score' => $score,
);
list($valid,) = $task->validateCreation($values); list($valid,) = $task->validateCreation($values);
return $valid && $task->create($values) !== false; return $valid && $task->create($values) !== false;
}); });
@@ -129,8 +143,29 @@ $server->register('getAllTasks', function($project_id, array $status) use ($task
return $task->getAll($project_id, $status); return $task->getAll($project_id, $status);
}); });
$server->register('updateTask', function($values) use ($task) { $server->register('updateTask', function($id, $title = null, $project_id = null, $color_id = null, $column_id = null, $owner_id = null, $creator_id = null, $date_due = null, $description = null, $category_id = null, $score = null) use ($task) {
list($valid,) = $task->validateModification($values);
$values = array(
'id' => $id,
'title' => $title,
'project_id' => $project_id,
'color_id' => $color_id,
'column_id' => $column_id,
'owner_id' => $owner_id,
'creator_id' => $creator_id,
'date_due' => $date_due,
'description' => $description,
'category_id' => $category_id,
'score' => $score,
);
foreach ($values as $key => $value) {
if (is_null($value)) {
unset($values[$key]);
}
}
list($valid) = $task->validateModification($values);
return $valid && $task->update($values); return $valid && $task->update($values);
}); });

View File

@@ -11,7 +11,7 @@ class Api extends PHPUnit_Framework_TestCase
public function setUp() public function setUp()
{ {
$this->client = new JsonRPC\Client(self::URL, 5, true); $this->client = new JsonRPC\Client(self::URL);
$this->client->authentication('jsonrpc', self::KEY); $this->client->authentication('jsonrpc', self::KEY);
$pdo = new PDO('sqlite:data/db.sqlite'); $pdo = new PDO('sqlite:data/db.sqlite');
@@ -132,7 +132,7 @@ class Api extends PHPUnit_Framework_TestCase
'column_id' => 2, 'column_id' => 2,
); );
$this->assertTrue($this->client->createTask($task)); $this->assertTrue($this->client->execute('createTask', $task));
$task = array( $task = array(
'title' => 'Task #1', 'title' => 'Task #1',
@@ -140,7 +140,7 @@ class Api extends PHPUnit_Framework_TestCase
'owner_id' => 1, 'owner_id' => 1,
); );
$this->assertFalse($this->client->createTask($task)); $this->assertNull($this->client->createTask($task));
} }
public function testGetTask() public function testGetTask()
@@ -175,7 +175,7 @@ class Api extends PHPUnit_Framework_TestCase
$task['description'] = 'test'; $task['description'] = 'test';
$task['date_due'] = ''; $task['date_due'] = '';
$this->assertTrue($this->client->updateTask($task)); $this->assertTrue($this->client->execute('updateTask', $task));
} }
public function testRemoveTask() public function testRemoveTask()
@@ -278,7 +278,7 @@ class Api extends PHPUnit_Framework_TestCase
'column_id' => 1, 'column_id' => 1,
); );
$this->assertTrue($this->client->createTask($task)); $this->assertTrue($this->client->execute('createTask', $task));
$comment = array( $comment = array(
'task_id' => 1, 'task_id' => 1,
@@ -407,8 +407,15 @@ class Api extends PHPUnit_Framework_TestCase
'column_id' => 1, 'column_id' => 1,
); );
$this->assertTrue($this->client->createTask($task)); $this->assertTrue($this->client->execute('createTask', $task));
$this->assertTrue($this->client->moveTaskPosition(1, 2, 3, 1)); $this->assertTrue($this->client->moveTaskPosition(1, 1, 3, 1));
$task = $this->client->getTask(1);
$this->assertNotFalse($task);
$this->assertTrue(is_array($task));
$this->assertEquals(1, $task['position']);
$this->assertEquals(3, $task['column_id']);
} }
} }

View File

@@ -27,14 +27,6 @@ class Client
*/ */
private $timeout; private $timeout;
/**
* Debug flag
*
* @access private
* @var bool
*/
private $debug;
/** /**
* Username for authentication * Username for authentication
* *
@@ -69,14 +61,12 @@ class Client
* @access public * @access public
* @param string $url Server URL * @param string $url Server URL
* @param integer $timeout Server URL * @param integer $timeout Server URL
* @param bool $debug Debug flag
* @param array $headers Custom HTTP headers * @param array $headers Custom HTTP headers
*/ */
public function __construct($url, $timeout = 5, $debug = false, $headers = array()) public function __construct($url, $timeout = 5, $headers = array())
{ {
$this->url = $url; $this->url = $url;
$this->timeout = $timeout; $this->timeout = $timeout;
$this->debug = $debug;
$this->headers = array_merge($this->headers, $headers); $this->headers = array_merge($this->headers, $headers);
} }
@@ -133,9 +123,6 @@ class Client
if (isset($result['id']) && $result['id'] == $id && array_key_exists('result', $result)) { if (isset($result['id']) && $result['id'] == $id && array_key_exists('result', $result)) {
return $result['result']; return $result['result'];
} }
else if ($this->debug && isset($result['error'])) {
print_r($result['error']);
}
return null; return null;
} }

View File

@@ -177,7 +177,7 @@ class Server
$params[$name] = $request_params[$name]; $params[$name] = $request_params[$name];
} }
else if ($p->isDefaultValueAvailable()) { else if ($p->isDefaultValueAvailable()) {
continue; $params[$name] = $p->getDefaultValue();
} }
else { else {
return false; return false;