Дашборд, зоны, устройства, правила автоматизации и профиль теперь Vue 3 + Inertia вместо Blade+Alpine — гостевые страницы Breeze (логин/регистрация) сознательно оставлены на Blade, чтобы не трогать уже протестированную аутентификацию. Контроллеры возвращают Inertia::render() вместо view(), переиспользуют существующие API Resources и FormRequest. Ключевой нюанс: Resource/ResourceCollection, переданные напрямую в проп Inertia, заворачиваются в ключ "data" (Inertia вызывает toResponse() у Responsable-объектов) — везде используется ->resolve() и явное резолвление вложенных ресурсов (zone/device_type внутри Device и т.п.), иначе вложенные поля тоже задваивались бы обёрткой. Alpine.js и все Blade-вьюхи защищённой части удалены как мёртвый код. Тесты (ZoneControllerTest/DeviceControllerTest) переведены на assertInertia(). UserFactory теперь явно задаёт role=owner — без этого Eloquent не подтягивает DB-default обратно в модель после create(), что уронило бы общий auth.user проп на любой странице.
51 lines
2.0 KiB
PHP
51 lines
2.0 KiB
PHP
<?php
|
|
|
|
use App\Http\Controllers\AutomationRuleController;
|
|
use App\Http\Controllers\DeviceController;
|
|
use App\Http\Controllers\ProfileController;
|
|
use App\Http\Controllers\ZoneController;
|
|
use App\Models\AutomationRule;
|
|
use App\Models\Device;
|
|
use App\Models\Zone;
|
|
use App\Services\DeviceShadow;
|
|
use Illuminate\Support\Facades\Route;
|
|
use Inertia\Inertia;
|
|
|
|
Route::get('/', function () {
|
|
return view('welcome');
|
|
});
|
|
|
|
Route::get('/dashboard', function (DeviceShadow $shadow) {
|
|
$devices = Device::all();
|
|
$onlineCount = collect($shadow->statuses($devices->pluck('external_id')->all()))
|
|
->filter(fn (string $status) => $status === 'online')
|
|
->count();
|
|
|
|
return Inertia::render('Dashboard', [
|
|
'zonesCount' => Zone::count(),
|
|
'devicesCount' => $devices->count(),
|
|
'onlineDevicesCount' => $onlineCount,
|
|
'activeRulesCount' => AutomationRule::where('is_active', true)->count(),
|
|
]);
|
|
})->middleware(['auth', 'verified'])->name('dashboard');
|
|
|
|
Route::middleware(['auth', 'verified'])->group(function () {
|
|
Route::resource('zones', ZoneController::class)->except('show');
|
|
Route::resource('devices', DeviceController::class);
|
|
Route::resource('automation-rules', AutomationRuleController::class)
|
|
->except('show')
|
|
->parameters(['automation-rules' => 'automation_rule']);
|
|
|
|
Route::post('/devices/{device}/turn-on', [DeviceController::class, 'turnOn'])->name('devices.turn-on');
|
|
Route::post('/devices/{device}/turn-off', [DeviceController::class, 'turnOff'])->name('devices.turn-off');
|
|
Route::post('/devices/{device}/set-level', [DeviceController::class, 'setLevel'])->name('devices.set-level');
|
|
});
|
|
|
|
Route::middleware('auth')->group(function () {
|
|
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
|
|
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
|
|
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
|
|
});
|
|
|
|
require __DIR__.'/auth.php';
|