build: initialize RetroHub with Laravel, Inertia, Vue, and Horizon
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Games\Repositories;
|
||||
|
||||
use App\Features\Games\Models\Game;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class GameRepository
|
||||
{
|
||||
public function __construct(
|
||||
private Game $model
|
||||
) {}
|
||||
|
||||
public function getByConsole(int $consoleId, int $perPage = 24): LengthAwarePaginator
|
||||
{
|
||||
return $this->model
|
||||
->where('console_id', $consoleId)
|
||||
->with('romFiles')
|
||||
->orderBy('title')
|
||||
->paginate($perPage);
|
||||
}
|
||||
|
||||
public function getBySlug(string $slug): ?Game
|
||||
{
|
||||
return $this->model
|
||||
->with(['console', 'romFiles'])
|
||||
->where('slug', $slug)
|
||||
->first();
|
||||
}
|
||||
|
||||
public function getRecent(int $limit = 10): Collection
|
||||
{
|
||||
return $this->model
|
||||
->with('console')
|
||||
->latest()
|
||||
->take($limit)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function search(string $query): Collection
|
||||
{
|
||||
return $this->model
|
||||
->with('console')
|
||||
->where('title', 'like', "%{$query}%")
|
||||
->orderBy('title')
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
return $this->model
|
||||
->with('console')
|
||||
->orderBy('title')
|
||||
->paginate(24);
|
||||
}
|
||||
|
||||
public function create(array $data): Game
|
||||
{
|
||||
return $this->model->create($data);
|
||||
}
|
||||
|
||||
public function firstOrCreate(array $conditions, array $values = []): Game
|
||||
{
|
||||
return $this->model->firstOrCreate($conditions, $values);
|
||||
}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return $this->model->count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Games\Repositories;
|
||||
|
||||
use App\Features\Games\Models\RomFile;
|
||||
|
||||
class RomFileRepository
|
||||
{
|
||||
public function __construct(
|
||||
private RomFile $model
|
||||
) {}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return $this->model->count();
|
||||
}
|
||||
|
||||
public function findByHash(string $hash): ?RomFile
|
||||
{
|
||||
return $this->model->where('file_hash', $hash)->first();
|
||||
}
|
||||
|
||||
public function create(array $data): RomFile
|
||||
{
|
||||
return $this->model->create($data);
|
||||
}
|
||||
|
||||
public function getByGame(int $gameId)
|
||||
{
|
||||
return $this->model->where('game_id', $gameId)->get();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user