Improve API calls for comments

This commit is contained in:
Frédéric Guillot
2014-09-16 17:54:17 +02:00
parent a76939066b
commit eb6dfdca53
5 changed files with 374 additions and 17 deletions

View File

@@ -23,7 +23,7 @@ class CommentNotificationListener extends BaseNotificationListener
{ {
$values = array(); $values = array();
$values['comment'] = $this->notification->comment->getById($data['id']); $values['comment'] = $this->notification->comment->getById($data['id']);
$values['task'] = $this->notification->task->getById($data['task_id'], true); $values['task'] = $this->notification->task->getById($values['comment']['task_id'], true);
return $values; return $values;
} }

View File

@@ -440,6 +440,18 @@ Response example:
- Result on success: **board properties** - Result on success: **board properties**
- Result on failure: **null** - Result on failure: **null**
Request example:
```json
```
Response example:
```json
```
### getColumns ### getColumns
- Purpose: **Get all columns information for a given project** - Purpose: **Get all columns information for a given project**
@@ -447,6 +459,18 @@ Response example:
- Result on success: **columns properties** - Result on success: **columns properties**
- Result on failure: **null** - Result on failure: **null**
Request example:
```json
```
Response example:
```json
```
### moveColumnUp ### moveColumnUp
- Purpose: **Move up the column position** - Purpose: **Move up the column position**
@@ -454,6 +478,18 @@ Response example:
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
```
Response example:
```json
```
### moveColumnDown ### moveColumnDown
- Purpose: **Move down the column position** - Purpose: **Move down the column position**
@@ -461,6 +497,18 @@ Response example:
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
```
Response example:
```json
```
### updateColumn ### updateColumn
- Purpose: **Update column properties** - Purpose: **Update column properties**
@@ -468,6 +516,18 @@ Response example:
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
```
Response example:
```json
```
### addColumn ### addColumn
- Purpose: **Add a new column** - Purpose: **Add a new column**
@@ -475,6 +535,18 @@ Response example:
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
```
Response example:
```json
```
### removeColumn ### removeColumn
- Purpose: **Remove a column** - Purpose: **Remove a column**
@@ -482,6 +554,18 @@ Response example:
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
```
Response example:
```json
```
### getAllowedUsers ### getAllowedUsers
- Purpose: **Get allowed users for a given project** - Purpose: **Get allowed users for a given project**
@@ -489,6 +573,18 @@ Response example:
- Result on success: Key/value pair of user_id and username - Result on success: Key/value pair of user_id and username
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
```
Response example:
```json
```
### revokeUser ### revokeUser
- Purpose: **Revoke user access for a given project** - Purpose: **Revoke user access for a given project**
@@ -496,6 +592,18 @@ Response example:
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
```
Response example:
```json
```
### allowUser ### allowUser
- Purpose: **Grant user access for a given project** - Purpose: **Grant user access for a given project**
@@ -503,7 +611,17 @@ Response example:
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
```
Response example:
```json
```
### createTask ### createTask
@@ -853,6 +971,18 @@ Response example:
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
```
Response example:
```json
```
### getUser ### getUser
- Purpose: **Get user information** - Purpose: **Get user information**
@@ -860,6 +990,18 @@ Response example:
- Result on success: **user properties** - Result on success: **user properties**
- Result on failure: **null** - Result on failure: **null**
Request example:
```json
```
Response example:
```json
```
### getAllUsers ### getAllUsers
- Purpose: **Get all available users** - Purpose: **Get all available users**
@@ -867,6 +1009,18 @@ Response example:
- Result on success: **List of users** - Result on success: **List of users**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
```
Response example:
```json
```
### updateUser ### updateUser
- Purpose: **Update a user** - Purpose: **Update a user**
@@ -874,6 +1028,18 @@ Response example:
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
```
Response example:
```json
```
### removeUser ### removeUser
- Purpose: **Remove a user** - Purpose: **Remove a user**
@@ -881,7 +1047,17 @@ Response example:
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
```
Response example:
```json
```
### createCategory ### createCategory
@@ -1058,39 +1234,182 @@ Response example:
### createComment ### createComment
- Purpose: **Create a new comment** - Purpose: **Create a new comment**
- Parameters: Key/value pair composed of the **task_id** (integer), **user_id** (integer), **comment** (string) - Parameters:
- **task_id** (integer, required)
- **user_id** (integer, required)
- **content** Markdown content (string, required)
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
{
"jsonrpc": "2.0",
"method": "createComment",
"id": 1580417921,
"params": {
"task_id": 1,
"user_id": 1,
"content": "Comment #1"
}
}
```
Response example:
```json
"jsonrpc": "2.0",
"id": 1580417921,
"result": true
}
```
### getComment ### getComment
- Purpose: **Get comment information** - Purpose: **Get comment information**
- Parameters: **comment_id** (integer) - Parameters:
- **comment_id** (integer, required)
- Result on success: **comment properties** - Result on success: **comment properties**
- Result on failure: **null** - Result on failure: **null**
Request example:
```json
{
"jsonrpc": "2.0",
"method": "getComment",
"id": 867839500,
"params": {
"comment_id": 1
}
}
```
Response example:
```json
{
"jsonrpc": "2.0",
"id": 867839500,
"result": {
"id": "1",
"task_id": "1",
"user_id": "1",
"date": "1410881970",
"comment": "Comment #1",
"username": "admin",
"name": null
}
}
```
### getAllComments ### getAllComments
- Purpose: **Get all available comments** - Purpose: **Get all available comments**
- Parameters: **none** - Parameters:
- **task_id** (integer, required)
- Result on success: **List of comments** - Result on success: **List of comments**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
{
"jsonrpc": "2.0",
"method": "getAllComments",
"id": 148484683,
"params": {
"task_id": 1
}
}
```
Response example:
```json
{
"jsonrpc": "2.0",
"id": 148484683,
"result": [
{
"id": "1",
"date": "1410882272",
"task_id": "1",
"user_id": "1",
"comment": "Comment #1",
"username": "admin",
"name": null
},
...
]
}
```
### updateComment ### updateComment
- Purpose: **Update a comment** - Purpose: **Update a comment**
- Parameters: Key/value pair composed of the **id** (integer), **task_id** (integer), **user_id** (integer), **comment** (string) - Parameters:
- **id** (integer, required)
- **content** Markdown content (string, required)
- Result on success: **true** - Result on success: **true**
- Result on failure: **false** - Result on failure: **false**
Request example:
```json
{
"jsonrpc": "2.0",
"method": "updateComment",
"id": 496470023,
"params": {
"id": 1,
"content": "Comment #1 updated"
}
}
```
Response example:
```json
{
"jsonrpc": "2.0",
"id": 1493368950,
"result": true
}
```
### removeComment ### removeComment
- Purpose: **Remove a comment** - Purpose: **Remove a comment**
- Parameters: **comment_id** (integer) - Parameters:
- **comment_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": "removeComment",
"id": 328836871,
"params": {
"comment_id": 1
}
}
```
Response example:
```json
{
"jsonrpc": "2.0",
"id": 328836871,
"result": true
}
```
### createSubtask ### createSubtask

View File

@@ -288,7 +288,14 @@ $server->register('removeCategory', function($category_id) use ($category) {
/** /**
* Comments procedures * Comments procedures
*/ */
$server->register('createComment', function(array $values) use ($comment) { $server->register('createComment', function($task_id, $user_id, $content) use ($comment) {
$values = array(
'task_id' => $task_id,
'user_id' => $user_id,
'comment' => $content,
);
list($valid,) = $comment->validateCreation($values); list($valid,) = $comment->validateCreation($values);
return $valid && $comment->create($values); return $valid && $comment->create($values);
}); });
@@ -301,7 +308,13 @@ $server->register('getAllComments', function($task_id) use ($comment) {
return $comment->getAll($task_id); return $comment->getAll($task_id);
}); });
$server->register('updateComment', function($values) use ($comment) { $server->register('updateComment', function($id, $content) use ($comment) {
$values = array(
'id' => $id,
'comment' => $content,
);
list($valid,) = $comment->validateModification($values); list($valid,) = $comment->validateModification($values);
return $valid && $comment->update($values); return $valid && $comment->update($values);
}); });

View File

@@ -318,10 +318,10 @@ class Api extends PHPUnit_Framework_TestCase
$comment = array( $comment = array(
'task_id' => $tasks[0]['id'], 'task_id' => $tasks[0]['id'],
'user_id' => 2, 'user_id' => 2,
'comment' => 'boo', 'content' => 'boo',
); );
$this->assertTrue($this->client->createComment($comment)); $this->assertTrue($this->client->execute('createComment', $comment));
} }
public function testGetComment() public function testGetComment()
@@ -335,10 +335,11 @@ class Api extends PHPUnit_Framework_TestCase
public function testUpdateComment() public function testUpdateComment()
{ {
$comment = $this->client->getComment(1); $comment = array();
$comment['comment'] = 'test'; $comment['id'] = 1;
$comment['content'] = 'test';
$this->assertTrue($this->client->updateComment($comment)); $this->assertTrue($this->client->execute('updateComment', $comment));
$comment = $this->client->getComment(1); $comment = $this->client->getComment(1);
$this->assertEquals('test', $comment['comment']); $this->assertEquals('test', $comment['comment']);
@@ -351,10 +352,10 @@ class Api extends PHPUnit_Framework_TestCase
$comment = array( $comment = array(
'task_id' => $task_id, 'task_id' => $task_id,
'user_id' => 1, 'user_id' => 1,
'comment' => 'blabla', 'content' => 'blabla',
); );
$this->assertTrue($this->client->createComment($comment)); $this->assertTrue($this->client->execute('createComment', $comment));
$comments = $this->client->getAllComments($task_id); $comments = $this->client->getAllComments($task_id);
$this->assertNotFalse($comments); $this->assertNotFalse($comments);
@@ -366,13 +367,20 @@ class Api extends PHPUnit_Framework_TestCase
public function testRemoveComment() public function testRemoveComment()
{ {
$task_id = $this->getTaskId(); $task_id = $this->getTaskId();
$this->assertTrue($this->client->removeComment($task_id));
$comments = $this->client->getAllComments($task_id); $comments = $this->client->getAllComments($task_id);
$this->assertNotFalse($comments); $this->assertNotFalse($comments);
$this->assertNotEmpty($comments); $this->assertNotEmpty($comments);
$this->assertTrue(is_array($comments)); $this->assertTrue(is_array($comments));
$this->assertEquals(1, count($comments));
foreach ($comments as $comment) {
$this->assertTrue($this->client->removeComment($comment['id']));
}
$comments = $this->client->getAllComments($task_id);
$this->assertNotFalse($comments);
$this->assertEmpty($comments);
$this->assertTrue(is_array($comments));
} }
public function testCreateSubtask() public function testCreateSubtask()

View File

@@ -47,6 +47,8 @@ class CommentTest extends Base
$this->assertEquals(1, $comments[0]['id']); $this->assertEquals(1, $comments[0]['id']);
$this->assertEquals(2, $comments[1]['id']); $this->assertEquals(2, $comments[1]['id']);
$this->assertEquals(3, $comments[2]['id']); $this->assertEquals(3, $comments[2]['id']);
$this->assertEquals(3, $c->count(1));
} }
public function testUpdate() public function testUpdate()
@@ -65,6 +67,21 @@ class CommentTest extends Base
$this->assertEquals('bla', $comment['comment']); $this->assertEquals('bla', $comment['comment']);
} }
public function validateRemove()
{
$c = new Comment($this->registry);
$t = new Task($this->registry);
$p = new Project($this->registry);
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
$this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
$this->assertTrue($c->remove(1));
$this->assertFalse($c->remove(1));
$this->assertFalse($c->remove(1111));
}
public function testValidateCreation() public function testValidateCreation()
{ {
$c = new Comment($this->registry); $c = new Comment($this->registry);