From 0c7403b123d917a21b813ed44d77caa242dcc8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 1 Aug 2026 23:20:17 +0300 Subject: [PATCH] =?UTF-8?q?docs:=20=F0=9F=93=90=20teach=20all=20three=20su?= =?UTF-8?q?rfaces=20the=20class=20layer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 115 ++++++++++++++++++++++++++++++++++++++++++++++++----- src/lib.rs | 8 ++-- 2 files changed, 108 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ff4f062..d1ab8c6 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ closes the moment the event starts (or, for an event with only an end time — a pure signup deadline — the moment that end passes). Every event stays visible to everyone — the audience is a roster, not a wall. Marks are course-shaped (Google Classroom style): a teacher creates a course — kind **`course`** (a -regular class), **`study`** (a supervised study session — *etüt*), or +regular taught course), **`study`** (a supervised study session — *etüt*), or **`club`** (a student club — *kulüp*; same behavior, different label), optionally capped by a `capacity` that refuses new enrolls once the roster is full — lays out its **subjects** (curriculum topics — @@ -33,7 +33,14 @@ all student-only, staff never take part. A course is run by whoever created it plus any teachers a **manager assigns** to it (`POST /courses/{id}/teachers`): an assigned teacher manages everything inside the course — exams, sessions, subjects, roster, grading — but can't delete it or change who else teaches it, -and a demotion below `teacher` sweeps their assignments away. Students read a per-course weighted average and +and a demotion below `teacher` sweeps their assignments away. Students are +grouped into **classes** (*şube* — 9-A, 10-B) when a school teaches that way: +a class is bulk enrollment and not a second kind of membership — attaching a +course to it enrolls the whole roster, adding a member enrolls them into every +course already attached, and what lands are ordinary enrollment rows tagged +with the class that pumped them (untagged = placed by hand, and hand-placed +rows are never adopted and never swept). A course without room for everyone +refuses the whole operation, naming it (see "Classes (şube)"). Students read a per-course weighted average and an overall average from their mark report — each exam weighted by its **kind** (midterms can count double, orals once: weights are set per kind in settings, not per exam). Exams run **sync** (one @@ -55,7 +62,7 @@ whoever saved them. Teachers watch attendance, per-student remaining time, sittings, walk-outs, no-shows (`absent` once the window closes), submissions, and marks land live on a monitor endpoint (snapshot or SSE stream). Courses also hand out -**homework**: assigned to the whole class or a named subset (the unnamed never +**homework**: assigned to the whole course or a named subset (the unnamed never even see it), tagged with a course subject, due by a required future `due_at` — students hand in text and/or **files of any type** (same size cap, 10 per submission, served back only as forced downloads), editable until the teacher @@ -514,6 +521,8 @@ course enrollments. | Delete a course | teacher | Only the **creator**, or a `manager`+ — an assigned teacher runs the course but doesn't own it | | Manage inside a course: edit it, enroll/unenroll **students**, add/edit/delete its exams and **subjects**, grade, remove results | teacher | The **course creator**, a teacher **assigned** to it, or a `manager`+ for any course; only students can be enrolled; a subject still referenced by exam questions or homework won't delete (`409`) | | View a course's roster, an exam's result list / statistics | teacher | Course-management rights | +| Create / edit / delete a **class** (şube); add or remove its members | manager | Reading classes, their rosters and their course lists is teacher+; a member must be a `student` | +| Attach / detach a course on a class | teacher | Course-management rights on **that course** — attaching enrolls the whole class into it, so it takes exactly the right enrolling one student takes | | Read another user's mark report | teacher | Narrowed to the caller's managed courses; `manager`+ sees all; a `parent` sees a linked student's in full | | Grade students | teacher | Target must be an **enrolled student**; grading never targets oneself | | Assign / edit / delete homework; grade it; read its roster | teacher | Course-management rights; an `assigned` subset (≤ 200 enrolled students) can't be narrowed over existing work (`409`); a grade (`done`/`incomplete`/`missing` + optional mark) freezes the submission until removed | @@ -561,7 +570,7 @@ against the SurrealDB server — e.g. `Auth` is the minimum role; `no` means no session required, `student` means any logged-in user. -A course is a regular class (kind `course`, the default), an *etüt* (kind +A course is a regular taught course (kind `course`, the default), an *etüt* (kind `study` — a supervised study session), or a *kulüp* (kind `club` — a student club). The three kinds behave identically everywhere — enrollment, exams, sessions, marks — the kind is a label the UI renders differently, settable at @@ -701,10 +710,10 @@ window filtering, before paging; negative values are a `400` naming the field. | DELETE | `/classes/{id}` | manager | Delete a class — `409` while it still holds students or courses | | POST | `/classes/{id}/members` | manager | `{user_id}` — add a **student**; enrolls them into every attached course (`409` if one is full, naming it, or if already a member) | | GET | `/classes/{id}/members` | teacher | List the class roster · paged | -| DELETE | `/classes/{id}/members/{user}` | manager | Remove a student and sweep the enrollments the class pumped for them | +| DELETE | `/classes/{id}/members/{user}` | manager | Remove a member — sweeps only the enrollments **this class** pumped for them (one another class still claims is re-tagged to it; hand-placed rows stay) | | POST | `/classes/{id}/courses` | teacher | `{course_id}` — attach a course (that **course's** manager); enrolls the whole roster (`409` if it cannot hold them all, or if already attached) | | GET | `/classes/{id}/courses` | teacher | List the class's attached courses · paged | -| DELETE | `/classes/{id}/courses/{course}` | teacher | Detach a course (that course's manager) and sweep the enrollments the class pumped | +| DELETE | `/classes/{id}/courses/{course}` | teacher | Detach a course (that course's manager) — the same sweep along the course axis | | POST | `/courses/{id}/sessions` | teacher | `{topic?, teacher_id?, starts_at, ends_at?}` — add a lesson (course manager; teacher defaults to the caller) | | GET | `/courses/{id}/sessions` | student | List the course's sessions, most recent first (enrolled, creator, assigned teacher, or manager+) · paged | | POST | `/courses/{id}/subjects` | teacher | `{name, description?}` — add a curriculum subject (course manager) | @@ -825,7 +834,7 @@ window filtering, before paging; negative values are a `400` naming the field. | GET | `/terms` | student | List terms, newest first · paged | | GET | `/terms/{id}` | student | Get one term | | PATCH | `/terms/{id}` | manager | Edit a term (the merged range must stay ordered) | -| DELETE | `/terms/{id}` | manager | Delete a term — `409` while any course still links to it | +| DELETE | `/terms/{id}` | manager | Delete a term — `409` while any course or class still links to it | | POST | `/meals/menus` | manager | `{date, slot, capacity?}` — publish a menu; `date` is `YYYY-MM-DD` text, `slot` must be one of the school's `meal_slots`; `409` when that day+slot is already published | | GET | `/meals/menus` | student | List menus with their dishes, newest day first · `?from=&to=` inclusive `YYYY-MM-DD` range · paged | | GET | `/meals/menus/{id}` | student | One menu with its dishes | @@ -1258,10 +1267,11 @@ The kitchen is data too: a manager publishes a **menu** per calendar day and mea Academic structure is data too. **Terms** (`/terms`) model whatever calendar the school runs — semester, trimester, quarter systems are just rows with a -name and a date range. Courses may link to one via `term_id` (nullable), and -deleting a term is refused with a `409` while any course still links to it — -unlink those courses (`PATCH /courses/{id}` with `"term_id": null`) or delete -them first, so the calendar never disappears under them. Term dates may lie in the past, +name and a date range. Courses *and classes* may link to one via `term_id` (nullable), +and deleting a term is refused with a `409` while any of them still links to +it — unlink them (`PATCH /courses/{id}` or `PATCH /classes/{id}` with +`"term_id": null`) or delete them first, so the calendar never disappears +under them. Term dates may lie in the past, deliberately: a school adopting the app mid-year backfills its calendar — unlike exam/lesson/event times, which reject backdating. @@ -2131,6 +2141,89 @@ for every course the user has roll-call rows in — attendance is a historical record, so unenrolling hides marks from the marks report but never hides an absence. +## Classes (şube) + +A **class** is the group a school actually teaches in — 9-A, 10-B — and here +it is a bulk-enrollment tool rather than a second kind of membership. A class +row carries a name, an optional free-text `grade` label in the school's own +vocabulary (`"9"`, `"Lise 2"`; `""` means no grade, exactly like omitting it) +and an optional `term_id`; nothing else about a course changes because a class +exists. Schools that run electives or a college-style timetable simply never +create one — individual enrollment is untouched, and classes are a +convenience. + +**The pump.** A class holds **members** (students) and **attached courses**, +and owes the product of the two: every member enrolled in every attached +course. So both writes push the same way — attaching a course +(`POST /classes/{id}/courses`) enrolls the whole roster into it, adding a +member (`POST /classes/{id}/members`) enrolls them into every course the class +already carries — and what gets written is an ordinary `enrollment` row, the +same one `POST /courses/{id}/enrollments` writes, counted against the same +`enrollment_count`. Each row a class writes is tagged with it as the row's +`source`; **no `source` means placed by hand**, and that one bit is what makes +the sweeps below safe. It is internal bookkeeping, not API surface: no +enrollment response returns it. + +**Already enrolled is skipped.** A pair that already has an enrollment row is +left exactly as it stands — no second seat charged, no `source` rewritten. A +student a teacher enrolled by hand *stays* hand-placed when the class later +attaches that course, so the class never quietly adopts someone else's roster +decision. + +**Capacity is all-or-nothing.** Attaching a course, or adding a member, claims +one seat per pair that needs a new row, each against its own course's +`capacity` — and if any single course has no room the whole call is a `409` +naming it (`course: is full, so the class cannot take this student`, +`course: cannot hold the whole class`). Nothing lands, not even the seats +claimed earlier in the same run: a half-enrolled class is worse than a refused +one, and the refusal names the course whose capacity to raise. + +**Removals take back only what the class pumped, and repair before they +delete.** Removing a member (`DELETE /classes/{id}/members/{user}`) or +detaching a course (`DELETE /classes/{id}/courses/{course}`) sweeps the +enrollment rows whose `source` is *this* class and no others — hand-placed +rows survive every class operation. Even a tagged row is not automatically +deleted: if a **second class** still claims that pair (it holds the same +student *and* that course attached), the row is re-tagged to that class +instead, because the row it skipped writing is the row now being swept and the +student is still owed the seat. The heir is the lowest class id among the +claimants, so repeating a sweep lands on the same class. Only a row nobody is +left to claim is deleted and its seat handed back. Sweeps also tolerate rows +that are already gone — deleting a course wipes its enrollments wholesale +while the class memberships survive — so "this class has a member" and "that +member holds a pumped row" are independent facts. + +**A manual unenroll wins, permanently.** `DELETE /courses/{id}/enrollments/{user}` +on a pumped student is allowed and sticks: nothing re-pumps them while they +remain a member, because the pump runs on writes, never on a schedule. Staff +put them back by enrolling them by hand (which makes the row hand-placed) or +by detaching and re-attaching the course. + +**Delete guards.** A class still holding members or attached courses refuses +deletion with a `409` ("remove its members and detach its courses first") — +the roster it owes is never dropped out from under the courses silently. A +term linked by any class refuses deletion the same way courses make it refuse. +Deleting a **course** detaches it from every class it was on (its enrollments +go with it), and a role change that takes a user off `student` drops their +class memberships exactly as it drops their enrollments — a membership left +behind would keep pumping them back into courses. + +**Who may.** Creating, editing and deleting a class, and adding or removing +its members, is **manager+** — a class is school structure, not classroom +work. Attaching or detaching a course takes management rights on **that +course** (its creator, a teacher assigned to it, or manager+), since the call +writes that course's roster and nothing else: the same right enrolling one +student takes. Every read (`GET /classes`, `/classes/{id}`, its members and +its courses, all paged, newest first) is **teacher+**. + +**Codes.** Adding a member or attaching a course answers `201`; a repeat is a +`409` ("the student is already in this class", "the course is already on this +class"). An id in the **body** that names nothing — an unknown `user_id` or +`course_id`, or a member who is not a `student` — is a `400`; an id in the +**path** that names nothing (the class, or a member/course that was not on it) +is a `404`. Bounds: name ≤ 200 characters, grade ≤ 20, both published in the +`course` group of `GET /limits`. + ## Quick tour (curl) ```sh diff --git a/src/lib.rs b/src/lib.rs index 6607f0c..684ceb9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,7 +36,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. Notes carry file attachments (PDFs, documents — stored on disk, capped per file by the school's settings). Any two users can message each other one-to-one, mail-style: each side files its own copy through folders (recipient: inbox/archive/trash with a read flag the sender sees as a receipt; sender: sent/archive/trash), and a message is truly gone only when both sides have deleted it from their trash. 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; questions can carry images — an illustration on any question, and per-option pictures on choice questions; students can attach an answer drawing to any question in their attempt. Enrollment, exam-sitting, roll call, and marks are student-only — staff run them, they don't take part. Every event carries an audience — the whole school, one role, a course's enrollment, or a registration list — that defines its expected-attendee roster (visibility is unaffected: everyone sees every event). Registration-audience events hold a signup list built one seat at a time: teachers register students (students never register themselves), staff register only themselves, the list optionally caps at a capacity, and it closes the moment the event starts. Event attendance is taken by teachers+ against that audience (students never self-mark), and a per-event roster report joins the expected list with the marks to show who missed. Courses come in three behaviorally identical kinds — `course` (a regular class), `study` (a supervised study session — etüt), and `club` (a student club — kulüp) — may cap their roster with an optional enroll-time `capacity` (a full course refuses new members), and carry lesson sessions with teacher-taken roll call. A course is run by whoever created it plus any teachers a manager assigns to it (`POST /courses/{id}/teachers`) — an assigned teacher manages everything inside the course (exams, sessions, subjects, roster, grading) but cannot delete the course or change who else teaches it, and a demotion below `teacher` drops their assignments. Each course also owns its curriculum as a list of subjects, and every exam question and every homework must be tagged with one of its course's subjects (a subject still referenced by questions or homework cannot be deleted); staff clock in/out on a server-stamped work log; students run a pomodoro study timer whose focus sessions land in a server-stamped log (starting discards a dangling unfinished session; teachers can read any student's log and its total focus time); attendance reports tally events and per-course roll call with rates. Courses also hand out homework: teacher-assigned per course to the whole class or a named subset the unnamed never even see (404s, no existence leak), subject-tagged and due by a required future `due_at`; students submit optional text plus up to 10 files of any content type (each capped by `max_file_bytes`, always served back as forced attachment downloads), editable until a teacher grades a status (`done`/`incomplete`/`missing`) with an optional 0–100 mark — the grade freezes the submission until removed, work never handed in is gradable `missing`, lateness is computed from an immutable first-submit stamp and a moving last-touch stamp (never stored), the grading roster computes `missing` and `unenrolled` flags, and homework marks stay out of the weighted `/marks` averages. School-varying policy (exam kinds with their course-average weights, attendance statuses, grade-display bands, the note-file size limit) lives in an editable settings singleton, and courses may link to academic terms. Each account also carries its own UI preferences — theme (`light`/`dark`), language (`tr`/`en`), and accent color (`palette_color`, a 6-digit hex like `#fefae0` — any hex, not a fixed palette) — self-managed, admin-editable for anyone, and `null` until chosen (the client then follows the device preference). A `parent` role observes without touching: admins tie any number of students to a parent account (`POST /users/{id}/students`), the parent lists them at `GET /users/me/students` and reads each one's mark, attendance, pomodoro, and homework reports — and nothing else; parents hold no staff power and never act as students (no enrolling, sitting exams, or roll call). A school-wide **question pool** lets students ask for help: a student posts a question (optionally with a photo of the problem — same raster rules and size cap as question images), a teacher+ approves it into the pool (or deletes it — rejection is deletion, there is no rejected state), and every approved question is readable by the whole school (parents excepted), with anyone free to offer solutions under it — text plus an optional photo of the worked steps, both editable by the solution's author at any time, since solutions are unmoderated and never freeze — and every question row carries its `solution_count`; pending questions are visible only to their asker and to teacher+ (whose `?status=pending` list is the approval queue), and approval freezes the question's content so nothing unmoderated can slip into the pool afterwards. Teachers keep an **appointment calendar**: a teacher+ publishes availability slots (one-off, or repeating weekly up to an `until` date as a series that deletes as one), and students and parents book a slot with a reason — the booking lands `pending` until the teacher approves it, rejects it, or counter-proposes another time (which sends it back to `pending` for the requester to accept or decline); the requester may cancel until the meeting starts — a teacher ends a booking by rejecting it, or by counter-proposing and then rejecting an approved one — one live booking holds a slot, a teacher's published windows may not overlap each other (`409`, half-open, so back-to-back slots are fine), and no approved meeting may overlap another for the teacher or the requester. While the database connection is reconnecting (a restart, a dropped socket) requests briefly answer `503` with `Retry-After: 1` — transient, retry shortly. Every list endpoint accepts `?limit=&offset=` and returns a `{items, total, limit, offset}` page envelope — paging is opt-in, so omitting `limit` returns the full list and `total` always carries the unpaged count. Every fixed validation bound — field lengths, numeric ranges, and the closed value sets (roles, course kinds, exam and question kinds, homework statuses, uploadable image types) — is published at `GET /limits` (no auth, cache for the session), so a client validates against the server's own constants instead of a hard-coded copy that drifts. It also reports this server's live rate-limit tiers, so a client learns its request budget instead of discovering it by collecting a `429`, and it keeps answering while the database is down — a client booting against a degraded backend still gets the contract.", + description = "Notes, events, attendance, courses, and weighted exam marks behind cookie-session auth. Notes carry file attachments (PDFs, documents — stored on disk, capped per file by the school's settings). Any two users can message each other one-to-one, mail-style: each side files its own copy through folders (recipient: inbox/archive/trash with a read flag the sender sees as a receipt; sender: sent/archive/trash), and a message is truly gone only when both sides have deleted it from their trash. 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; questions can carry images — an illustration on any question, and per-option pictures on choice questions; students can attach an answer drawing to any question in their attempt. Enrollment, exam-sitting, roll call, and marks are student-only — staff run them, they don't take part. Every event carries an audience — the whole school, one role, a course's enrollment, or a registration list — that defines its expected-attendee roster (visibility is unaffected: everyone sees every event). Registration-audience events hold a signup list built one seat at a time: teachers register students (students never register themselves), staff register only themselves, the list optionally caps at a capacity, and it closes the moment the event starts. Event attendance is taken by teachers+ against that audience (students never self-mark), and a per-event roster report joins the expected list with the marks to show who missed. Courses come in three behaviorally identical kinds — `course` (a regular taught course), `study` (a supervised study session — etüt), and `club` (a student club — kulüp) — may cap their roster with an optional enroll-time `capacity` (a full course refuses new members), and carry lesson sessions with teacher-taken roll call. A course is run by whoever created it plus any teachers a manager assigns to it (`POST /courses/{id}/teachers`) — an assigned teacher manages everything inside the course (exams, sessions, subjects, roster, grading) but cannot delete the course or change who else teaches it, and a demotion below `teacher` drops their assignments. Students can also be grouped into classes (şube — a `9-A`), which are bulk enrollment rather than a second kind of membership: attaching a course to a class enrolls its whole roster, adding a member enrolls them into every course the class already carries, and what gets written are ordinary enrollment rows tagged with the class that pumped them (untagged = placed by hand, and a hand-placed row is never adopted, never swept). An attach or a member-add that any target course has no seat for is refused whole (409 naming that course), removing a member or detaching a course takes back only the rows that class pumped — re-tagging a row a second class still claims instead of dropping it — and a class still holding members or courses refuses deletion. Each course also owns its curriculum as a list of subjects, and every exam question and every homework must be tagged with one of its course's subjects (a subject still referenced by questions or homework cannot be deleted); staff clock in/out on a server-stamped work log; students run a pomodoro study timer whose focus sessions land in a server-stamped log (starting discards a dangling unfinished session; teachers can read any student's log and its total focus time); attendance reports tally events and per-course roll call with rates. Courses also hand out homework: teacher-assigned per course to the whole course or a named subset the unnamed never even see (404s, no existence leak), subject-tagged and due by a required future `due_at`; students submit optional text plus up to 10 files of any content type (each capped by `max_file_bytes`, always served back as forced attachment downloads), editable until a teacher grades a status (`done`/`incomplete`/`missing`) with an optional 0–100 mark — the grade freezes the submission until removed, work never handed in is gradable `missing`, lateness is computed from an immutable first-submit stamp and a moving last-touch stamp (never stored), the grading roster computes `missing` and `unenrolled` flags, and homework marks stay out of the weighted `/marks` averages. School-varying policy (exam kinds with their course-average weights, attendance statuses, grade-display bands, the note-file size limit) lives in an editable settings singleton, and courses may link to academic terms. Each account also carries its own UI preferences — theme (`light`/`dark`), language (`tr`/`en`), and accent color (`palette_color`, a 6-digit hex like `#fefae0` — any hex, not a fixed palette) — self-managed, admin-editable for anyone, and `null` until chosen (the client then follows the device preference). A `parent` role observes without touching: admins tie any number of students to a parent account (`POST /users/{id}/students`), the parent lists them at `GET /users/me/students` and reads each one's mark, attendance, pomodoro, and homework reports — and nothing else; parents hold no staff power and never act as students (no enrolling, sitting exams, or roll call). A school-wide **question pool** lets students ask for help: a student posts a question (optionally with a photo of the problem — same raster rules and size cap as question images), a teacher+ approves it into the pool (or deletes it — rejection is deletion, there is no rejected state), and every approved question is readable by the whole school (parents excepted), with anyone free to offer solutions under it — text plus an optional photo of the worked steps, both editable by the solution's author at any time, since solutions are unmoderated and never freeze — and every question row carries its `solution_count`; pending questions are visible only to their asker and to teacher+ (whose `?status=pending` list is the approval queue), and approval freezes the question's content so nothing unmoderated can slip into the pool afterwards. Teachers keep an **appointment calendar**: a teacher+ publishes availability slots (one-off, or repeating weekly up to an `until` date as a series that deletes as one), and students and parents book a slot with a reason — the booking lands `pending` until the teacher approves it, rejects it, or counter-proposes another time (which sends it back to `pending` for the requester to accept or decline); the requester may cancel until the meeting starts — a teacher ends a booking by rejecting it, or by counter-proposing and then rejecting an approved one — one live booking holds a slot, a teacher's published windows may not overlap each other (`409`, half-open, so back-to-back slots are fine), and no approved meeting may overlap another for the teacher or the requester. While the database connection is reconnecting (a restart, a dropped socket) requests briefly answer `503` with `Retry-After: 1` — transient, retry shortly. Every list endpoint accepts `?limit=&offset=` and returns a `{items, total, limit, offset}` page envelope — paging is opt-in, so omitting `limit` returns the full list and `total` always carries the unpaged count. Every fixed validation bound — field lengths, numeric ranges, and the closed value sets (roles, course kinds, exam and question kinds, homework statuses, uploadable image types) — is published at `GET /limits` (no auth, cache for the session), so a client validates against the server's own constants instead of a hard-coded copy that drifts. It also reports this server's live rate-limit tiers, so a client learns its request budget instead of discovering it by collecting a `429`, and it keeps answering while the database is down — a client booting against a degraded backend still gets the contract.", ), modifiers(&SecurityAddon), tags( @@ -49,8 +49,8 @@ use crate::state::AppState; (name = "messages", description = "One-to-one mail-style messages between any two users (parents included — messaging is the one place a parent writes), each optionally tagged with a free-text `label` badge. Each party owns their copy independently: the recipient's moves through `inbox`/`archive`/`trash` with a read flag (visible to the sender as a read receipt), the sender's through `sent`/`archive`/`trash`. Filing a copy away records the folder it left as its `previous_folder`, so restoring it puts it back where it came from (a trashed archive copy returns to the archive, not the inbox). `GET /messages?folder=` lists one folder (`&read=false` narrows to unread — with `limit=1`, `total` is the unread badge); permanent deletion (`DELETE`) works only from the trash and removes the row once both sides have deleted"), (name = "appointments", description = "Teacher availability slots and the meetings booked on them. A teacher+ publishes windows (`POST /appointments/slots`), optionally repeating weekly up to an `until` date (at most 52 occurrences, all sharing a `series` id that deletes as one). A published window may not overlap another of the *same teacher's* (`409`): the check is half-open, so 10:00–10:30 and 10:30–11:00 are two slots and not a collision, and a weekly publish is all-or-nothing — one colliding occurrence refuses the whole series. Students and parents book one with a required reason — a parent books for themselves, this is the parent-teacher conference — and the request lands `pending`: publishing availability is not consent to a person and a topic. The teacher approves, rejects, or counter-proposes another time; a counter-proposal sends the booking back to `pending` and clears `decided_by`, and the requester either accepts it (approval at the new time) or declines, which cancels the booking. A window that has already opened is closed on every side (409): such a slot cannot be booked, an underway time cannot be approved, accepted, or counter-proposed, and the requester may cancel — declining included, since a decline *is* a cancel — only until the meeting's effective window starts. Cancelling is the **requester's** route alone (`403` for anyone else, the slot's teacher and a manager/admin included, since the guard compares ids and not roles): a teacher ends a booking by rejecting it while it is `pending`, and an approved one by counter-proposing another time (back to `pending`) and then rejecting it, or simply by rescheduling. Both the reject and the cancel take an optional `reason`, and the row records who settled it (`decided_by`, `cancelled_by`) with that text (`reject_reason`, `cancel_reason`) — visible only to the requester and the slot's teacher, since that is who a booking is ever rendered to. One live booking holds a slot (rejecting or cancelling frees it), no approved meeting may overlap another for the teacher *or* the requester (409), and a slot with a live booking refuses deletion (409). A teacher demoted after publishing leaves inert slots: they drop out of the bookable list and booking one is refused"), (name = "events", description = "Events with an audience (school-wide, one role, a course's enrollment, or a registration signup list — the expected-attendee roster; every event stays visible to all) and their attendance: teacher+ marks people in the audience (students never mark, not even themselves), and the roster report joins the expected list with the marks to show who missed. Registration lists are filled seat by seat (teachers place students, staff place only themselves), optionally capped by `capacity`, and close once the event starts. `GET /events` takes an optional `?starts_after=&ends_after=` schedule window (unix-millis) that keeps only upcoming/unfinished events and lists them soonest-first; without it the list stays newest-first"), - (name = "courses", description = "Courses — kind `course` (regular class), `study` (etüt, a supervised study session), or `club` (kulüp, a student club; same behavior, different label) — optional enroll-time seat `capacity`, enrollment (students only), course exams, and course sessions. A course is run by its creator plus any teachers a manager assigned to it (`POST /courses/{id}/teachers`): assigned teachers manage everything inside the course but cannot delete it or change the assignment list. A course with anyone still enrolled refuses deletion (409) — empty the roster first"), - (name = "classes", description = "Classes (şube): a named set of students the school moves as one. A class is bulk enrollment, not a second kind of membership — adding a student enrolls them into every course the class carries, attaching a course enrolls the whole roster into it, and the rows written are ordinary enrollments. A course with too few seats takes none of the class (409, naming the course), a student already enrolled by hand keeps their own row (never adopted, never swept), and a class still holding students or courses refuses deletion (409). The class itself and its roster are manager+; attaching or detaching a course takes management rights on *that course*, since it writes that course's roster"), + (name = "courses", description = "Courses — kind `course` (a regular taught course), `study` (etüt, a supervised study session), or `club` (kulüp, a student club; same behavior, different label) — optional enroll-time seat `capacity`, enrollment (students only), course exams, and course sessions. A course is run by its creator plus any teachers a manager assigned to it (`POST /courses/{id}/teachers`): assigned teachers manage everything inside the course but cannot delete it or change the assignment list. A roster is also filled in bulk by attaching the course to a class (see `classes`), which writes the same ordinary enrollment rows one at a time. A course with anyone still enrolled refuses deletion (409) — empty the roster first"), + (name = "classes", description = "Classes (şube): a named set of students the school moves as one. A class is bulk enrollment, not a second kind of membership — adding a student enrolls them into every course the class carries, attaching a course enrolls the whole roster into it, and the rows written are ordinary enrollments, each tagged with the class that pumped it (a row with no such tag was placed individually). A course with too few seats takes none of the class — the whole call is a 409 naming the course that ran out, and not one of the seats claimed earlier in the same run is kept — and a student already enrolled by hand keeps their own row (never adopted, never swept). Removing a member or detaching a course takes back only the rows that class pumped, and even then repairs before it deletes: a row a *second* class still claims (it holds the same student and the same course) is re-tagged to that class instead of being dropped, so nobody loses a seat someone is still responsible for. Unenrolling a pumped student by hand is allowed and permanent — the class does not put them back; staff re-enroll them or detach and re-attach the course. A class may link an academic term (which then refuses deletion while it does), and a class still holding students or courses refuses deletion itself (409). The class itself and its roster are manager+, every read is teacher+, and attaching or detaching a course takes management rights on *that course*, since it writes that course's roster"), (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 = "pomodoro", description = "Student pomodoro focus log: start/finish stamped by the server clock (starting discards any dangling unfinished session, so a crashed timer never blocks the next one), own history with the unpaged `total_focus_ms` sum, and teacher+ (or linked-parent) reads of any student's log. Breaks and the work/break rhythm stay in the frontend — the backend records only focus stints"), @@ -65,7 +65,7 @@ use crate::state::AppState; (name = "subjects", description = "A course's curriculum topics. Created and listed under `/courses/{id}/subjects`; lookup/edit/delete at `/subjects/{id}`. Every exam question links to one of its course's subjects, so a subject in use cannot be deleted (409) — re-tag or delete the questions first. View follows the course (enrolled users, creator, assigned teachers, manager+); edit follows course management rights"), (name = "homework", description = "Course homework: a teacher assigns it per course (`POST /courses/{id}/homework`), tagged with one of the course's subjects (re-taggable; a subject with homework refuses deletion until it is re-tagged or removed) and given a future `due_at`, to the whole enrolled course or an optional `assigned` subset (empty means the whole course — whoever is enrolled when they submit; a subset cannot later be narrowed so as to strand work that already exists). Students submit optional text plus files — any content type, up to 10 per submission, each capped by the school's `max_file_bytes`, always served back as forced attachment downloads (never inline); a submission touched after `due_at` is flagged late (computed from the moving last-touch stamp, never stored — the first-submit stamp is immutable) and stays editable until it is graded. A teacher grades a status (`done`/`incomplete`/`missing`) with an optional 0–100 mark — grading freezes the submission until the grade is removed (un-grading reopens it), never targets the grader themselves, and covers work never handed in (that is how `missing` is set; the student reads the verdict at `GET /homework/{id}/result`). Beyond a teacher-set `missing` the roster and reports also compute a `missing` for anyone unsubmitted past due, and the roster keeps a straggler's stale work visible (flagged `unenrolled`) after an unenrollment or promotion. Homework marks stay out of the weighted `/marks` averages. Students see and fetch only the homework they are assigned (others 404, so a subset assignment never leaks); a linked parent reads a student's homework report — statuses, late flags, marks — but never the submitted files"), (name = "boards", description = "Collaborative whiteboards. Anyone **from `student` upwards** opens a board (`POST /boards`) with a title and an ad-hoc invite list of user ids — no course, session or appointment is involved — and every participant draws on it; the creator alone clears, locks, closes or deletes it. The `parent` role has no whiteboard access whatsoever: it is refused `POST /boards` and `GET /boards` with a `403`, and cannot be named in an invite list at all (`400`) — so a parent is never on a roster, which makes every id-scoped route and the room's door answer the outsider's `404` rather than a `403` that would confirm the board exists. A caller who is not on a board gets a `404` for it on every route, existence included, while a participant who is not the creator gets a `403` on those four commands (they are already rendering the board, so hiding it from them would be a lie their client cannot act on). Strokes are **append-only and a clear deletes nothing**: it bumps the board's `epoch`, so the live canvas empties while every mark ever drawn stays stored — `GET /boards/{id}/strokes` is the current epoch (what a client draws to catch up), `GET /boards/{id}/history?epoch=` is the whole session or one named epoch, and `GET /boards/{id}/epochs` is the index of `clear` markers, each carrying the epoch it closed, that epoch's final stroke count, who cleared and when (the markers *are* the index, so the open epoch is deliberately absent from it). Two growth caps, both published at `GET /limits`: `max_epoch_strokes` bounds the *live* canvas and is recoverable (clear it and drawing resumes, losing nothing), while `max_board_strokes` bounds the board's *lifetime* storage and stamps `closed_at` on the way past — a closed board is permanently read-only and fully readable, never deleted, and there is no reopen. `POST /boards/{id}/close` is the manual form of that, and idempotent. `DELETE /boards/{id}` is the one operation here that really destroys marks — it takes the whole stroke log with it and frees one of the creator's `max_boards_per_creator` seats. `PATCH /boards/{id}` re-titles (any participant) or changes the roster and the lock (creator only). Not in this spec (WebSocket): the live board room at `GET /boards/{id}/ws`, where the drawing itself happens — JSON frames, cookie-authed, and a **404** at the door for anyone not on the board. A `join` replays the current epoch only (chunked `strokes`, then `synced` with the cursor to resume from); a `stroke` is persisted before it is fanned out, so every canvas in the room is showing rows that committed; `clear` and `lock` are the creator's alone and refuse anyone else with `error{code:\"forbidden\"}` *without* closing their socket. The REST mutations above fan out into the same room, and a roster change drops the socket of anyone it removed. See `src/web/board_ws.rs` for the frame-by-frame protocol"), - (name = "terms", description = "Academic terms (semester/trimester/quarter — whatever the school runs); courses may link to one. A term still linked by any course cannot be deleted (409) — unlink those courses first. Read: any authenticated user; edit: manager+"), + (name = "terms", description = "Academic terms (semester/trimester/quarter — whatever the school runs); courses and classes may link to one. A term still linked by any course or class cannot be deleted (409) — unlink them first. Read: any authenticated user; edit: manager+"), ), )] struct ApiDoc;