Nyavokevin 9e5cc5ab1a
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
add dark theme
2025-09-18 20:34:07 +03:00

77 lines
1.9 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Illuminate\Support\Facades\Log;
use App\Repositories\CardRepositoryInterface;
class CardController extends Controller
{
protected $cardRepository;
public function __construct(CardRepositoryInterface $cardRepository)
{
$this->cardRepository = $cardRepository;
}
public function index()
{
try {
$cards = app('App\Repositories\CardRepositoryInterface')->all();
return Inertia::render('cards/shuffle', [
'cards' => $cards,
]);
} catch (\Exception $e) {
// Log the error for debugging
Log::error('Error fetching cards: '.$e->getMessage(), [
'trace' => $e->getTraceAsString()
]);
// Optionally, you can return an Inertia error page or empty array
return Inertia::render('Cards/Index', [
'cards' => [],
'error' => 'Impossible de récupérer les cartes pour le moment.'
]);
}
}
public function drawCard(Request $request)
{
// Validate the request if needed
$request->validate([
'count' => 'sometimes|integer'
]);
$cardDraw = $this->cardRepository->draw($request->count);
// Return the response (Inertia will automatically handle this)
return response()->json([
'success' => true,
'card' => $cardDraw,
'message' => 'Card drawn successfully'
]);
}
public function cartResult()
{
return Inertia::render('cards/resultat', [
]);
}
public function freeCartResult($id)
{
$card = $this->cardRepository->find($id);
return response()->json([
'success' => true,
'cards' => $card,
]);
}
}