feat: dashboard + tutorials modules - stats tiles, tutorial list, reader, completion
Dieser Commit ist enthalten in:
Ursprung
2c34aea901
Commit
03778e4bed
4 geänderte Dateien mit 197 neuen und 0 gelöschten Zeilen
47
edu/api/tutorials.php
Normale Datei
47
edu/api/tutorials.php
Normale Datei
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
$user_id = require_auth();
|
||||
|
||||
// GET /api/tutorials
|
||||
if (get_method() === 'GET' && empty($segments[1])) {
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT t.id, t.slug, t.title, t.description, t.duration_min, t.sort_order,
|
||||
COALESCE(tp.completed, false) AS completed, tp.completed_at
|
||||
FROM tutorials t
|
||||
LEFT JOIN tutorial_progress tp ON tp.tutorial_id = t.id AND tp.user_id = :uid
|
||||
ORDER BY t.sort_order
|
||||
");
|
||||
$stmt->execute([':uid' => $user_id]);
|
||||
json_ok(['tutorials' => $stmt->fetchAll()]);
|
||||
}
|
||||
|
||||
// GET /api/tutorials/{slug}
|
||||
if (get_method() === 'GET' && !empty($segments[1]) && ($segments[2] ?? '') !== 'complete') {
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT t.*, COALESCE(tp.completed, false) AS completed
|
||||
FROM tutorials t
|
||||
LEFT JOIN tutorial_progress tp ON tp.tutorial_id = t.id AND tp.user_id = :uid
|
||||
WHERE t.slug = :slug
|
||||
");
|
||||
$stmt->execute([':slug' => $segments[1], ':uid' => $user_id]);
|
||||
$tutorial = $stmt->fetch();
|
||||
if (!$tutorial) json_error('Tutorial nicht gefunden', 404);
|
||||
json_ok(['tutorial' => $tutorial]);
|
||||
}
|
||||
|
||||
// POST /api/tutorials/{slug}/complete
|
||||
if (get_method() === 'POST' && !empty($segments[1]) && ($segments[2] ?? '') === 'complete') {
|
||||
$stmt = $pdo->prepare("SELECT id FROM tutorials WHERE slug = :slug");
|
||||
$stmt->execute([':slug' => $segments[1]]);
|
||||
$tutorial = $stmt->fetch();
|
||||
if (!$tutorial) json_error('Tutorial nicht gefunden', 404);
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO tutorial_progress (user_id, tutorial_id, completed, completed_at)
|
||||
VALUES (:uid, :tid, true, NOW())
|
||||
ON CONFLICT (user_id, tutorial_id) DO UPDATE SET completed = true, completed_at = NOW()
|
||||
");
|
||||
$stmt->execute([':uid' => $user_id, ':tid' => $tutorial['id']]);
|
||||
json_ok(['ok' => true]);
|
||||
}
|
||||
|
||||
json_error('Unbekannter Tutorials-Endpunkt', 404);
|
||||
Laden …
Tabelle hinzufügen
Einen Link hinzufügen
In neuem Issue referenzieren