Queries: Addressed failing test cases from recent changes

This commit is contained in:
Dan Brown 2024-02-08 17:18:03 +00:00
parent ed21a6d798
commit ed9c013f6e
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
8 changed files with 18 additions and 12 deletions

View File

@ -17,11 +17,11 @@ class FavouriteController extends Controller
/**
* Show a listing of all favourite items for the current user.
*/
public function index(Request $request)
public function index(Request $request, QueryTopFavourites $topFavourites)
{
$viewCount = 20;
$page = intval($request->get('page', 1));
$favourites = (new QueryTopFavourites())->run($viewCount + 1, (($page - 1) * $viewCount));
$favourites = $topFavourites->run($viewCount + 1, (($page - 1) * $viewCount));
$hasMoreLink = ($favourites->count() > $viewCount) ? url('/favourites?page=' . ($page + 1)) : null;

View File

@ -9,7 +9,8 @@ use Illuminate\Database\Eloquent\Builder;
class BookQueries implements ProvidesEntityQueries
{
protected static array $listAttributes = [
'id', 'slug', 'name', 'description', 'created_at', 'updated_at', 'image_id'
'id', 'slug', 'name', 'description',
'created_at', 'updated_at', 'image_id', 'owned_by',
];
public function start(): Builder

View File

@ -9,7 +9,8 @@ use Illuminate\Database\Eloquent\Builder;
class BookshelfQueries implements ProvidesEntityQueries
{
protected static array $listAttributes = [
'id', 'slug', 'name', 'description', 'created_at', 'updated_at', 'image_id'
'id', 'slug', 'name', 'description',
'created_at', 'updated_at', 'image_id', 'owned_by',
];
public function start(): Builder

View File

@ -10,7 +10,7 @@ class ChapterQueries implements ProvidesEntityQueries
{
protected static array $listAttributes = [
'id', 'slug', 'name', 'description', 'priority',
'created_at', 'updated_at'
'book_id', 'created_at', 'updated_at', 'owned_by',
];
public function start(): Builder

View File

@ -10,11 +10,12 @@ class PageQueries implements ProvidesEntityQueries
{
protected static array $contentAttributes = [
'name', 'id', 'slug', 'book_id', 'chapter_id', 'draft',
'template', 'html', 'text', 'created_at', 'updated_at', 'priority'
'template', 'html', 'text', 'created_at', 'updated_at', 'priority',
'created_by', 'updated_by', 'owned_by',
];
protected static array $listAttributes = [
'name', 'id', 'slug', 'book_id', 'chapter_id', 'draft',
'template', 'text', 'created_at', 'updated_at', 'priority'
'template', 'text', 'created_at', 'updated_at', 'priority', 'owned_by',
];
public function start(): Builder

View File

@ -329,13 +329,14 @@ class PageContent
protected function getContentProviderClosure(bool $blankIncludes): Closure
{
$contextPage = $this->page;
$queries = $this->pageQueries;
return function (PageIncludeTag $tag) use ($blankIncludes, $contextPage): PageIncludeContent {
return function (PageIncludeTag $tag) use ($blankIncludes, $contextPage, $queries): PageIncludeContent {
if ($blankIncludes) {
return PageIncludeContent::fromHtmlAndTag('', $tag);
}
$matchedPage = $this->pageQueries->findVisibleById($tag->getPageId());
$matchedPage = $queries->findVisibleById($tag->getPageId());
$content = PageIncludeContent::fromHtmlAndTag($matchedPage->html ?? '', $tag);
if (Theme::hasListeners(ThemeEvents::PAGE_INCLUDE_PARSE)) {

View File

@ -38,7 +38,8 @@ class PageEditorData
$templates = $this->queries->pages->visibleTemplates()
->orderBy('name', 'asc')
->take(10)
->get();
->paginate()
->withPath('/templates');
$draftsEnabled = auth()->check();
@ -51,7 +52,7 @@ class PageEditorData
}
// Check for a current draft version for this user
$userDraft = $this->queries->revisions->findLatestCurrentUserDraftsForPageId($page->id)->first();
$userDraft = $this->queries->revisions->findLatestCurrentUserDraftsForPageId($page->id);
if (!is_null($userDraft)) {
$page->forceFill($userDraft->only(['name', 'html', 'markdown']));
$isDraftRevision = true;

View File

@ -14,6 +14,7 @@ class SiblingFetcher
{
public function __construct(
protected EntityQueries $queries,
protected ShelfContext $shelfContext,
) {
}
@ -38,7 +39,7 @@ class SiblingFetcher
// Book
// Gets just the books in a shelf if shelf is in context
if ($entity instanceof Book) {
$contextShelf = (new ShelfContext())->getContextualShelfForBook($entity);
$contextShelf = $this->shelfContext->getContextualShelfForBook($entity);
if ($contextShelf) {
$entities = $contextShelf->visibleBooks()->get();
} else {