diff --git a/app/routes/api/pages.php b/app/routes/api/pages.php index ee809e0..9b0984c 100644 --- a/app/routes/api/pages.php +++ b/app/routes/api/pages.php @@ -7,9 +7,9 @@ use Parvula\Models\PagesFlatFiles; use Parvula\Exceptions\IOException; use Rs\Json\Patch; +use Rs\Json\Patch\InvalidOperationException; use Rs\Json\Patch\InvalidPatchDocumentJsonException; use Rs\Json\Patch\InvalidTargetDocumentJsonException; -use Rs\Json\Patch\InvalidOperationException; $pages = $app['pages']; @@ -136,34 +136,17 @@ /** * @api {patch} /pages/:slug Update specific field(s) of a page + * @apiDescription For more details about json patch: https://tools.ietf.org/html/rfc6902 * @apiName Patch page * @apiGroup Page * - * @apiParamExample Request-Example: - * title=My new title - * - * @apiParamExample Request-Example: - * title=My new title&content=new content - * * @apiSuccess (204) PagePatched + * @apiError (400) InvalidPatchDocumentJsonException + * @apiError (400) InvalidTargetDocumentJsonException + * @apiError (400) InvalidOperationException + * @apiError (404) PageDoesNotExists If page does not exists * @apiError (404) PageException If exception */ -// $this->patch('/{slug:.+}', function ($req, $res, $args) use ($pages) { -// $pageArr = (array) $req->getParsedBody(); -// -// try { -// $pages->patch($args['slug'], $pageArr); -// } catch (Exception $e) { -// return $this->api->json($res, [ -// 'error' => 'PageException', -// 'message' => $e->getMessage() -// ], 500); -// } -// -// return $res->withStatus(204); -// }); - -// DEV $this->patch('/{slug:.+}', function ($req, $res, $args) use ($app, $pages) { $parsedBody = $req->getParsedBody(); $bodyJson = json_encode($req->getParsedBody()); @@ -208,13 +191,14 @@ 'error' => 'InvalidOperationException', 'message' => $e->getMessage() ], 400); + } catch (Exception $e) { + return $this->api->json($res, [ + 'error' => 'InvalidOperationException', + 'message' => $e->getMessage() + ], 500); } }); - - - - /* * @api {delete} /page/:slug Delete a page. * @apiName Delete page