Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON API #271

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c51070a
List boards, and fetch a specific board.
srbaker Jul 28, 2017
1b22c44
Delete boards via the API.
srbaker Jul 29, 2017
fc02f58
Undo deletion of boards via API.
srbaker Jul 29, 2017
43c7fb7
Update the documentation.
srbaker Jul 29, 2017
6343412
Change the API version to 1.0, and fix the preflighted_cors version.
srbaker Jul 29, 2017
03d1d6c
These parens are not needed.
srbaker Jul 29, 2017
b8676ee
Board creation via API.
srbaker Jul 29, 2017
f6f78fc
Add Stack support to API.
srbaker Jul 29, 2017
05f5323
Merge branch 'master' into add-json-api
srbaker Jul 29, 2017
f797b31
Fix the routing and the stacks API endpoint.
srbaker Jul 29, 2017
d095c27
Merge branch 'master' into add-json-api
srbaker Jul 30, 2017
2c7c768
Merge branch 'master' into add-json-api
srbaker Aug 11, 2017
42d88e9
Merge branch 'master' into add-json-api
hanzei Sep 3, 2017
5de1b94
Merge branch 'master' into add-json-api
srbaker Feb 12, 2018
20be99e
Re-format code according to the coding style.
srbaker Feb 12, 2018
e218d55
This should be 200 on deletion, so we can tell whether a deletion suc…
srbaker Feb 12, 2018
fb19856
Extract getBoardPererequisites() so it can be re-used.
srbaker Feb 12, 2018
6e722ae
Merge remote-tracking branch 'origin/add-json-api' into add-json-api
srbaker Feb 12, 2018
8b4efbc
Don't need to pass around the userInfo with it encapsulated in BoardS…
srbaker Feb 12, 2018
6691234
Merge branch 'master' into add-json-api
srbaker Feb 14, 2018
e68b292
Merge branch 'master' into add-json-api
srbaker Feb 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,18 @@
['name' => 'label#update', 'url' => '/labels/{labelId}', 'verb' => 'PUT'],
['name' => 'label#delete', 'url' => '/labels/{labelId}', 'verb' => 'DELETE'],

// api
['name' => 'board_api#index', 'url' => '/api/v1.0/boards', 'verb' => 'GET'],
['name' => 'board_api#get', 'url' => '/api/v1.0/board/{id}', 'verb' => 'GET'],
['name' => 'board_api#create', 'url' => '/api/v1.0/board', 'verb' => 'POST'],
['name' => 'board_api#delete', 'url' => '/api/v1.0/board/{id}', 'verb' => 'DELETE'],
['name' => 'board_api#undo_delete', 'url' => '/api/v1.0/board/{id}/undo_delete', 'verb' => 'POST'],

['name' => 'stack_api#index', 'url' => '/api/v1.0/board/{boardId}/stacks', 'verb' => 'GET'],
['name' => 'stack_api#create', 'url' => '/api/v1.0/board/{boardId}/stack', 'verb' => 'POST'],
['name' => 'stack_api#delete', 'url' => '/api/v1.0/board/{boardId}/stack/{id}', 'verb' => 'DELETE'],

['name' => 'board_api#preflighted_cors', 'url' => '/api/v1.0/{path}',
'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']],
]
];
130 changes: 130 additions & 0 deletions lib/Controller/BoardApiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php
/**
* @copyright Copyright (c) 2017 Steven R. Baker <[email protected]>
*
* @author Steven R. Baker <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Deck\Controller;

use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IGroupManager;

use OCA\Deck\Service\BoardService;

/**
* Class BoardApiController
*
* @package OCA\Deck\Controller
*/
class BoardApiController extends ApiController {

private $service;

/**
* @param string $appName
* @param IRequest $request
* @param BoardService $service
* @param $userId
*/
public function __construct($appName, IRequest $request, BoardService $service, $userId) {
parent::__construct($appName, $request);
$this->service = $service;
$this->userId = $userId;
}

/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*
* Return all of the boards that the current user has access to.
*/
public function index() {
$boards = $this->service->findAll();

return new DataResponse($boards);
}

/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*
* @params $id
*
* Return the board specified by $id.
*/
public function get($id) {
$board = $this->service->find($id);

return new DataResponse($board);
}

/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*
* @params $title
* @params $color
*
* Create a board with the specified title and color.
*/
public function create($title, $color) {
$board = $this->service->create($title, $this->userId, $color);

return new DataResponse($board);
}

/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*
* @params $id
*
* Delete the board specified by $id. Return the board that was deleted.
*/
public function delete($id) {
$board = $this->service->delete($id);

return new DataResponse($board);
}

/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*
* @params $id
*
* Undo the deletion of the board specified by $id.
*/
public function undoDelete($id) {
$board = $this->service->find($id);
$this->service->deleteUndo($id);

return new DataResponse($board);
}

}
18 changes: 1 addition & 17 deletions lib/Controller/BoardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class BoardController extends Controller {
private $userManager;
private $groupManager;
private $permissionService;
private $userInfo;

public function __construct($appName, IRequest $request, IUserManager $userManager, IGroupManager $groupManager, BoardService $boardService, PermissionService $permissionService, $userId) {
parent::__construct($appName, $request);
Expand All @@ -46,28 +45,13 @@ public function __construct($appName, IRequest $request, IUserManager $userManag
$this->groupManager = $groupManager;
$this->boardService = $boardService;
$this->permissionService = $permissionService;
$this->userInfo = $this->getBoardPrerequisites();
}

/**
* TODO: move to boardservice
* @return array
*/
private function getBoardPrerequisites() {
$groups = $this->groupManager->getUserGroupIds(
$this->userManager->get($this->userId)
);
return [
'user' => $this->userId,
'groups' => $groups
];
}

/**
* @NoAdminRequired
*/
public function index() {
return $this->boardService->findAll($this->userInfo);
return $this->boardService->findAll();
}

/**
Expand Down
97 changes: 97 additions & 0 deletions lib/Controller/StackApiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* @copyright Copyright (c) 2017 Steven R. Baker <[email protected]>
*
* @author Steven R. Baker <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Deck\Controller;

use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;

use OCA\Deck\Service\StackService;

/**
* Class StackApiController
*
* @package OCA\Deck\Controller
*/
class StackApiController extends ApiController {

private $service;
private $userInfo;

/**
* @param string $appName
* @param IRequest $request
* @param StackService $service
*/
public function __construct($appName, IRequest $request, StackService $service) {
parent::__construct($appName, $request);
$this->service = $service;
}

/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*
* Return all of the stacks in the specified board.
*/
public function index($boardId) {
$stacks = $this->service->findAll($boardId);

return new DataResponse($stacks);
}

/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*
* @params $title
* @params $order
*
* Create a stack with the specified title and order.
*/
public function create($boardId, $title, $order) {
// this throws a StatusException that needs to be caught and handled
$stack = $this->service->create($title, $boardId, $order);

return new DataResponse($stack);
}

/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*
* @params $id
*
* Delete the stack specified by $id. Return the board that was deleted.
*/
public function delete($boardId, $id) {
$stack = $this->service->delete($id);

return new DataResponse($stack);
}

}
13 changes: 12 additions & 1 deletion lib/Service/BoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public function __construct(
$this->notificationHelper = $notificationHelper;
}

public function findAll($userInfo) {
public function findAll() {
$userInfo = $this->getBoardPrerequisites();
$userBoards = $this->boardMapper->findAllByUser($userInfo['user']);
$groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups']);
$complete = array_merge($userBoards, $groupBoards);
Expand Down Expand Up @@ -108,6 +109,16 @@ public function find($boardId) {
return $board;
}

private function getBoardPrerequisites() {
$groups = $this->groupManager->getUserGroupIds(
$this->userManager->get($this->userId)
);
return [
'user' => $this->userId,
'groups' => $groups
];
}

public function isArchived($mapper, $id) {
try {
$boardId = $id;
Expand Down