1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-31 15:24:31 +03:00

Queries: Migrated bookshelf repo queries to new class

This commit is contained in:
Dan Brown
2024-02-04 19:32:19 +00:00
parent 1559b0acd1
commit 3886aedf54
5 changed files with 80 additions and 79 deletions

View File

@ -5,6 +5,7 @@ namespace BookStack\Entities\Controllers;
use BookStack\Activity\ActivityQueries;
use BookStack\Activity\Models\View;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Queries\BookshelfQueries;
use BookStack\Entities\Repos\BookshelfRepo;
use BookStack\Entities\Tools\ShelfContext;
use BookStack\Exceptions\ImageUploadException;
@ -20,8 +21,9 @@ class BookshelfController extends Controller
{
public function __construct(
protected BookshelfRepo $shelfRepo,
protected BookshelfQueries $queries,
protected ShelfContext $shelfContext,
protected ReferenceFetcher $referenceFetcher
protected ReferenceFetcher $referenceFetcher,
) {
}
@ -37,10 +39,15 @@ class BookshelfController extends Controller
'updated_at' => trans('common.sort_updated_at'),
]);
$shelves = $this->shelfRepo->getAllPaginated(18, $listOptions->getSort(), $listOptions->getOrder());
$recents = $this->isSignedIn() ? $this->shelfRepo->getRecentlyViewed(4) : false;
$popular = $this->shelfRepo->getPopular(4);
$new = $this->shelfRepo->getRecentlyCreated(4);
$shelves = $this->queries->visibleForListWithCover()
->orderBy($listOptions->getSort(), $listOptions->getOrder())
->paginate(18);
$recents = $this->isSignedIn() ? $this->queries->recentlyViewedForCurrentUser()->get() : false;
$popular = $this->queries->popularForList()->get();
$new = $this->queries->visibleForList()
->orderBy('created_at', 'desc')
->take(4)
->get();
$this->shelfContext->clearShelfContext();
$this->setPageTitle(trans('entities.shelves'));
@ -96,7 +103,7 @@ class BookshelfController extends Controller
*/
public function show(Request $request, ActivityQueries $activities, string $slug)
{
$shelf = $this->shelfRepo->getBySlug($slug);
$shelf = $this->queries->findVisibleBySlug($slug);
$this->checkOwnablePermission('bookshelf-view', $shelf);
$listOptions = SimpleListOptions::fromRequest($request, 'shelf_books')->withSortOptions([
@ -134,7 +141,7 @@ class BookshelfController extends Controller
*/
public function edit(string $slug)
{
$shelf = $this->shelfRepo->getBySlug($slug);
$shelf = $this->queries->findVisibleBySlug($slug);
$this->checkOwnablePermission('bookshelf-update', $shelf);
$shelfBookIds = $shelf->books()->get(['id'])->pluck('id');
@ -157,7 +164,7 @@ class BookshelfController extends Controller
*/
public function update(Request $request, string $slug)
{
$shelf = $this->shelfRepo->getBySlug($slug);
$shelf = $this->queries->findVisibleBySlug($slug);
$this->checkOwnablePermission('bookshelf-update', $shelf);
$validated = $this->validate($request, [
'name' => ['required', 'string', 'max:255'],
@ -183,7 +190,7 @@ class BookshelfController extends Controller
*/
public function showDelete(string $slug)
{
$shelf = $this->shelfRepo->getBySlug($slug);
$shelf = $this->queries->findVisibleBySlug($slug);
$this->checkOwnablePermission('bookshelf-delete', $shelf);
$this->setPageTitle(trans('entities.shelves_delete_named', ['name' => $shelf->getShortName()]));
@ -198,7 +205,7 @@ class BookshelfController extends Controller
*/
public function destroy(string $slug)
{
$shelf = $this->shelfRepo->getBySlug($slug);
$shelf = $this->queries->findVisibleBySlug($slug);
$this->checkOwnablePermission('bookshelf-delete', $shelf);
$this->shelfRepo->destroy($shelf);