diff --git a/appinfo/routes.php b/appinfo/routes.php index 6d0838d2b..2454d6daa 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -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' => '.+']], ] ]; diff --git a/lib/Controller/BoardApiController.php b/lib/Controller/BoardApiController.php new file mode 100644 index 000000000..312590541 --- /dev/null +++ b/lib/Controller/BoardApiController.php @@ -0,0 +1,130 @@ + + * + * @author Steven R. Baker + * + * @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 . + * + */ + +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); + } + +} diff --git a/lib/Controller/BoardController.php b/lib/Controller/BoardController.php index a0ed9790a..6de90f63a 100644 --- a/lib/Controller/BoardController.php +++ b/lib/Controller/BoardController.php @@ -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); @@ -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(); } /** diff --git a/lib/Controller/StackApiController.php b/lib/Controller/StackApiController.php new file mode 100644 index 000000000..9cae1a8af --- /dev/null +++ b/lib/Controller/StackApiController.php @@ -0,0 +1,97 @@ + + * + * @author Steven R. Baker + * + * @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 . + * + */ + +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); + } + +} diff --git a/lib/Service/BoardService.php b/lib/Service/BoardService.php index 072f7c1f5..f398f81a9 100644 --- a/lib/Service/BoardService.php +++ b/lib/Service/BoardService.php @@ -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); @@ -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;