refactor ClientDepartmentController and ClientFacultyController; replace caching logic with action classes for department and faculty retrieval, enhancing code clarity and maintainability
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\InstituteStructure\Tasks;
|
||||
|
||||
use App\Containers\InstituteStructure\Models\Department;
|
||||
use App\Ship\Enums\CacheKeys;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class GetDepartmentBySlugTask
|
||||
{
|
||||
public function run(string $departmentSlug, string $cacheKey): Department
|
||||
{
|
||||
return Cache::remember(
|
||||
CacheKeys::DEPARTMENT_PREFIX->value . $cacheKey,
|
||||
now()->addDay(),
|
||||
function () use ($departmentSlug) {
|
||||
return Department::query()
|
||||
->where('slug', $departmentSlug)
|
||||
->where('is_active', true)
|
||||
->with([
|
||||
'faculty',
|
||||
'workers' => fn ($query) => $query->orderBy('sort', 'asc'),
|
||||
'teachers' => fn ($query) => $query->orderBy('sort', 'asc'),
|
||||
'programs' => fn ($query) => $query->orderBy('sort', 'asc'),
|
||||
'workers.userDetail',
|
||||
'teachers.userDetail',
|
||||
'programs.directionStudy',
|
||||
'seo'
|
||||
])
|
||||
->firstOrFail();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user