Files
Adminator 1e51ef7def Nachtrag: alle bisher untracked Ordner + hängende Änderungen mit-committen
- Konzept/, didaktik_geografie/, didaktik_simulation/, v2-modules/, v2-platform/
- 12 code-workspace-Files
- STATUS-*.md
- viele M/D/R-Änderungen an bereits getrackten Files
- .gitignore verstärkt: **/.humaninput/, **/secret_keys.txt

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-07-08 02:27:02 +02:00

60 lines
1.8 KiB
PHP

<?php
/**
* GET /api/module/state?slug=<slug> → Resume-State holen
* PUT /api/module/state → Resume-State speichern
*/
declare(strict_types=1);
require_once __DIR__ . '/../../bootstrap.php';
$method = v2_validate_method_in(['GET', 'PUT']);
$auth = v2_auth_require('student');
$studentId = (int) ($auth['sub'] ?? 0);
if ($method === 'GET') {
$slug = $_GET['slug'] ?? '';
if (!$slug) {
v2_response_error(400, 'missing_slug', 'Parameter "slug" fehlt.');
}
$row = v2_db_one("
SELECT state_json, summary, updated_at
FROM module_state_v2
WHERE student_id = :sid AND module_slug = :slug
", [':sid' => $studentId, ':slug' => $slug]);
if (!$row) {
v2_response_ok(['exists' => false]);
}
v2_response_ok([
'exists' => true,
'lastUpdated' => $row['updated_at'],
'state' => json_decode($row['state_json'], true),
'summary' => $row['summary'] ?? '',
]);
}
// PUT — State speichern
$body = v2_request_body_json_required();
v2_validate_required($body, ['moduleSlug', 'state']);
$slug = (string) $body['moduleSlug'];
$stateJson = json_encode($body['state'], JSON_UNESCAPED_UNICODE);
$summary = (string) ($body['summary'] ?? '');
if (strlen($stateJson) > 1024 * 1024) { // 1 MB Limit
v2_response_error(413, 'state_too_large', 'State darf max 1 MB sein.');
}
v2_db_exec("
INSERT INTO module_state_v2 (student_id, module_slug, state_json, summary)
VALUES (:sid, :slug, :st, :sum)
ON DUPLICATE KEY UPDATE
state_json = VALUES(state_json),
summary = VALUES(summary),
updated_at = CURRENT_TIMESTAMP
", [':sid' => $studentId, ':slug' => $slug, ':st' => $stateJson, ':sum' => $summary]);
v2_response_ok(['ok' => true, 'savedAt' => date('c')]);