fedi-feed-router/backend/app/Http/Controllers/OnboardingController.php

114 lines
No EOL
3.1 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Feed;
use App\Models\PlatformAccount;
use App\Models\PlatformChannel;
use App\Models\PlatformInstance;
use App\Services\SystemStatusService;
use App\Services\DashboardStatsService;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Illuminate\Http\RedirectResponse;
class OnboardingController extends Controller
{
public function index(Request $request): View|RedirectResponse
{
// Check if user needs onboarding
if (!$this->needsOnboarding()) {
$systemStatus = resolve(SystemStatusService::class)->getSystemStatus();
$statsService = resolve(DashboardStatsService::class);
$period = $request->get('period', 'today');
$stats = $statsService->getStats($period);
$systemStats = $statsService->getSystemStats();
$availablePeriods = $statsService->getAvailablePeriods();
return view('pages.dashboard', compact(
'systemStatus',
'stats',
'systemStats',
'availablePeriods',
'period'
));
}
return view('onboarding.welcome');
}
public function platform(): View|RedirectResponse
{
if (!$this->needsOnboarding()) {
return redirect()->route('feeds.index');
}
return view('onboarding.platform');
}
public function feed(): View|RedirectResponse
{
if (!$this->needsOnboarding()) {
return redirect()->route('feeds.index');
}
if (!$this->hasPlatformAccount()) {
return redirect()->route('onboarding.platform');
}
return view('onboarding.feed');
}
public function channel(): View|RedirectResponse
{
if (!$this->needsOnboarding()) {
return redirect()->route('feeds.index');
}
if (!$this->hasPlatformAccount()) {
return redirect()->route('onboarding.platform');
}
if (!$this->hasFeed()) {
return redirect()->route('onboarding.feed');
}
return view('onboarding.channel');
}
public function complete(): View|RedirectResponse
{
if (!$this->needsOnboarding()) {
return redirect()->route('feeds.index');
}
if (!$this->hasPlatformAccount() || !$this->hasFeed() || !$this->hasChannel()) {
return redirect()->route('onboarding.index');
}
$systemStatus = resolve(SystemStatusService::class)->getSystemStatus();
return view('onboarding.complete', compact('systemStatus'));
}
private function needsOnboarding(): bool
{
return !$this->hasPlatformAccount() || !$this->hasFeed() || !$this->hasChannel();
}
private function hasPlatformAccount(): bool
{
return PlatformAccount::where('is_active', true)->exists();
}
private function hasFeed(): bool
{
return Feed::where('is_active', true)->exists();
}
private function hasChannel(): bool
{
return PlatformChannel::where('is_active', true)->exists();
}
}