fixed browse and tailwindcss style

This commit is contained in:
2026-02-15 11:01:19 +01:00
parent d114472823
commit 7734e53d87
16 changed files with 341 additions and 200 deletions

View File

@@ -8,6 +8,7 @@ use App\Models\ArtworkFeature;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Contracts\Pagination\CursorPaginator;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Cache;
@@ -23,6 +24,29 @@ class ArtworkService
{
protected int $cacheTtl = 3600; // seconds
/**
* Shared browse query used by /browse, content-type pages, and category pages.
*/
private function browseQuery(string $sort = 'latest'): Builder
{
$query = Artwork::public()
->published()
->with([
'user:id,name',
'categories' => function ($q) {
$q->select('categories.id', 'categories.content_type_id', 'categories.parent_id', 'categories.name', 'categories.slug', 'categories.sort_order')
->with(['parent:id,parent_id,content_type_id,name,slug', 'contentType:id,slug,name']);
},
]);
$normalizedSort = strtolower(trim($sort));
if ($normalizedSort === 'oldest') {
return $query->orderBy('published_at', 'asc');
}
return $query->orderByDesc('published_at');
}
/**
* Fetch a single public artwork by slug.
* Applies visibility rules (public + approved + not-deleted).
@@ -115,18 +139,9 @@ class ArtworkService
* Uses new authoritative tables only (no legacy joins) and eager-loads
* lightweight relations needed for presentation.
*/
public function browsePublicArtworks(int $perPage = 24): CursorPaginator
public function browsePublicArtworks(int $perPage = 24, string $sort = 'latest'): CursorPaginator
{
$query = Artwork::public()
->published()
->with([
'user:id,name',
'categories' => function ($q) {
$q->select('categories.id', 'categories.content_type_id', 'categories.parent_id', 'categories.name', 'categories.slug', 'categories.sort_order')
->with(['parent:id,parent_id,content_type_id,name,slug', 'contentType:id,slug,name']);
},
])
->orderByDesc('published_at');
$query = $this->browseQuery($sort);
// Use cursor pagination for high-load browse feeds (SEO handled via canonical URLs).
return $query->cursorPaginate($perPage);
@@ -136,7 +151,7 @@ class ArtworkService
* Browse artworks scoped to a content type slug using keyset pagination.
* Applies public + approved + published filters.
*/
public function getArtworksByContentType(string $slug, int $perPage): CursorPaginator
public function getArtworksByContentType(string $slug, int $perPage, string $sort = 'latest'): CursorPaginator
{
$contentType = ContentType::where('slug', strtolower($slug))->first();
@@ -146,19 +161,10 @@ class ArtworkService
throw $e;
}
$query = Artwork::public()
->published()
$query = $this->browseQuery($sort)
->whereHas('categories', function ($q) use ($contentType) {
$q->where('categories.content_type_id', $contentType->id);
})
->with([
'user:id,name',
'categories' => function ($q) {
$q->select('categories.id', 'categories.content_type_id', 'categories.parent_id', 'categories.name', 'categories.slug', 'categories.sort_order')
->with(['parent:id,parent_id,content_type_id,name,slug', 'contentType:id,slug,name']);
},
])
->orderByDesc('published_at');
});
return $query->cursorPaginate($perPage);
}
@@ -169,7 +175,7 @@ class ArtworkService
*
* @param array<int, string> $slugs
*/
public function getArtworksByCategoryPath(array $slugs, int $perPage): CursorPaginator
public function getArtworksByCategoryPath(array $slugs, int $perPage, string $sort = 'latest'): CursorPaginator
{
if (empty($slugs)) {
$e = new ModelNotFoundException();
@@ -214,19 +220,10 @@ class ArtworkService
}
}
$query = Artwork::public()
->published()
$query = $this->browseQuery($sort)
->whereHas('categories', function ($q) use ($current) {
$q->where('categories.id', $current->id);
})
->with([
'user:id,name',
'categories' => function ($q) {
$q->select('categories.id', 'categories.content_type_id', 'categories.parent_id', 'categories.name', 'categories.slug', 'categories.sort_order')
->with(['parent:id,parent_id,content_type_id,name,slug', 'contentType:id,slug,name']);
},
])
->orderByDesc('published_at');
});
return $query->cursorPaginate($perPage);
}