28 Zeilen
1,1 KiB
PHP
28 Zeilen
1,1 KiB
PHP
<?php
|
|
require_auth();
|
|
|
|
// GET /api/cheatsheets
|
|
if (get_method() === 'GET' && empty($segments[1])) {
|
|
$stmt = $pdo->query("SELECT id, slug, title, category FROM cheatsheets ORDER BY category, title");
|
|
json_ok(['cheatsheets' => $stmt->fetchAll()]);
|
|
}
|
|
|
|
// GET /api/cheatsheets/search?q=...
|
|
if (get_method() === 'GET' && ($segments[1] ?? '') === 'search') {
|
|
$q = get_param('q', '');
|
|
if (mb_strlen($q) < 2) json_error('Mindestens 2 Zeichen');
|
|
$stmt = $pdo->prepare("SELECT id, slug, title, category FROM cheatsheets WHERE content_md ILIKE :q OR title ILIKE :q ORDER BY title");
|
|
$stmt->execute([':q' => '%' . $q . '%']);
|
|
json_ok(['cheatsheets' => $stmt->fetchAll(), 'query' => $q]);
|
|
}
|
|
|
|
// GET /api/cheatsheets/{slug}
|
|
if (get_method() === 'GET' && !empty($segments[1])) {
|
|
$stmt = $pdo->prepare("SELECT * FROM cheatsheets WHERE slug = :slug");
|
|
$stmt->execute([':slug' => $segments[1]]);
|
|
$sheet = $stmt->fetch();
|
|
if (!$sheet) json_error('Cheat Sheet nicht gefunden', 404);
|
|
json_ok(['cheatsheet' => $sheet]);
|
|
}
|
|
|
|
json_error('Unbekannter Cheatsheet-Endpunkt', 404);
|