namespace BookStack\Entities\Controllers;
use BookStack\Entities\Models\Bookshelf;
+use BookStack\Entities\Queries\BookshelfQueries;
use BookStack\Entities\Repos\BookshelfRepo;
use BookStack\Http\ApiController;
use Exception;
class BookshelfApiController extends ApiController
{
public function __construct(
- protected BookshelfRepo $bookshelfRepo
+ protected BookshelfRepo $bookshelfRepo,
+ protected BookshelfQueries $queries,
) {
}
*/
public function list()
{
- $shelves = Bookshelf::visible();
+ $shelves = $this->queries
+ ->visibleForList()
+ ->addSelect(['created_by', 'updated_by']);
return $this->apiListingResponse($shelves, [
'id', 'name', 'slug', 'description', 'created_at', 'updated_at', 'created_by', 'updated_by', 'owned_by',
*/
public function read(string $id)
{
- $shelf = Bookshelf::visible()->findOrFail($id);
+ $shelf = $this->queries->findVisibleByIdOrFail(intval($id));
$shelf = $this->forJsonDisplay($shelf);
$shelf->load([
'createdBy', 'updatedBy', 'ownedBy',
*/
public function update(Request $request, string $id)
{
- $shelf = Bookshelf::visible()->findOrFail($id);
+ $shelf = $this->queries->findVisibleByIdOrFail(intval($id));
$this->checkOwnablePermission('bookshelf-update', $shelf);
$requestData = $this->validate($request, $this->rules()['update']);
*/
public function delete(string $id)
{
- $shelf = Bookshelf::visible()->findOrFail($id);
+ $shelf = $this->queries->findVisibleByIdOrFail(intval($id));
$this->checkOwnablePermission('bookshelf-delete', $shelf);
$this->bookshelfRepo->destroy($shelf);