basic loading stuffs

This commit is contained in:
red 2025-12-04 14:14:49 +00:00
parent 465f077a9f
commit a161794795
7 changed files with 80 additions and 41 deletions

View File

@ -2,38 +2,65 @@
namespace App\Models; namespace App\Models;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable; use Illuminate\Support\Facades\Log;
use Laravel\Fortify\TwoFactorAuthenticatable;
class Participant extends Authenticatable class Participant extends Model
{ {
/** @use HasFactory<UserFactory> */
use HasFactory; use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [ protected $fillable = [
'user_id', 'user_id',
'giving_id',
'prompt',
'submission_url',
'desperate',
'token', 'token',
]; ];
/** protected $casts = [
* The attributes that should be hidden for serialization. 'desperate' => 'boolean',
*
* @var list<string>
*/
protected $hidden = [
'token',
]; ];
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;
} }
} }

View File

@ -14,7 +14,8 @@
"laravel/framework": "^12.0", "laravel/framework": "^12.0",
"laravel/tinker": "^2.10.1", "laravel/tinker": "^2.10.1",
"livewire/flux": "^2.9.0", "livewire/flux": "^2.9.0",
"livewire/volt": "^1.7.0" "livewire/volt": "^1.7.0",
"ext-curl": "*"
}, },
"require-dev": { "require-dev": {
"fakerphp/faker": "^1.23", "fakerphp/faker": "^1.23",
@ -24,7 +25,8 @@
"mockery/mockery": "^1.6", "mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.6", "nunomaduro/collision": "^8.6",
"pestphp/pest": "^4.1", "pestphp/pest": "^4.1",
"pestphp/pest-plugin-laravel": "^4.0" "pestphp/pest-plugin-laravel": "^4.0",
"ext-curl": "*"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

11
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "dfe0e74063033164e5069fc96d3bb510", "content-hash": "c78bcab45d4b86c31ecc79b40f1a12ad",
"packages": [ "packages": [
{ {
"name": "bacon/bacon-qr-code", "name": "bacon/bacon-qr-code",
@ -9834,8 +9834,11 @@
"prefer-stable": true, "prefer-stable": true,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
"php": "^8.2" "php": "^8.2",
"ext-curl": "*"
}, },
"platform-dev": {}, "platform-dev": {
"plugin-api-version": "2.9.0" "ext-curl": "*"
},
"plugin-api-version": "2.6.0"
} }

View File

@ -24,8 +24,9 @@ class ParticipantFactory extends Factory
public function definition(): array public function definition(): array
{ {
return [ return [
'name' => fake()->unique()->randomNumber(), 'id' => fake()->unique()->randomNumber(),
'token' => Str::random(32), 'token' => Str::random(32),
'user_id' => fake()->unique()->randomNumber(),
]; ];
} }

View File

@ -13,18 +13,18 @@ return new class extends Migration
{ {
Schema::create('participants', function (Blueprint $table) { Schema::create('participants', function (Blueprint $table) {
$table->id(); $table->id();
$table->unsignedBigInteger('user_id');
$table->unsignedBigInteger('giving_id')->nullable(); $table->unsignedBigInteger('giving_id')->nullable();
$table->unsignedBigInteger('receiving_id')->nullable();
$table->foreign('giving_id')->references('id')->on('participants')->onDelete('set null'); $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('prompt')->nullable();
$table->string('submission_url'); $table->string('submission_url')->nullable();
$table->boolean('desperate')->default(false); $table->boolean('desperate')->default(false);
$table->string('token'); $table->string('token');
$table->timestamps();
}); });
} }

View File

@ -1,20 +1,26 @@
<?php <?php
use function Livewire\Volt\state;
use App\Models\Participant; use App\Models\Participant;
use Illuminate\Support\Facades\Log;
use function Livewire\Volt\{computed, state};
$props = ['token']; state(['token'])->url();
$token = 0; $participant = computed(function () {
state([ return Participant::findByToken($this->token);
'count' => 0, });
'user' => Participant::find($token),
]);
$increment = fn () => $this->count++; $userData = computed(function () {
return $this->participant->getUserData();
});
?> ?>
@if($this->participant)
<div> <div>
<h1>User: {{$user?->name ?? 'Not found'}}</h1> <pre>{{ $this->participant }}</pre>
@if($this->userData)
<h1><img src ="{{ $this->userData['data']['profile_image_url'] }}"> {{ $this->userData['data']['username'] }}</h1>
@endif
</div> </div>
@endif

View File

@ -15,7 +15,7 @@ Route::get('/', function () {
})->name('home'); })->name('home');
Volt::route('start', 'pages.start')->name('start'); 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'); Volt::route('withdraw', 'pages.withdraw')->name('withdraw');
Route::middleware(['auth'])->group(function () { Route::middleware(['auth'])->group(function () {