30 Zeilen
1 KiB
PHP
30 Zeilen
1 KiB
PHP
<?php
|
|
$user_id = require_auth();
|
|
|
|
// GET /api/decks
|
|
if (get_method() === 'GET' && empty($segments[1])) {
|
|
$stmt = $pdo->prepare("
|
|
SELECT d.id, d.slug, d.name, d.description, d.card_count,
|
|
COUNT(cp.id) AS reviewed,
|
|
COUNT(cp.id) FILTER (WHERE cp.last_rating IN ('easy','medium')) AS correct,
|
|
COUNT(cp.id) FILTER (WHERE cp.next_review <= CURRENT_DATE) AS due
|
|
FROM decks d
|
|
LEFT JOIN cards c ON c.deck_id = d.id
|
|
LEFT JOIN card_progress cp ON cp.card_id = c.id AND cp.user_id = :uid
|
|
GROUP BY d.id
|
|
ORDER BY d.sort_order, d.name
|
|
");
|
|
$stmt->execute([':uid' => $user_id]);
|
|
json_ok(['decks' => $stmt->fetchAll()]);
|
|
}
|
|
|
|
// GET /api/decks/{slug}
|
|
if (get_method() === 'GET' && !empty($segments[1])) {
|
|
$stmt = $pdo->prepare("SELECT * FROM decks WHERE slug = :s");
|
|
$stmt->execute([':s' => $segments[1]]);
|
|
$deck = $stmt->fetch();
|
|
if (!$deck) json_error('Deck nicht gefunden', 404);
|
|
json_ok(['deck' => $deck]);
|
|
}
|
|
|
|
json_error('Methode nicht erlaubt', 405);
|