Files
ntspi-app/app/Containers/Article/Actions/ListPostsAction.php
F4ilji c01016a154 Migrate backend to Porto architecture and fix minor bugs
- Fully transitioned the backend to the Porto architectural pattern
- Improved code organization and maintainability
- Fixed minor bugs and inconsistencies
2025-05-12 08:47:43 +05:00

39 lines
1.3 KiB
PHP

<?php
namespace App\Containers\Article\Actions;
use App\Containers\Article\Tasks\BuildFiltersTask;
use App\Containers\Article\Tasks\GetCategoriesTask;
use App\Containers\Article\Tasks\GetPostsTask;
use App\Containers\Article\Tasks\GetTagsTask;
use App\Containers\Article\UI\WEB\Transformers\PostListResource;
use App\Ship\Contracts\SeoServiceInterface;
class ListPostsAction
{
public function __construct(
private readonly GetPostsTask $getPostsTask,
private readonly GetCategoriesTask $getCategoriesTask,
private readonly GetTagsTask $getTagsTask,
private readonly BuildFiltersTask $buildFiltersTask,
private readonly SeoServiceInterface $seoPageProvider,
) {}
public function run(array $filters): array
{
$posts = $this->getPostsTask->run($filters);
$categories = $this->getCategoriesTask->run();
$tags = $this->getTagsTask->run();
$filtersData = $this->buildFiltersTask->run($filters);
$seo = $this->seoPageProvider->getSeoForCurrentPage();
return [
'posts' => inertia()->deepMerge(fn() => PostListResource::collection($posts->items())),
'posts_pagination' => $posts->toArray(),
'filters' => $filtersData,
'categories' => $categories,
'tags' => $tags,
'seo' => $seo,
];
}
}