Added in Create + Delete functions to the LabelApiController

Signed-off-by: Ryan Fletcher <ryan.fletcher@codepassion.ca>
This commit is contained in:
Ryan Fletcher
2018-07-13 12:29:23 -04:00
committed by Julius Härtl
parent 6002067b64
commit f97c7c3f7b
2 changed files with 60 additions and 0 deletions

View File

@@ -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' => '.+']],
]

View File

@@ -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);
}
}