- Moved logic from MainController to dedicated action and task classes. - Introduced GetMainPageDataAction, GetEducationsDataTask, GetRecentPostsTask, GetUpcomingEventsTask, and GetPageDataTask for better separation of concerns. - Updated routes to use the new MainController from the Main container. - Deprecated the old MainController with a clear message for future removal. - Updated caching mechanisms to use the new task classes. - Adjusted environment variable access to use config() instead of env() for better practice. - Added new MainPageResource for structured data response. - Updated .gitignore to exclude QWEN.md. - Added Jenkins service to docker-compose for CI/CD integration.
32 lines
962 B
PHP
32 lines
962 B
PHP
<?php
|
|
|
|
namespace App\Containers\Main\Tasks;
|
|
|
|
use App\Containers\Article\Enums\PostStatus;
|
|
use App\Containers\Article\Models\Post;
|
|
use App\Containers\Widget\UI\API\Transformers\PostThumbnailResource;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class GetRecentPostsTask
|
|
{
|
|
public function run()
|
|
{
|
|
return Cache::remember('posts_recent', now()->addHour(), function () {
|
|
return $this->getRecentPosts();
|
|
});
|
|
}
|
|
|
|
private function getRecentPosts()
|
|
{
|
|
return PostThumbnailResource::collection(
|
|
Post::select('title', 'slug', 'authors', 'preview_text', 'category_id', 'preview', 'search_data', 'publish_at', 'created_at')
|
|
->with('category')
|
|
->where('publish_at', '<', Carbon::now())
|
|
->where('status', '=', PostStatus::PUBLISHED)
|
|
->orderBy('publish_at', 'desc')
|
|
->limit(3)
|
|
->get()
|
|
);
|
|
}
|
|
} |