Created LabelApiController and it's get / update methods.
Signed-off-by: Ryan Fletcher <ryan.fletcher@codepassion.ca>
This commit is contained in:
committed by
Julius Härtl
parent
7e4d24236a
commit
6002067b64
@@ -96,6 +96,9 @@ return [
|
||||
['name' => 'card_api#update', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}', 'verb' => 'PUT'],
|
||||
['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#update', 'url' => '/api/v1.0/boards/{boardId}/labels/{labelId}', 'verb' => 'PUT'],
|
||||
|
||||
['name' => 'board_api#preflighted_cors', 'url' => '/api/v1.0/{path}','verb' => 'OPTIONS', 'requirements' => ['path' => '.+']],
|
||||
]
|
||||
];
|
||||
|
||||
@@ -42,7 +42,7 @@ class CardApiController extends ApiController {
|
||||
/**
|
||||
* @param string $appName
|
||||
* @param IRequest $request
|
||||
* @param BoardService $service
|
||||
* @param CardService $service
|
||||
* @param $userId
|
||||
*/
|
||||
public function __construct($appName, IRequest $request, CardService $cardService, $userId) {
|
||||
@@ -70,7 +70,7 @@ class CardApiController extends ApiController {
|
||||
|
||||
if (is_numeric($this->request->params['cardId']) === false) {
|
||||
return new DataResponse("card id must be a number", HTTP::STATUS_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
$card = $this->cardService->find($this->request->params['cardId']);
|
||||
|
||||
|
||||
117
lib/Controller/LabelApiController.php
Normal file
117
lib/Controller/LabelApiController.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Ryan Fletcher <ryan.fletcher@codepassion.ca>
|
||||
*
|
||||
* @author Ryan Fletcher <ryan.fletcher@codepassion.ca>
|
||||
*
|
||||
* @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;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\IRequest;
|
||||
|
||||
use OCA\Deck\Service\LabelService;
|
||||
|
||||
/**
|
||||
* Class BoardApiController
|
||||
*
|
||||
* @package OCA\Deck\Controller
|
||||
*/
|
||||
class LabelApiController extends ApiController {
|
||||
|
||||
private $labelService;
|
||||
private $userId;
|
||||
|
||||
/**
|
||||
* @param string $appName
|
||||
* @param IRequest $request
|
||||
* @param LabelService $service
|
||||
* @param $userId
|
||||
*/
|
||||
public function __construct($appName, IRequest $request, LabelService $labelService, $userId) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->labelService = $labelService;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* Get a specific label.
|
||||
*/
|
||||
public function get() {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
$label = $this->labelService->find($this->request->params['labelId']);
|
||||
|
||||
if ($label === false || $label === null) {
|
||||
return new DataResponse('Label not found', HTTP::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
return new DataResponse($label, HTTP::STATUS_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @params $title
|
||||
* @params $color
|
||||
* Update a specific label
|
||||
*/
|
||||
public function update($title, $color) {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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->update($this->request->params['labelId'], $title, $color);
|
||||
} catch (Exception $e) {
|
||||
return new DataResponse($e->getMessage(), HTTP::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
return new DataResponse($label, HTTP::STATUS_OK);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user