use BookStack\Entities\Queries\BookshelfQueries;
use BookStack\Entities\Repos\BookshelfRepo;
use BookStack\Http\ApiController;
+use BookStack\Permissions\Permission;
use Exception;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Http\Request;
{
$shelves = $this->queries
->visibleForList()
+ ->with(['cover:id,name,url'])
->addSelect(['created_by', 'updated_by']);
return $this->apiListingResponse($shelves, [
*/
public function create(Request $request)
{
- $this->checkPermission('bookshelf-create-all');
+ $this->checkPermission(Permission::BookshelfCreateAll);
$requestData = $this->validate($request, $this->rules()['create']);
$bookIds = $request->get('books', []);
public function update(Request $request, string $id)
{
$shelf = $this->queries->findVisibleByIdOrFail(intval($id));
- $this->checkOwnablePermission('bookshelf-update', $shelf);
+ $this->checkOwnablePermission(Permission::BookshelfUpdate, $shelf);
$requestData = $this->validate($request, $this->rules()['update']);
$bookIds = $request->get('books', null);
public function delete(string $id)
{
$shelf = $this->queries->findVisibleByIdOrFail(intval($id));
- $this->checkOwnablePermission('bookshelf-delete', $shelf);
+ $this->checkOwnablePermission(Permission::BookshelfDelete, $shelf);
$this->bookshelfRepo->destroy($shelf);
$shelf = clone $shelf;
$shelf->unsetRelations()->refresh();
- $shelf->load(['tags', 'cover']);
- $shelf->makeVisible('description_html')
- ->setAttribute('description_html', $shelf->descriptionHtml());
+ $shelf->load(['tags']);
+ $shelf->makeVisible(['cover', 'description_html'])
+ ->setAttribute('description_html', $shelf->descriptionInfo()->getHtml())
+ ->setAttribute('cover', $shelf->coverInfo()->getImage());
return $shelf;
}