Skip to content

Commit c8ce9d2

Browse files
committed
feat: create a route for display cards in decks
1 parent 389f5d3 commit c8ce9d2

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Http\Controllers;
6+
7+
use App\Domain\Dto\FeCard;
8+
use App\Domain\Dto\FeDeck;
9+
use Illuminate\Http\Request;
10+
use Inertia\Inertia;
11+
use Inertia\Response;
12+
13+
class DeckCardsController extends Controller
14+
{
15+
public function show(Request $req, int $id): Response
16+
{
17+
$deck = $req->user()->decks()->find($id);
18+
19+
$cards = $deck->cards()->get();
20+
21+
return Inertia::render('DeckCards/Show', [
22+
'cards' => fn () => FeCard::collect($cards),
23+
'deck' => fn () => FeDeck::from($deck),
24+
]);
25+
}
26+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Authenticated from '@/Layouts/AuthenticatedLayout';
2+
3+
export default function Show({
4+
deck,
5+
cards,
6+
}: {
7+
deck: App.Domain.Dto.FeDeck;
8+
cards: Array<App.Domain.Dto.FeCard>;
9+
}) {
10+
return (
11+
<Authenticated>
12+
<pre>{JSON.stringify(deck, null, 2)}</pre>
13+
<pre>{JSON.stringify(cards, null, 2)}</pre>
14+
</Authenticated>
15+
);
16+
}

resources/js/Pages/Decks/DeckList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export default function DeckList({
2424
key={deck.id}
2525
>
2626
<div className="w-full p-2 bg-white/10 backdrop-blur-[3px] text-md font-semibold rounded-t-md">
27-
{deck.name}
27+
<Link href={route('deck.cards', { id: deck.id })}>
28+
{deck.name}
29+
</Link>
2830
</div>
2931
<div className="w-full p-2 bg-white/10 backdrop-blur-[3px] text-sm rounded-b-md">
3032
<Link

routes/web.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use App\Http\Controllers\CardController;
44
use App\Http\Controllers\DashboardController;
5+
use App\Http\Controllers\DeckCardsController;
56
use App\Http\Controllers\DeckController;
67
use App\Http\Controllers\ImportCardsController;
78
use App\Http\Controllers\ProfileController;
@@ -42,6 +43,10 @@
4243
Route::patch('/decks/{id}', [DeckController::class, 'update'])
4344
->whereNumber('id')
4445
->name('deck.update');
46+
47+
Route::get('/decks/{id}/cards', [DeckCardsController::class, 'show'])
48+
->whereNumber('id')
49+
->name('deck.cards');
4550
});
4651

4752
require __DIR__.'/auth.php';

0 commit comments

Comments
 (0)