diff --git a/app/Models/Participant.php b/app/Models/Participant.php index 08fb212..3b610d8 100644 --- a/app/Models/Participant.php +++ b/app/Models/Participant.php @@ -2,38 +2,65 @@ namespace App\Models; -use Database\Factories\UserFactory; use Illuminate\Database\Eloquent\Factories\HasFactory; -use Illuminate\Foundation\Auth\User as Authenticatable; -use Illuminate\Notifications\Notifiable; -use Laravel\Fortify\TwoFactorAuthenticatable; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Log; -class Participant extends Authenticatable +class Participant extends Model { - /** @use HasFactory */ use HasFactory; - /** - * The attributes that are mass assignable. - * - * @var list - */ protected $fillable = [ 'user_id', + 'giving_id', + 'prompt', + 'submission_url', + 'desperate', 'token', ]; - /** - * The attributes that should be hidden for serialization. - * - * @var list - */ - protected $hidden = [ - 'token', + protected $casts = [ + 'desperate' => 'boolean', ]; - public function getToken(): int + public function giver() { - return 0; + return $this->belongsTo(Participant::class, 'giving_id'); + } + + public function receiver() + { + return $this->hasOne(Participant::class, 'giving_id', 'id'); + } + + public static function findByToken(string $token): ?self + { + return self::where('token', $token)->first(); + } + + public function getUserData(): ?array + { + + if (!$this->token) return null; + + $url = "https://sketchersunited.org/users/{$this->user_id}"; + + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'Accept: application/json' + ]); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); + + $response = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + if ($response !== false && $httpCode === 200) { + + return json_decode($response, true); + } + Log::info($this->user_id); + return null; } } diff --git a/composer.json b/composer.json index 4ae469b..0070991 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,8 @@ "laravel/framework": "^12.0", "laravel/tinker": "^2.10.1", "livewire/flux": "^2.9.0", - "livewire/volt": "^1.7.0" + "livewire/volt": "^1.7.0", + "ext-curl": "*" }, "require-dev": { "fakerphp/faker": "^1.23", @@ -24,7 +25,8 @@ "mockery/mockery": "^1.6", "nunomaduro/collision": "^8.6", "pestphp/pest": "^4.1", - "pestphp/pest-plugin-laravel": "^4.0" + "pestphp/pest-plugin-laravel": "^4.0", + "ext-curl": "*" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index e0c6d15..43a3447 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "dfe0e74063033164e5069fc96d3bb510", + "content-hash": "c78bcab45d4b86c31ecc79b40f1a12ad", "packages": [ { "name": "bacon/bacon-qr-code", @@ -9834,8 +9834,11 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^8.2" + "php": "^8.2", + "ext-curl": "*" }, - "platform-dev": {}, - "plugin-api-version": "2.9.0" + "platform-dev": { + "ext-curl": "*" + }, + "plugin-api-version": "2.6.0" } diff --git a/database/factories/ParticipantFactory.php b/database/factories/ParticipantFactory.php index 8efa4de..0fbaf4d 100644 --- a/database/factories/ParticipantFactory.php +++ b/database/factories/ParticipantFactory.php @@ -24,8 +24,9 @@ class ParticipantFactory extends Factory public function definition(): array { return [ - 'name' => fake()->unique()->randomNumber(), + 'id' => fake()->unique()->randomNumber(), 'token' => Str::random(32), + 'user_id' => fake()->unique()->randomNumber(), ]; } diff --git a/database/migrations/2025_12_04_105253_add_participants_table.php b/database/migrations/2025_12_04_105253_add_participants_table.php index 62b6e4b..578db7c 100644 --- a/database/migrations/2025_12_04_105253_add_participants_table.php +++ b/database/migrations/2025_12_04_105253_add_participants_table.php @@ -13,18 +13,18 @@ return new class extends Migration { Schema::create('participants', function (Blueprint $table) { $table->id(); + $table->unsignedBigInteger('user_id'); $table->unsignedBigInteger('giving_id')->nullable(); - $table->unsignedBigInteger('receiving_id')->nullable(); $table->foreign('giving_id')->references('id')->on('participants')->onDelete('set null'); - $table->foreign('receiving_id')->references('id')->on('participants')->onDelete('set null'); - $table->string('prompt'); - $table->string('submission_url'); + $table->string('prompt')->nullable(); + $table->string('submission_url')->nullable(); $table->boolean('desperate')->default(false); $table->string('token'); + $table->timestamps(); }); } diff --git a/resources/views/livewire/pages/profile.blade.php b/resources/views/livewire/pages/profile.blade.php index 7fa3e1d..7006b79 100644 --- a/resources/views/livewire/pages/profile.blade.php +++ b/resources/views/livewire/pages/profile.blade.php @@ -1,20 +1,26 @@ url(); -$token = 0; -state([ - 'count' => 0, - 'user' => Participant::find($token), -]); +$participant = computed(function () { + return Participant::findByToken($this->token); +}); -$increment = fn () => $this->count++; +$userData = computed(function () { + return $this->participant->getUserData(); +}); ?> +@if($this->participant)
-

User: {{$user?->name ?? 'Not found'}}

+
{{ $this->participant }}
+ @if($this->userData) +

{{ $this->userData['data']['username'] }}

+ @endif
+@endif diff --git a/routes/web.php b/routes/web.php index 144e0df..a6d6c3a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -15,7 +15,7 @@ Route::get('/', function () { })->name('home'); Volt::route('start', 'pages.start')->name('start'); -Volt::route('profile', 'pages.profile')->name('profile'); +Volt::route('profile/{token}', 'pages.profile')->name('profile'); Volt::route('withdraw', 'pages.withdraw')->name('withdraw'); Route::middleware(['auth'])->group(function () {