Wire admin studio SSR and search infrastructure

This commit is contained in:
2026-05-01 11:46:06 +02:00
parent 257b0dbef6
commit 18cea8b0f0
329 changed files with 197465 additions and 2741 deletions

View File

@@ -214,43 +214,7 @@ class ArtworkService
*/
public function getArtworksByCategoryPath(array $slugs, int $perPage, string $sort = 'latest'): CursorPaginator
{
if (empty($slugs)) {
$e = new ModelNotFoundException();
$e->setModel(Category::class);
throw $e;
}
$parts = array_values(array_map('strtolower', $slugs));
$contentTypeSlug = array_shift($parts);
$contentType = $this->resolveContentTypeOrFail((string) $contentTypeSlug);
if (empty($parts)) {
$e = new ModelNotFoundException();
$e->setModel(Category::class, []);
throw $e;
}
// Resolve the category path from roots downward within the content type.
$current = Category::where('content_type_id', $contentType->id)
->whereNull('parent_id')
->where('slug', array_shift($parts))
->first();
if (! $current) {
$e = new ModelNotFoundException();
$e->setModel(Category::class, $slugs);
throw $e;
}
foreach ($parts as $slug) {
$current = $current->children()->where('slug', $slug)->first();
if (! $current) {
$e = new ModelNotFoundException();
$e->setModel(Category::class, $slugs);
throw $e;
}
}
$current = $this->resolveCategoryByPath($slugs);
$categoryIds = $this->categoryAndDescendantIds($current);
@@ -262,6 +226,69 @@ class ArtworkService
return $query->cursorPaginate($perPage);
}
/**
* Resolve a category path within a content type using one category query.
*
* @param array<int, string> $slugs
* @throws ModelNotFoundException
*/
public function resolveCategoryByPath(array $slugs): Category
{
if (empty($slugs)) {
$e = new ModelNotFoundException();
$e->setModel(Category::class);
throw $e;
}
$parts = array_values(array_map('strtolower', $slugs));
$contentTypeSlug = array_shift($parts);
$contentType = $this->resolveContentTypeOrFail((string) $contentTypeSlug);
if (empty($parts)) {
$e = new ModelNotFoundException();
$e->setModel(Category::class, []);
throw $e;
}
$categories = Category::query()
->where('content_type_id', $contentType->id)
->get();
$categoriesByParent = [];
foreach ($categories as $category) {
$parentId = $category->parent_id !== null ? (int) $category->parent_id : 0;
$categoriesByParent[$parentId][strtolower((string) $category->slug)] = $category;
$category->setRelation('contentType', $contentType);
}
$current = null;
$parentId = 0;
foreach ($parts as $slug) {
$next = $categoriesByParent[$parentId][$slug] ?? null;
if (! $next instanceof Category) {
$e = new ModelNotFoundException();
$e->setModel(Category::class, $slugs);
throw $e;
}
if ($current instanceof Category) {
$next->setRelation('parent', $current);
}
$current = $next;
$parentId = (int) $current->id;
}
if (! $current instanceof Category) {
$e = new ModelNotFoundException();
$e->setModel(Category::class, $slugs);
throw $e;
}
return $current;
}
/**
* Collect category id plus all descendant category ids.
*