namespace BookStack\Entities\Controllers;
-use BookStack\Entities\Models\Book;
-use BookStack\Entities\Models\Chapter;
-use BookStack\Entities\Models\Page;
+use BookStack\Entities\Queries\EntityQueries;
+use BookStack\Entities\Queries\PageQueries;
use BookStack\Entities\Repos\PageRepo;
use BookStack\Exceptions\PermissionsException;
use BookStack\Http\ApiController;
'html' => ['required_without:markdown', 'string'],
'markdown' => ['required_without:html', 'string'],
'tags' => ['array'],
+ 'priority' => ['integer'],
],
'update' => [
'book_id' => ['integer'],
'html' => ['string'],
'markdown' => ['string'],
'tags' => ['array'],
+ 'priority' => ['integer'],
],
];
public function __construct(
- protected PageRepo $pageRepo
+ protected PageRepo $pageRepo,
+ protected PageQueries $queries,
+ protected EntityQueries $entityQueries,
) {
}
*/
public function list()
{
- $pages = Page::visible();
+ $pages = $this->queries->visibleForList()
+ ->addSelect(['created_by', 'updated_by', 'revision_count', 'editor']);
return $this->apiListingResponse($pages, [
'id', 'book_id', 'chapter_id', 'name', 'slug', 'priority',
$this->validate($request, $this->rules['create']);
if ($request->has('chapter_id')) {
- $parent = Chapter::visible()->findOrFail($request->get('chapter_id'));
+ $parent = $this->entityQueries->chapters->findVisibleByIdOrFail(intval($request->get('chapter_id')));
} else {
- $parent = Book::visible()->findOrFail($request->get('book_id'));
+ $parent = $this->entityQueries->books->findVisibleByIdOrFail(intval($request->get('book_id')));
}
$this->checkOwnablePermission('page-create', $parent);
*/
public function read(string $id)
{
- $page = $this->pageRepo->getById($id, []);
+ $page = $this->queries->findVisibleByIdOrFail($id);
return response()->json($page->forJsonDisplay());
}
{
$requestData = $this->validate($request, $this->rules['update']);
- $page = $this->pageRepo->getById($id, []);
+ $page = $this->queries->findVisibleByIdOrFail($id);
$this->checkOwnablePermission('page-update', $page);
$parent = null;
if ($request->has('chapter_id')) {
- $parent = Chapter::visible()->findOrFail($request->get('chapter_id'));
+ $parent = $this->entityQueries->chapters->findVisibleByIdOrFail(intval($request->get('chapter_id')));
} elseif ($request->has('book_id')) {
- $parent = Book::visible()->findOrFail($request->get('book_id'));
+ $parent = $this->entityQueries->books->findVisibleByIdOrFail(intval($request->get('book_id')));
}
if ($parent && !$parent->matches($page->getParent())) {
*/
public function delete(string $id)
{
- $page = $this->pageRepo->getById($id, []);
+ $page = $this->queries->findVisibleByIdOrFail($id);
$this->checkOwnablePermission('page-delete', $page);
$this->pageRepo->destroy($page);