forge
Explore
Log in

Don't you dare go Hollow

Align OpenAPI + README with attempts/rejoin

Browse files at this commit

7341f2f7fe0522b77a9b431e8afe087a84830785Ahmet Kaan GümüşParent: c010b64
  • docs
    • align OpenAPI + README with attempts/rejoin
Show full message
📝 docs(exams): align OpenAPI + README with attempts/rejoin

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.mdmodified+14 -5
@@ -7,11 +7,14 @@ Session-cookie auth with four hierarchical roles (`student < teacher < manager
77 then mark users present / absent / late / excused. Marks are course-shaped
88 (Google Classroom style): a teacher creates a course, enrolls students, adds
99 weighted exams inside it, and grades; students read a per-course weighted
10-average and an overall average from their mark report. Exams can be scheduled
11-**sync** (one fixed window) or **async** (start anytime inside the window, with
12-a personal time budget); students *sit* them via attempts, and teachers watch
13-attendance, per-student remaining time, submissions, and marks land live on a
14-monitor endpoint (snapshot or SSE stream). Courses also carry **lesson
10+average and an overall average from their mark report. Exams run **sync** (one
11+fixed window), **async** (start anytime inside the window, with a personal
12+time budget), or **open** (sit anytime, optionally timed per attempt);
13+students *sit* them via attempts — retakes metered by a per-exam limit
14+(`0` = unlimited), leaving the exam room governed by a teacher-controlled
15+rejoin door — and teachers watch attendance, per-student remaining time,
16+sittings, walk-outs, submissions, and marks land live on a monitor endpoint
17+(snapshot or SSE stream). Courses also carry **lesson
1518 sessions** with teacher-taken roll call (students never self-mark a lesson),
1619 staff clock in/out on a server-stamped **work log**, and every user has an
1720 **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.
477480 > keep data, backfill manually with the SurrealDB CLI (server stopped), e.g.
478481 > `UPDATE exam SET course = course:<id>, weight = 1 WHERE course = NONE;`
479482 > after creating a course to attach them to.
483+>
484+> **Upgrading to the attempts/rejoin build needs nothing manual**: the boot
485+> migration backfills `max_attempts = 1`, `allow_rejoin = true`, and attempt
486+> `seq = 1` on existing rows, and swaps the single-attempt unique index for
487+> the per-sitting one. Pre-upgrade attempts keep their record ids and count
488+> as sitting #1.
480489
481490 ## Taking an exam: questions, answers & the exam room
482491
src/lib.rsmodified+2 -2
@@ -32,7 +32,7 @@ use crate::state::AppState;
3232 info(
3333 title = "Hezarfen Backend API",
3434 version = env!("CARGO_PKG_VERSION"),
35- 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.",
35+ 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.",
3636 ),
3737 modifiers(&SecurityAddon),
3838 tags(
@@ -45,7 +45,7 @@ use crate::state::AppState;
4545 (name = "sessions", description = "Lesson sessions and their roll call (session teacher or course manager marks enrolled students; manager+ marks the teacher)"),
4646 (name = "work", description = "Staff work log: check-in/check-out stamped by the server clock, manager corrections"),
4747 (name = "attendance", description = "Attendance summary reports: event tallies + per-course lesson roll call with rates"),
48- (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"),
48+ (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"),
4949 (name = "marks", description = "Weighted mark reports per course and overall, labeled by the school's grade bands when configured"),
5050 (name = "settings", description = "School policy, one singleton: exam kinds, attendance statuses, grade-display bands. Read: any authenticated user; edit: manager+"),
5151 (name = "terms", description = "Academic terms (semester/trimester/quarter — whatever the school runs); courses may link to one. Read: any authenticated user; edit: manager+"),
src/web/courses.rsmodified+6 -1
@@ -488,6 +488,11 @@ async fn unenroll(
488488
489489 /// Create an exam inside a course. Requires teacher+ and course management
490490 /// rights; the exam's marks count `weight` times into the course average.
491+/// Omit `mode` for an offline-graded draft nobody can sit; `sync`/`async`
492+/// take a window (async also `duration_ms`), `open` is sittable anytime with
493+/// an optional per-attempt `duration_ms`. `max_attempts` (default 1, `0` =
494+/// unlimited) meters retakes and `allow_rejoin` (default `true`) is the
495+/// exam-room door — both stay editable while the exam runs.
491496 #[utoipa::path(
492497 post,
493498 path = "/{id}/exams",
@@ -497,7 +502,7 @@ async fn unenroll(
497502 request_body = CreateExamInCourse,
498503 responses(
499504 (status = 201, description = "Exam created", body = ExamResponse),
500- (status = 400, description = "Invalid fields, kind, weight, or schedule (malformed window, or times in the past)", body = ErrorResponse),
505+ (status = 400, description = "Invalid fields, kind, weight, attempt limit, or schedule (malformed window, or times in the past)", body = ErrorResponse),
501506 (status = 401, description = "Not authenticated", body = ErrorResponse),
502507 (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse),
503508 (status = 404, description = "Course not found", body = ErrorResponse),
src/web/exams.rsmodified+11 -8
@@ -232,7 +232,7 @@ async fn get_exam(
232232 request_body = UpdateExam,
233233 responses(
234234 (status = 200, description = "Updated exam", body = ExamResponse),
235- (status = 400, description = "Invalid fields, kind, weight, or schedule (malformed window, or newly set times in the past)", body = ErrorResponse),
235+ (status = 400, description = "Invalid fields, kind, weight, attempt limit, or schedule (malformed window, or newly set times in the past)", body = ErrorResponse),
236236 (status = 401, description = "Not authenticated", body = ErrorResponse),
237237 (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse),
238238 (status = 404, description = "Not found", body = ErrorResponse),
@@ -1056,8 +1056,9 @@ async fn live_snapshot(exam: &Exam, db: &Database) -> Result<ExamLiveResponse, A
10561056 })
10571057 }
10581058
1059-/// A one-shot live snapshot of the exam: who's in, who's still writing, time
1060-/// each student has left, and marks as they land. Requires teacher+ and
1059+/// A one-shot live snapshot of the exam: who's in, who's still writing (and
1060+/// on which sitting), who walked out of the room (`left_at`), time each
1061+/// student has left, and marks as they land. Requires teacher+ and
10611062 /// management rights over the exam's course. For a self-updating feed of the
10621063 /// same shape, see `GET /exams/{id}/live/stream`.
10631064 #[utoipa::path(
@@ -1556,7 +1557,8 @@ pub(crate) async fn save_answer_checked(
15561557 }
15571558
15581559 /// The exam's questions as the sitting student sees them: `correct` stripped,
1559-/// their own saved answers embedded. Requires an attempt — start one with
1560+/// their own saved answers embedded — the latest sitting's, since a retake
1561+/// starts from a blank sheet. Requires an attempt — start one with
15601562 /// `POST /exams/{id}/attempt` first (404 until then). Readable in every
15611563 /// attempt state, so a submitted student can still review what they wrote.
15621564 #[utoipa::path(
@@ -1657,10 +1659,11 @@ async fn save_answer(
16571659 }))
16581660 }
16591661
1660-/// One student's answer sheet with correctness flags. Every row carries the
1661-/// saved answer plus `is_correct` (`null` for text questions — those are the
1662-/// grader's call), and the machine's `auto_score` over the choice questions is
1663-/// attached as a *suggestion*: the final mark stays human, via
1662+/// One student's answer sheet with correctness flags — always the *latest*
1663+/// sitting's answers (a retake starts from a blank sheet). Every row carries
1664+/// the saved answer plus `is_correct` (`null` for text questions — those are
1665+/// the grader's call), and the machine's `auto_score` over the choice
1666+/// questions is attached as a *suggestion*: the final mark stays human, via
16641667 /// `POST /exams/{id}/results`. Requires teacher+ and management rights over
16651668 /// the exam's course.
16661669 #[utoipa::path(