diff --git a/app/Http/Controllers/FeedsController.php b/app/Http/Controllers/FeedsController.php index 88599d4..c23040d 100644 --- a/app/Http/Controllers/FeedsController.php +++ b/app/Http/Controllers/FeedsController.php @@ -29,7 +29,7 @@ public function store(Request $request): RedirectResponse 'name' => 'required|string|max:255', 'url' => 'required|url|unique:feeds,url', 'type' => 'required|in:website,rss', - 'language' => 'required|string|size:2', + 'language_id' => 'required|exists:languages,id', 'description' => 'nullable|string', 'is_active' => 'boolean' ]); @@ -39,6 +39,13 @@ public function store(Request $request): RedirectResponse Feed::create($validated); + // Check if there's a redirect_to parameter for onboarding flow + $redirectTo = $request->input('redirect_to'); + if ($redirectTo) { + return redirect($redirectTo) + ->with('success', 'Feed created successfully!'); + } + return redirect()->route('feeds.index') ->with('success', 'Feed created successfully!'); } @@ -59,7 +66,7 @@ public function update(Request $request, Feed $feed): RedirectResponse 'name' => 'required|string|max:255', 'url' => 'required|url|unique:feeds,url,' . $feed->id, 'type' => 'required|in:website,rss', - 'language' => 'required|string|size:2', + 'language_id' => 'required|exists:languages,id', 'description' => 'nullable|string', 'is_active' => 'boolean' ]); diff --git a/app/Http/Controllers/OnboardingController.php b/app/Http/Controllers/OnboardingController.php new file mode 100644 index 0000000..3c37e59 --- /dev/null +++ b/app/Http/Controllers/OnboardingController.php @@ -0,0 +1,96 @@ +needsOnboarding()) { + return redirect()->route('feeds.index'); + } + + 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'); + } + + return view('onboarding.complete'); + } + + 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(); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/PlatformAccountsController.php b/app/Http/Controllers/PlatformAccountsController.php index 029f6fa..2d3870c 100644 --- a/app/Http/Controllers/PlatformAccountsController.php +++ b/app/Http/Controllers/PlatformAccountsController.php @@ -3,6 +3,8 @@ namespace App\Http\Controllers; use App\Models\PlatformAccount; +use App\Models\PlatformInstance; +use App\Enums\PlatformEnum; use Illuminate\Http\Request; use Illuminate\Contracts\View\View; use Illuminate\Http\RedirectResponse; @@ -31,6 +33,17 @@ public function store(Request $request): RedirectResponse 'settings' => 'nullable|array', ]); + // Create or find platform instance + $platformEnum = PlatformEnum::from($validated['platform']); + $instance = PlatformInstance::firstOrCreate([ + 'platform' => $platformEnum, + 'url' => $validated['instance_url'], + ], [ + 'name' => parse_url($validated['instance_url'], PHP_URL_HOST), + 'description' => ucfirst($validated['platform']) . ' instance', + 'is_active' => true, + ]); + $account = PlatformAccount::create($validated); // If this is the first account for this platform, make it active @@ -38,6 +51,13 @@ public function store(Request $request): RedirectResponse $account->setAsActive(); } + // Check if there's a redirect_to parameter for onboarding flow + $redirectTo = $request->input('redirect_to'); + if ($redirectTo) { + return redirect($redirectTo) + ->with('success', 'Platform account created successfully!'); + } + return redirect()->route('platforms.index') ->with('success', 'Platform account created successfully!'); } diff --git a/app/Http/Controllers/PlatformChannelsController.php b/app/Http/Controllers/PlatformChannelsController.php index 6816d21..7658421 100644 --- a/app/Http/Controllers/PlatformChannelsController.php +++ b/app/Http/Controllers/PlatformChannelsController.php @@ -34,13 +34,28 @@ public function store(Request $request): RedirectResponse $validated = $request->validate([ 'platform_instance_id' => 'required|exists:platform_instances,id', 'name' => 'required|string|max:255', - 'display_name' => 'required|string|max:255', - 'channel_id' => 'required|string|max:255', + 'display_name' => 'nullable|string|max:255', + 'channel_id' => 'nullable|string|max:255', 'description' => 'nullable|string', + 'language_id' => 'required|exists:languages,id', + 'is_active' => 'boolean', ]); + // Default is_active to true if not provided + $validated['is_active'] = $validated['is_active'] ?? true; + + // Set display_name to name if not provided + $validated['display_name'] = $validated['display_name'] ?? $validated['name']; + PlatformChannel::create($validated); + // Check if there's a redirect_to parameter for onboarding flow + $redirectTo = $request->input('redirect_to'); + if ($redirectTo) { + return redirect($redirectTo) + ->with('success', 'Channel created successfully!'); + } + return redirect()->route('channels.index') ->with('success', 'Channel created successfully!'); } diff --git a/resources/views/onboarding/channel.blade.php b/resources/views/onboarding/channel.blade.php new file mode 100644 index 0000000..5367e37 --- /dev/null +++ b/resources/views/onboarding/channel.blade.php @@ -0,0 +1,110 @@ +@extends('layouts.app') + +@section('content') +
+ Set up a Lemmy community where articles will be posted +
+ + ++ Great! You've successfully configured Lemmy Poster. Your feeds will now be monitored and articles will be automatically posted to your configured channels. +
++ Set up routing rules to control which articles get posted where based on keywords, titles, or content. +
+ + Configure Routing → + ++ Add a RSS feed or website to monitor for new articles +
+ + ++ Enter your Lemmy instance details and login credentials +
+ + ++ Let's get you set up! We'll help you configure your Lemmy account, add your first feed, and create a channel for posting. +
+ +