diff --git a/appinfo/routes.php b/appinfo/routes.php index d2a5b33fa..c075405bd 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -83,6 +83,10 @@ return [ ['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/boards/{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/StackApiController.php b/lib/Controller/StackApiController.php new file mode 100644 index 000000000..6186694a4 --- /dev/null +++ b/lib/Controller/StackApiController.php @@ -0,0 +1,101 @@ + + * + * @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\StackService; + +/** + * Class StackApiController + * + * @package OCA\Deck\Controller + */ +class StackApiController extends ApiController { + + private $service; + private $userInfo; + + /** + * @param string $appName + * @param IRequest $request + * @param StackService $service + * @param $boardId + */ + public function __construct($appName, IRequest $request, StackService $service, $boardId) { + parent::__construct($appName, $request); + $this->service = $service; + $this->boardId = $boardId; + } + + /** + * @NoAdminRequired + * @CORS + * @NoCSRFRequired + * + * Return all of the stacks in the specified board. + */ + public function index() { + $stacks = $this->service->findAll($this->boardId); + + return new DataResponse($stacks); + } + + /** + * @NoAdminRequired + * @CORS + * @NoCSRFRequired + * + * @params $title + * @params $order + * + * Create a stack with the specified title and order. + */ + public function create($title, $order) { + // this throws a StatusException that needs to be caught and handled + $stack = $this->service->create($title, $this->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($id) { + $stack = $this->service->delete($id); + + return new DataResponse($stack); + } + +}