From 7341f2f7fe0522b77a9b431e8afe087a84830785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 13 Jul 2026 16:27:42 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20docs(exams):=20align=20OpenAPI?= =?UTF-8?q?=20+=20README=20with=20attempts/rejoin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The generated spec and README lagged the feature: the exams tag and top-level description still said sync/async only, the intro paragraph predated open mode, and several operation docs didn't say the sheet and sitting views are always the latest attempt's. - exams tag + API description: open mode, retake limits, rejoin door, draft-409 semantics, WS left_at behavior - create-exam summary walks the mode matrix and both policy knobs; 400 descriptions mention the attempt limit - answer sheet / sitting view / live snapshot docs note latest-sitting semantics and left_at - README: intro paragraph, and a note that the attempts/rejoin schema upgrade is fully automatic at boot (unlike the pre-course one) --- README.md | 19 ++++++++++++++----- src/lib.rs | 4 ++-- src/web/courses.rs | 7 ++++++- src/web/exams.rs | 19 +++++++++++-------- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 25c3977..231543c 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,14 @@ Session-cookie auth with four hierarchical roles (`student < teacher < manager then mark users present / absent / late / excused. Marks are course-shaped (Google Classroom style): a teacher creates a course, enrolls students, adds weighted exams inside it, and grades; students read a per-course weighted -average and an overall average from their mark report. Exams can be scheduled -**sync** (one fixed window) or **async** (start anytime inside the window, with -a personal time budget); students *sit* them via attempts, and teachers watch -attendance, per-student remaining time, submissions, and marks land live on a -monitor endpoint (snapshot or SSE stream). Courses also carry **lesson +average and an overall average from their mark report. Exams run **sync** (one +fixed window), **async** (start anytime inside the window, with a personal +time budget), or **open** (sit anytime, optionally timed per attempt); +students *sit* them via attempts — retakes metered by a per-exam limit +(`0` = unlimited), leaving the exam room governed by a teacher-controlled +rejoin door — and teachers watch attendance, per-student remaining time, +sittings, walk-outs, submissions, and marks land live on a monitor endpoint +(snapshot or SSE stream). Courses also carry **lesson sessions** with teacher-taken roll call (students never self-mark a lesson), staff clock in/out on a server-stamped **work log**, and every user has an **attendance report** (event + per-course lesson tallies with rates). @@ -477,6 +480,12 @@ roster but keeps the attempt and mark rows, mirroring the marks report. > keep data, backfill manually with the SurrealDB CLI (server stopped), e.g. > `UPDATE exam SET course = course:, weight = 1 WHERE course = NONE;` > after creating a course to attach them to. +> +> **Upgrading to the attempts/rejoin build needs nothing manual**: the boot +> migration backfills `max_attempts = 1`, `allow_rejoin = true`, and attempt +> `seq = 1` on existing rows, and swaps the single-attempt unique index for +> the per-sitting one. Pre-upgrade attempts keep their record ids and count +> as sitting #1. ## Taking an exam: questions, answers & the exam room diff --git a/src/lib.rs b/src/lib.rs index 0aa9a82..96ac5b7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,7 @@ use crate::state::AppState; info( title = "Hezarfen Backend API", version = env!("CARGO_PKG_VERSION"), - description = "Notes, events, attendance, courses, and weighted exam marks behind cookie-session auth. Courses carry lesson sessions with teacher-taken roll call; staff clock in/out on a server-stamped work log; attendance reports tally events and per-course roll call with rates. School-varying policy (exam kinds, attendance statuses, grade-display bands) lives in an editable settings singleton, and courses may link to academic terms.", + description = "Notes, events, attendance, courses, and weighted exam marks behind cookie-session auth. Exams run sync (one window), async (window + per-attempt duration), or open (sit anytime), with per-exam attempt limits (retakes) and a teacher-controlled rejoin door on the live exam room. Courses carry lesson sessions with teacher-taken roll call; staff clock in/out on a server-stamped work log; attendance reports tally events and per-course roll call with rates. School-varying policy (exam kinds, attendance statuses, grade-display bands) lives in an editable settings singleton, and courses may link to academic terms.", ), modifiers(&SecurityAddon), tags( @@ -45,7 +45,7 @@ use crate::state::AppState; (name = "sessions", description = "Lesson sessions and their roll call (session teacher or course manager marks enrolled students; manager+ marks the teacher)"), (name = "work", description = "Staff work log: check-in/check-out stamped by the server clock, manager corrections"), (name = "attendance", description = "Attendance summary reports: event tallies + per-course lesson roll call with rates"), - (name = "exams", description = "Exams (per course, weighted): results, sync/async scheduling, attempts, questions/answers, and live monitoring. Not in this spec (WebSocket): the student exam room at `GET /exams/{id}/attempt/ws` — JSON frames, see the README's \"Taking an exam\" section for the protocol"), + (name = "exams", description = "Exams (per course, weighted): results, sync/async/open scheduling, attempts with retakes (`max_attempts`, 0 = unlimited) and a live rejoin door (`allow_rejoin`), questions/answers, and live monitoring. A modeless exam is an offline-graded draft — attempts on it are a 409. Not in this spec (WebSocket): the student exam room at `GET /exams/{id}/attempt/ws` — JSON frames; entering clears the attempt's `left_at`, leaving mid-attempt stamps it. See the README's \"Taking an exam\" section for the protocol"), (name = "marks", description = "Weighted mark reports per course and overall, labeled by the school's grade bands when configured"), (name = "settings", description = "School policy, one singleton: exam kinds, attendance statuses, grade-display bands. Read: any authenticated user; edit: manager+"), (name = "terms", description = "Academic terms (semester/trimester/quarter — whatever the school runs); courses may link to one. Read: any authenticated user; edit: manager+"), diff --git a/src/web/courses.rs b/src/web/courses.rs index a62c0fb..b18041c 100644 --- a/src/web/courses.rs +++ b/src/web/courses.rs @@ -488,6 +488,11 @@ async fn unenroll( /// Create an exam inside a course. Requires teacher+ and course management /// rights; the exam's marks count `weight` times into the course average. +/// Omit `mode` for an offline-graded draft nobody can sit; `sync`/`async` +/// take a window (async also `duration_ms`), `open` is sittable anytime with +/// an optional per-attempt `duration_ms`. `max_attempts` (default 1, `0` = +/// unlimited) meters retakes and `allow_rejoin` (default `true`) is the +/// exam-room door — both stay editable while the exam runs. #[utoipa::path( post, path = "/{id}/exams", @@ -497,7 +502,7 @@ async fn unenroll( request_body = CreateExamInCourse, responses( (status = 201, description = "Exam created", body = ExamResponse), - (status = 400, description = "Invalid fields, kind, weight, or schedule (malformed window, or times in the past)", body = ErrorResponse), + (status = 400, description = "Invalid fields, kind, weight, attempt limit, or schedule (malformed window, or times in the past)", body = ErrorResponse), (status = 401, description = "Not authenticated", body = ErrorResponse), (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), (status = 404, description = "Course not found", body = ErrorResponse), diff --git a/src/web/exams.rs b/src/web/exams.rs index be33838..795c779 100644 --- a/src/web/exams.rs +++ b/src/web/exams.rs @@ -232,7 +232,7 @@ async fn get_exam( request_body = UpdateExam, responses( (status = 200, description = "Updated exam", body = ExamResponse), - (status = 400, description = "Invalid fields, kind, weight, or schedule (malformed window, or newly set times in the past)", body = ErrorResponse), + (status = 400, description = "Invalid fields, kind, weight, attempt limit, or schedule (malformed window, or newly set times in the past)", body = ErrorResponse), (status = 401, description = "Not authenticated", body = ErrorResponse), (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), (status = 404, description = "Not found", body = ErrorResponse), @@ -1056,8 +1056,9 @@ async fn live_snapshot(exam: &Exam, db: &Database) -> Result