diff --git a/app/Http/Controllers/ParticipantController.php b/app/Http/Controllers/ParticipantController.php index da7892c..26850c7 100644 --- a/app/Http/Controllers/ParticipantController.php +++ b/app/Http/Controllers/ParticipantController.php @@ -3,21 +3,28 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Participant; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; class ParticipantController extends Controller { - public function createFromToken(Request $request, string $id) + public static function createFromToken(Request $request, string $id) { - if ($request->input('password') !== env('ADMIN__PASSWORD')) { + if ($request->input('password') !== 'password123') { return response()->json(['message' => 'Unauthorized: Wrong password'], 401); } - $participant = Participant::create([ - 'user_id' => $id, - 'token' => (string) Str::ulid() - ]); + if(!Participant::where('id', $id)->exists()) { + $participant = Participant::create([ + 'user_id' => $id, + 'token' => (string) Str::ulid() + ]); - return $participant->token; + return $participant->token; + } + else { + $participant = Participant::where('id', $id)->first(); + return $participant->token; + } } } diff --git a/bootstrap/app.php b/bootstrap/app.php index c183276..c3928c5 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -7,6 +7,7 @@ use Illuminate\Foundation\Configuration\Middleware; return Application::configure(basePath: dirname(__DIR__)) ->withRouting( web: __DIR__.'/../routes/web.php', + api: __DIR__.'/../routes/api.php', commands: __DIR__.'/../routes/console.php', health: '/up', ) diff --git a/database/factories/ParticipantFactory.php b/database/factories/ParticipantFactory.php index ef82083..cc04f5c 100644 --- a/database/factories/ParticipantFactory.php +++ b/database/factories/ParticipantFactory.php @@ -24,9 +24,7 @@ class ParticipantFactory extends Factory public function definition(): array { return [ - 'id' => fake()->unique()->randomNumber(), 'token' => (string) Str::ulid(), - 'user_id' => fake()->unique()->randomNumber(), ]; } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 3ba09ec..4da4f16 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -4,7 +4,7 @@ namespace Database\Seeders; use App\Models\Participant; use App\Models\User; -// use Illuminate\Database\Console\Seeds\WithoutModelEvents; +use Illuminate\Database\Eloquent\Factories\Sequence; use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder @@ -14,7 +14,11 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - Participant::factory(10)->create(); - + Participant::factory(100) + ->sequence(fn (Sequence $sequence) => [ + 'id' => $sequence->index + 1, + 'user_id' => $sequence->index + 1, + ]) + ->create(); } } diff --git a/routes/api.php b/routes/api.php new file mode 100644 index 0000000..a12b1e1 --- /dev/null +++ b/routes/api.php @@ -0,0 +1,7 @@ +group(function () { - Route::get('/token/{id}', function ($id) { - return $id; // todo return the token from participant auth controller - }); -}); - Route::get('/', function () { return view('welcome'); })->name('home'); @@ -17,7 +10,3 @@ Route::get('/', function () { Volt::route('start', 'pages.start')->name('start'); Volt::route('profile/{token}', 'pages.profile')->name('profile'); Volt::route('withdraw', 'pages.withdraw')->name('withdraw'); - -Route::middleware(['auth'])->group(function () { - -});