Skip to content

Commit

Permalink
Feat(REST API): add url to (un)archive cards
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas H. Steiner <jsteiner@plusline.net>
  • Loading branch information
xyjonas authored and juliusknorr committed Aug 29, 2024
1 parent 43a0fec commit e986ca3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
2 changes: 2 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
['name' => 'card_api#assignUser', 'url' => '/api/v{apiVersion}/boards/{boardId}/stacks/{stackId}/cards/{cardId}/assignUser', 'verb' => 'PUT'],
['name' => 'card_api#unassignUser', 'url' => '/api/v{apiVersion}/boards/{boardId}/stacks/{stackId}/cards/{cardId}/unassignUser', 'verb' => 'PUT'],
['name' => 'card_api#reorder', 'url' => '/api/v{apiVersion}/boards/{boardId}/stacks/{stackId}/cards/{cardId}/reorder', 'verb' => 'PUT'],
['name' => 'card_api#archive', 'url' => '/api/v{apiVersion}/boards/{boardId}/stacks/{stackId}/cards/{cardId}/archive', 'verb' => 'PUT'],
['name' => 'card_api#unarchive', 'url' => '/api/v{apiVersion}/boards/{boardId}/stacks/{stackId}/cards/{cardId}/unarchive', 'verb' => 'PUT'],
['name' => 'card_api#delete', 'url' => '/api/v{apiVersion}/boards/{boardId}/stacks/{stackId}/cards/{cardId}', 'verb' => 'DELETE'],

['name' => 'card_api#findAllWithDue', 'url' => '/api/v{apiVersion}/dashboard/due', 'verb' => 'GET'],
Expand Down
28 changes: 28 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,34 @@ A 403 response might be returned if the users ability to create new boards has b

##### 200 Success

### PUT /boards/{boardId}/stacks/{stackId}/cards/{cardId}/archive - Archive a card

#### Request parameters

| Parameter | Type | Description |
| --------- | ------- | --------------------------------------- |
| boardId | Integer | The id of the board the card belongs to |
| stackId | Integer | The id of the stack the card belongs to |
| cardId | Integer | The id of the card |

#### Response

##### 200 Success

### PUT /boards/{boardId}/stacks/{stackId}/cards/{cardId}/unarchive - Unarchive a card

#### Request parameters

| Parameter | Type | Description |
| --------- | ------- | --------------------------------------- |
| boardId | Integer | The id of the board the card belongs to |
| stackId | Integer | The id of the stack the card belongs to |
| cardId | Integer | The id of the card |

#### Response

##### 200 Success

### DELETE /boards/{boardId} - Delete a board

#### Request parameters
Expand Down
24 changes: 24 additions & 0 deletions lib/Controller/CardApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,30 @@ public function unassignUser($cardId, $userId, $type = 0) {
return new DataResponse($card, HTTP::STATUS_OK);
}

/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*
* Archive card
*/
public function archive($cardId) {
$card = $this->cardService->archive($cardId);
return new DataResponse($card, HTTP::STATUS_OK);
}

/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*
* Unarchive card
*/
public function unarchive($cardId) {
$card = $this->cardService->unarchive($cardId);
return new DataResponse($card, HTTP::STATUS_OK);
}

/**
* @NoAdminRequired
* @CORS
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/controller/CardApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,32 @@ public function testUpdate() {
$this->assertEquals($expected, $actual);
}

public function testArchive() {
$card = new Card();
$card->setId($this->cardExample['id']);

$this->cardService->expects($this->once())
->method('archive')
->willReturn($card);

$expected = new DataResponse($card, HTTP::STATUS_OK);
$actual = $this->controller->archive($this->cardExample['id']);
$this->assertEquals($expected, $actual);
}

public function testUnArchive() {
$card = new Card();
$card->setId($this->cardExample['id']);

$this->cardService->expects($this->once())
->method('unarchive')
->willReturn($card);

$expected = new DataResponse($card, HTTP::STATUS_OK);
$actual = $this->controller->unarchive($this->cardExample['id']);
$this->assertEquals($expected, $actual);
}

public function testDelete() {
$card = new Card();
$card->setId($this->cardExample['id']);
Expand Down

0 comments on commit e986ca3

Please sign in to comment.