From e5f7f89ed9549a9fcf1713dd47f0e01d9c1a3b52 Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Fri, 13 Jul 2018 08:37:51 -0400 Subject: [PATCH] Wrote update method for CardApiController Signed-off-by: Ryan Fletcher --- appinfo/routes.php | 1 + lib/Controller/CardApiController.php | 56 +++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index bedac90ed..b8a372d80 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -93,6 +93,7 @@ return [ ['name' => 'card_api#get', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}', 'verb' => 'GET'], ['name' => 'card_api#create', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards', 'verb' => 'POST'], + ['name' => 'card_api#update', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}', 'verb' => 'PUT'], ['name' => 'board_api#preflighted_cors', 'url' => '/api/v1.0/{path}','verb' => 'OPTIONS', 'requirements' => ['path' => '.+']], ] diff --git a/lib/Controller/CardApiController.php b/lib/Controller/CardApiController.php index 5f2d5d7d9..64e68ac11 100644 --- a/lib/Controller/CardApiController.php +++ b/lib/Controller/CardApiController.php @@ -102,24 +102,68 @@ class CardApiController extends ApiController { return new DataResponse("stack id must be a number", HTTP::STATUS_BAD_REQUEST); } - if ($title === false) { + if ($title === false || $title === null) { return new DataResponse("title must be provided", HTTP::STATUS_BAD_REQUEST); } - if ($type === false) { - return new DataResponse("type must be provided", HTTP::STATUS_BAD_REQUEST); - } - if (is_numeric($order) === false) { return new DataResponse("order must be a number", HTTP::STATUS_BAD_REQUEST); } try { $card = $this->cardService->create($title, $this->request->params['stackId'], $type, $order, $this->userId); - } catch (StatusException $e) { + } catch (Exception $e) { return new DataResponse($e->getMessage(), HTTP::STATUS_INTERNAL_SERVER_ERROR); } return new DataResponse($card, HTTP::STATUS_OK); } + + /** + * @NoAdminRequired + * @CORS + * @NoCSRFRequired + * + * @params $title + * @params $type + * @params $order + * @params $description + * @params $duedate + * + * Get a specific card. + */ + public function update($title, $type, $order, $description = null, $duedate = null) { + + if (is_numeric($this->request->params['cardId']) === false) { + return new DataResponse("card id must be a number", HTTP::STATUS_BAD_REQUEST); + } + + if (is_numeric($this->request->params['stackId']) === false) { + return new DataResponse("stack 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 (is_numeric($order) === false) { + return new DataResponse("order must be a number", HTTP::STATUS_BAD_REQUEST); + } + + try { + $card = $this->cardService->update( + $this->request->params['cardId'], + $title, + $this->request->params['stackId'], + $type, + $order, + $description, + $this->userId, + $duedate); + } catch(Exception $e) { + return new DataResponse($e->getMessage(), HTTP::STATUS_INTERNAL_SERVER_ERROR); + } + + return new DataResponse($card, HTTP::STATUS_OK); + } } \ No newline at end of file