2026-03-25 09:39:51 +07:00
|
|
|
"""
|
2026-08-08 11:57:08 +07:00
|
|
|
Token & progress facade — kontrak publik yang dipakai routes.
|
|
|
|
|
|
feat(teacher): manajemen akun guru canonical + first-run otomatis; cabut backend CSV (PG only)
- feat: ./elemes.sh teacher — upsert satu akun guru canonical (prompt nama default TEACHER_NAME, token tersembunyi via stdin, rotasi token saat guru sudah ada, idempotent); TEACHER_NAME/TEACHER_TOKEN di .env
- feat: first-run otomatis — db_init jalankan alembic upgrade head + bootstrap guru bila TEACHER_TOKEN terisi (run/runbuild/runclearbuild)
- refactor: backend CSV dicabut penuh — hapus mount tokens_siswa.csv, TOKENS_FILE, STORAGE_BACKEND=csv, csv_backend.py, csv_importer.py, generate_tokens.py, script migrate/verify/export CSV, command generatetoken/dbimport/dbverify/dbexport/synclessons; storage fail-loud postgresql-only
- fix: dbrestore gagal diam-diam saat restore ke DB berisi data (dump tanpa --clean) — dbbackup kini --clean --if-exists + dbrestore reset schema public; roundtrip terverifikasi
- test: suite kontrak PG-native + route auth/progress integrasi PG; 183 passed container, 96 passed host, frontend 91 passed
- docs: README, documentation.md, docs/01/02/11, load-test/README disinkronkan ke realita PostgreSQL-only; proposal.md dipertahankan (historis)
- chore: load-test token sintetis di-seed ke PG (content_parser), config.py bersih TOKENS_FILE, .dockerignore/.gitignore dibersihkan
2026-08-09 11:21:08 +07:00
|
|
|
Mendelegasikan ke satu-satunya storage backend aktif: PostgreSQL
|
|
|
|
|
(services.storage.postgres_backend). Backend CSV sudah dicabut setelah
|
|
|
|
|
cutover penuh — routes TIDAK boleh tahu detail backend, cukup import sini.
|
2026-03-25 09:39:51 +07:00
|
|
|
"""
|
|
|
|
|
|
feat(teacher): manajemen akun guru canonical + first-run otomatis; cabut backend CSV (PG only)
- feat: ./elemes.sh teacher — upsert satu akun guru canonical (prompt nama default TEACHER_NAME, token tersembunyi via stdin, rotasi token saat guru sudah ada, idempotent); TEACHER_NAME/TEACHER_TOKEN di .env
- feat: first-run otomatis — db_init jalankan alembic upgrade head + bootstrap guru bila TEACHER_TOKEN terisi (run/runbuild/runclearbuild)
- refactor: backend CSV dicabut penuh — hapus mount tokens_siswa.csv, TOKENS_FILE, STORAGE_BACKEND=csv, csv_backend.py, csv_importer.py, generate_tokens.py, script migrate/verify/export CSV, command generatetoken/dbimport/dbverify/dbexport/synclessons; storage fail-loud postgresql-only
- fix: dbrestore gagal diam-diam saat restore ke DB berisi data (dump tanpa --clean) — dbbackup kini --clean --if-exists + dbrestore reset schema public; roundtrip terverifikasi
- test: suite kontrak PG-native + route auth/progress integrasi PG; 183 passed container, 96 passed host, frontend 91 passed
- docs: README, documentation.md, docs/01/02/11, load-test/README disinkronkan ke realita PostgreSQL-only; proposal.md dipertahankan (historis)
- chore: load-test token sintetis di-seed ke PG (content_parser), config.py bersih TOKENS_FILE, .dockerignore/.gitignore dibersihkan
2026-08-09 11:21:08 +07:00
|
|
|
from services.storage import get_backend_module
|
2026-03-27 16:41:57 +07:00
|
|
|
|
|
|
|
|
|
2026-08-08 11:57:08 +07:00
|
|
|
def _backend():
|
|
|
|
|
return get_backend_module()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def validate_token(token):
|
|
|
|
|
"""Valid token → {'student_name', 'is_teacher'} | None."""
|
|
|
|
|
return _backend().validate_token(token)
|
2026-03-27 16:41:57 +07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_teacher_token(token):
|
2026-08-08 11:57:08 +07:00
|
|
|
return _backend().is_teacher_token(token)
|
2026-03-27 16:41:57 +07:00
|
|
|
|
|
|
|
|
|
2026-03-25 09:39:51 +07:00
|
|
|
def get_student_progress(token):
|
2026-08-08 11:57:08 +07:00
|
|
|
"""Dict {lesson_slug: status} | None."""
|
|
|
|
|
return _backend().get_student_progress(token)
|
2026-03-25 09:39:51 +07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_student_progress(token, lesson_name, status="completed"):
|
2026-08-08 11:57:08 +07:00
|
|
|
return _backend().update_student_progress(token, lesson_name, status)
|
2026-03-25 09:39:51 +07:00
|
|
|
|
|
|
|
|
|
2026-08-08 11:57:08 +07:00
|
|
|
def reset_student_progress(student_id, lesson_name):
|
|
|
|
|
"""Reset progress siswa by student_id (id anonim dari report — bukan token)."""
|
|
|
|
|
return _backend().reset_progress(student_id, lesson_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_all_students_progress(all_lessons_func):
|
|
|
|
|
"""(students, ordered_lessons) — tanpa token mentah di student dict."""
|
|
|
|
|
return _backend().get_all_students_progress(all_lessons_func)
|
2026-03-25 09:39:51 +07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def calculate_student_completion(student_data, all_lessons):
|
2026-08-08 11:57:08 +07:00
|
|
|
"""Helper murni bersama (parity kedua backend)."""
|
|
|
|
|
from services.storage.completion import calculate_student_completion as _calc
|
2026-03-25 09:39:51 +07:00
|
|
|
|
2026-08-08 11:57:08 +07:00
|
|
|
return _calc(student_data, all_lessons)
|