X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/c157dc3490c39aa236e22714019a649ebeb11f13..refs/pull/2902/head:/app/Http/Controllers/Api/ChapterApiController.php diff --git a/app/Http/Controllers/Api/ChapterApiController.php b/app/Http/Controllers/Api/ChapterApiController.php index 60e0f0131..13b3f9821 100644 --- a/app/Http/Controllers/Api/ChapterApiController.php +++ b/app/Http/Controllers/Api/ChapterApiController.php @@ -1,10 +1,10 @@ - [ - 'book_id' => 'required|integer', - 'name' => 'required|string|max:255', + 'book_id' => 'required|integer', + 'name' => 'required|string|max:255', 'description' => 'string|max:1000', - 'tags' => 'array', + 'tags' => 'array', ], 'update' => [ - 'book_id' => 'integer', - 'name' => 'string|min:1|max:255', + 'book_id' => 'integer', + 'name' => 'string|min:1|max:255', 'description' => 'string|max:1000', - 'tags' => 'array', + 'tags' => 'array', ], ]; @@ -41,9 +41,10 @@ class ChapterApiController extends ApiController public function list() { $chapters = Chapter::visible(); + return $this->apiListingResponse($chapters, [ 'id', 'book_id', 'name', 'slug', 'description', 'priority', - 'created_at', 'updated_at', 'created_by', 'updated_by', + 'created_at', 'updated_at', 'created_by', 'updated_by', 'owned_by', ]); } @@ -59,6 +60,7 @@ class ChapterApiController extends ApiController $this->checkOwnablePermission('chapter-create', $book); $chapter = $this->chapterRepo->create($request->all(), $book); + return response()->json($chapter->load(['tags'])); } @@ -67,9 +69,10 @@ class ChapterApiController extends ApiController */ public function read(string $id) { - $chapter = Chapter::visible()->with(['tags', 'createdBy', 'updatedBy', 'pages' => function (HasMany $query) { + $chapter = Chapter::visible()->with(['tags', 'createdBy', 'updatedBy', 'ownedBy', 'pages' => function (HasMany $query) { $query->visible()->get(['id', 'name', 'slug']); }])->findOrFail($id); + return response()->json($chapter); } @@ -82,11 +85,13 @@ class ChapterApiController extends ApiController $this->checkOwnablePermission('chapter-update', $chapter); $updatedChapter = $this->chapterRepo->update($chapter, $request->all()); + return response()->json($updatedChapter->load(['tags'])); } /** - * Delete a chapter from the system. + * Delete a chapter. + * This will typically send the chapter to the recycle bin. */ public function delete(string $id) { @@ -94,6 +99,7 @@ class ChapterApiController extends ApiController $this->checkOwnablePermission('chapter-delete', $chapter); $this->chapterRepo->destroy($chapter); + return response('', 204); } }