Cleaned up StackApiController to use proper route parameters, removed route parameters from request payloads as per rest standards.

Signed-off-by: Ryan Fletcher <ryan.fletcher@codepassion.ca>
This commit is contained in:
Ryan Fletcher
2018-07-12 21:45:43 -04:00
committed by Julius Härtl
parent 03e0559afe
commit 3cb496daa2
2 changed files with 24 additions and 24 deletions

View File

@@ -84,10 +84,10 @@ return [
['name' => 'board_api#update', 'url' => '/api/v1.0/boards/{id}', 'verb' => 'PUT'], ['name' => 'board_api#update', 'url' => '/api/v1.0/boards/{id}', 'verb' => 'PUT'],
['name' => 'board_api#undo_delete', 'url' => '/api/v1.0/boards/{id}/undo_delete', 'verb' => 'POST'], ['name' => 'board_api#undo_delete', 'url' => '/api/v1.0/boards/{id}/undo_delete', 'verb' => 'POST'],
['name' => 'stack_api#index', 'url' => '/api/v1.0/board/{boardId}/stacks', 'verb' => 'GET'], ['name' => 'stack_api#index', 'url' => '/api/v1.0/boards/{boardId}/stacks', 'verb' => 'GET'],
['name' => 'stack_api#create', 'url' => '/api/v1.0/board/{boardId}/stacks', 'verb' => 'POST'], ['name' => 'stack_api#create', 'url' => '/api/v1.0/boards/{boardId}/stacks', 'verb' => 'POST'],
['name' => 'stack_api#update', 'url' => '/api/v1.0/board/{boardId}/stacks/{id}', 'verb' => 'PUT'], ['name' => 'stack_api#update', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}', 'verb' => 'PUT'],
['name' => 'stack_api#delete', 'url' => '/api/v1.0/board/{boardId}/stacks/{id}', 'verb' => 'DELETE'], ['name' => 'stack_api#delete', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}', 'verb' => 'DELETE'],
['name' => 'board_api#preflighted_cors', 'url' => '/api/v1.0/{path}', ['name' => 'board_api#preflighted_cors', 'url' => '/api/v1.0/{path}',
'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']], 'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']],

View File

@@ -3,6 +3,7 @@
* @copyright Copyright (c) 2017 Steven R. Baker <steven@stevenrbaker.com> * @copyright Copyright (c) 2017 Steven R. Baker <steven@stevenrbaker.com>
* *
* @author Steven R. Baker <steven@stevenrbaker.com> * @author Steven R. Baker <steven@stevenrbaker.com>
* @author Ryan Fletcher <ryan.fletcher@codepassion.ca>
* *
* @license GNU AGPL version 3 or any later version * @license GNU AGPL version 3 or any later version
* *
@@ -58,8 +59,8 @@ class StackApiController extends ApiController {
* *
* Return all of the stacks in the specified board. * Return all of the stacks in the specified board.
*/ */
public function index($boardId) { public function index() {
$stacks = $this->service->findAll($boardId); $stacks = $this->service->findAll($this->request->params['boardId']);
if ($stacks === false || $stacks === null) { if ($stacks === false || $stacks === null) {
return new DataResponse("No Stacks Found", HTTP::STATUS_NOT_FOUND); return new DataResponse("No Stacks Found", HTTP::STATUS_NOT_FOUND);
@@ -78,10 +79,10 @@ class StackApiController extends ApiController {
* *
* Create a stack with the specified title and order. * Create a stack with the specified title and order.
*/ */
public function create($boardId, $title, $order) { public function create($title, $order) {
try { try {
$stack = $this->service->create($title, $boardId, $order); $stack = $this->service->create($title, $this->request->params['boardId'], $order);
} catch (StatusException $e) { } catch (StatusException $e) {
$errorMessage['error'] = $e->getMessage(); $errorMessage['error'] = $e->getMessage();
return new DataResponse($errorMessage, HTTP::STATUS_INTERNAL_SERVER_ERROR); return new DataResponse($errorMessage, HTTP::STATUS_INTERNAL_SERVER_ERROR);
@@ -95,17 +96,18 @@ class StackApiController extends ApiController {
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* @params $stackId
* @params $title * @params $title
* @params $boardId
* @params $order * @params $order
* *
* Create a stack with the specified title and order. * Update a stack by the specified stackId and boardId with the values that were put.
*/ */
public function update($stackId, $title, $boardId, $order) { public function update($title, $order) {
try { try {
$stack = $this->service->update($stackId, $title, $boardId, $order); $stack = $this->service->update(
$this->request->params['stackId'],
$title,
$this->request->params['boardId'],
$order);
} catch (StatusException $e) { } catch (StatusException $e) {
$errorMessage['error'] = $e->getMessage(); $errorMessage['error'] = $e->getMessage();
return new DataResponse($errorMessage, HTTP::STATUS_INTERNAL_SERVER_ERROR); return new DataResponse($errorMessage, HTTP::STATUS_INTERNAL_SERVER_ERROR);
@@ -119,12 +121,10 @@ class StackApiController extends ApiController {
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* @params $id * Delete the stack specified by $this->request->params['id']. Return the board that was deleted.
*
* Delete the stack specified by $id. Return the board that was deleted.
*/ */
public function delete($boardId, $stackId) { public function delete() {
$stack = $this->service->delete($stackId); $stack = $this->service->delete($this->request->params['stackId']);
if ($stack == false || $stack == null) { if ($stack == false || $stack == null) {
return new DataResponse("Stack Not Found", HTTP::STATUS_NOT_FOUND); return new DataResponse("Stack Not Found", HTTP::STATUS_NOT_FOUND);