From f97c7c3f7b29a8a18232fe138ba471bd7c7f75f4 Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Fri, 13 Jul 2018 12:29:23 -0400 Subject: [PATCH] Added in Create + Delete functions to the LabelApiController Signed-off-by: Ryan Fletcher --- appinfo/routes.php | 2 + lib/Controller/LabelApiController.php | 58 +++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/appinfo/routes.php b/appinfo/routes.php index 5b90c0759..3c9eaf484 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -97,7 +97,9 @@ return [ ['name' => 'card_api#delete', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}', 'verb' => 'DELETE'], ['name' => 'label_api#get', 'url' => '/api/v1.0/boards/{boardId}/labels/{labelId}', 'verb' => 'GET'], + ['name' => 'label_api#create', 'url' => '/api/v1.0/boards/{boardId}/labels', 'verb' => 'POST'], ['name' => 'label_api#update', 'url' => '/api/v1.0/boards/{boardId}/labels/{labelId}', 'verb' => 'PUT'], + ['name' => 'label_api#delete', 'url' => '/api/v1.0/boards/{boardId}/labels/{labelId}', 'verb' => 'DELETE'], ['name' => 'board_api#preflighted_cors', 'url' => '/api/v1.0/{path}','verb' => 'OPTIONS', 'requirements' => ['path' => '.+']], ] diff --git a/lib/Controller/LabelApiController.php b/lib/Controller/LabelApiController.php index 11aa32974..86410730a 100644 --- a/lib/Controller/LabelApiController.php +++ b/lib/Controller/LabelApiController.php @@ -78,6 +78,38 @@ class LabelApiController extends ApiController { return new DataResponse($label, HTTP::STATUS_OK); } + /** + * @NoAdminRequired + * @CORS + * @NoCSRFRequired + * + * @params $title + * @params $color + * Create a new label + */ + public function create($title, $color) { + + if (is_numeric($this->request->params['boardId']) === false) { + return new DataResponse("board id must be a number", HTTP::STATUS_BAD_REQUEST); + } + + if ($title === false || $title === null) { + return new DataResponse("title must be provided", HTTP::STATUS_BAD_REQUEST); + } + + if ($color === false || $color === null) { + return new DataResponse("color must be provided", HTTP::STATUS_BAD_REQUEST); + } + + try { + $label = $this->labelService->create($title, $color, $this->request->params['boardId']); + } catch (Exception $e) { + return new DataResponse($e->getMessage(), HTTP::STATUS_INTERNAL_SERVER_ERROR); + } + + return new DataResponse($label, HTTP::STATUS_OK); + } + /** * @NoAdminRequired * @CORS @@ -114,4 +146,30 @@ class LabelApiController extends ApiController { return new DataResponse($label, HTTP::STATUS_OK); } + /** + * @NoAdminRequired + * @CORS + * @NoCSRFRequired + * + * Delete a specific label + */ + public function delete() { + + if (is_numeric($this->request->params['boardId']) === false) { + return new DataResponse("board id must be a number", HTTP::STATUS_BAD_REQUEST); + } + + if (is_numeric($this->request->params['labelId']) === false) { + return new DataResponse("label id must be a number", HTTP::STATUS_BAD_REQUEST); + } + + try { + $label = $this->labelService->delete($this->request->params['labelId']); + } catch (Exception $e) { + return new DataResponse($e->getMessage(), HTTP::STATUS_INTERNAL_SERVER_ERROR); + } + + return new DataResponse($label, HTTP::STATUS_OK); + } + } \ No newline at end of file