build: initialize RetroHub with Laravel, Inertia, Vue, and Horizon
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Settings\Data;
|
||||
|
||||
use App\Features\Settings\Models\SaveFile;
|
||||
use Spatie\LaravelData\Attributes\MapInputName;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
||||
|
||||
#[MapInputName(SnakeCaseMapper::class)]
|
||||
class SaveFileData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public int $userId,
|
||||
public int $gameId,
|
||||
public string $filePath,
|
||||
public string $fileName,
|
||||
public int $fileSize,
|
||||
public ?string $lastSyncedAt,
|
||||
) {}
|
||||
|
||||
public static function fromModel(SaveFile $saveFile): self
|
||||
{
|
||||
return new self(
|
||||
id: $saveFile->id,
|
||||
userId: $saveFile->user_id,
|
||||
gameId: $saveFile->game_id,
|
||||
filePath: $saveFile->file_path,
|
||||
fileName: $saveFile->file_name,
|
||||
fileSize: $saveFile->file_size,
|
||||
lastSyncedAt: $saveFile->last_synced_at?->toISOString(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Settings\Models;
|
||||
|
||||
use App\Features\Games\Models\Game;
|
||||
use App\Models\User;
|
||||
use Database\Factories\SaveFileFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class SaveFile extends Model
|
||||
{
|
||||
/** @use HasFactory<SaveFileFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected static ?string $factory = SaveFileFactory::class;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'game_id',
|
||||
'file_path',
|
||||
'file_name',
|
||||
'file_size',
|
||||
'last_synced_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'last_synced_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function game(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Game::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Settings\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Database\Factories\UserSettingFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserSetting extends Model
|
||||
{
|
||||
/** @use HasFactory<UserSettingFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected static ?string $factory = UserSettingFactory::class;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'setting_key',
|
||||
'setting_value',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Settings\Repositories;
|
||||
|
||||
use App\Features\Settings\Models\SaveFile;
|
||||
use App\Features\Settings\Models\UserSetting;
|
||||
use App\Models\User;
|
||||
|
||||
class SettingsRepository
|
||||
{
|
||||
public function __construct(
|
||||
private SaveFile $saveFileModel,
|
||||
private UserSetting $userSettingModel
|
||||
) {}
|
||||
|
||||
public function getUserSaves(User $user)
|
||||
{
|
||||
return $this->saveFileModel
|
||||
->where('user_id', $user->id)
|
||||
->with('game')
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getUserSettings(User $user)
|
||||
{
|
||||
return $this->userSettingModel
|
||||
->where('user_id', $user->id)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getSetting(User $user, string $key, mixed $default = null): mixed
|
||||
{
|
||||
$setting = $this->userSettingModel
|
||||
->where('user_id', $user->id)
|
||||
->where('setting_key', $key)
|
||||
->first();
|
||||
|
||||
return $setting?->setting_value ?? $default;
|
||||
}
|
||||
|
||||
public function setSetting(User $user, string $key, mixed $value): void
|
||||
{
|
||||
$this->userSettingModel->updateOrCreate(
|
||||
['user_id' => $user->id, 'setting_key' => $key],
|
||||
['setting_value' => $value]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user