forge
Explore
Log in

Don't you dare go Hollow

πŸ“ teach all three surfaces the class layer

Browse files at this commit

0c7403b123d917a21b813ed44d77caa242dcc8eeAhmet Kaan GümüşParent: ddc09d7
  • docs
    • πŸ“ teach all three surfaces the class layer
Show full message
docs: πŸ“ teach all three surfaces the class layer
README.mdmodified+104 -11
@@ -22,7 +22,7 @@ closes the moment the event starts (or, for an event with only an end time β€”
22 a pure signup deadline β€” the moment that end passes). Every event stays visible to everyone β€”22 a pure signup deadline β€” the moment that end passes). Every event stays visible to everyone β€”
23 the audience is a roster, not a wall. Marks are course-shaped23 the audience is a roster, not a wall. Marks are course-shaped
24 (Google Classroom style): a teacher creates a course β€” kind **`course`** (a24 (Google Classroom style): a teacher creates a course β€” kind **`course`** (a
25-regular class), **`study`** (a supervised study session β€” *etΓΌt*), or25+regular taught course), **`study`** (a supervised study session β€” *etΓΌt*), or
26 **`club`** (a student club β€” *kulΓΌp*; same behavior, different label),26 **`club`** (a student club β€” *kulΓΌp*; same behavior, different label),
27 optionally capped by a `capacity` that refuses new enrolls once the roster is27 optionally capped by a `capacity` that refuses new enrolls once the roster is
28 full β€” lays out its **subjects** (curriculum topics β€”28 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
33 plus any teachers a **manager assigns** to it (`POST /courses/{id}/teachers`):33 plus any teachers a **manager assigns** to it (`POST /courses/{id}/teachers`):
34 an assigned teacher manages everything inside the course β€” exams, sessions,34 an assigned teacher manages everything inside the course β€” exams, sessions,
35 subjects, roster, grading β€” but can't delete it or change who else teaches it,35 subjects, roster, grading β€” but can't delete it or change who else teaches it,
36-and a demotion below `teacher` sweeps their assignments away. Students read a per-course weighted average and36+and a demotion below `teacher` sweeps their assignments away. Students are
37+grouped into **classes** (*şube* β€” 9-A, 10-B) when a school teaches that way:
38+a class is bulk enrollment and not a second kind of membership β€” attaching a
39+course to it enrolls the whole roster, adding a member enrolls them into every
40+course already attached, and what lands are ordinary enrollment rows tagged
41+with the class that pumped them (untagged = placed by hand, and hand-placed
42+rows are never adopted and never swept). A course without room for everyone
43+refuses the whole operation, naming it (see "Classes (şube)"). Students read a per-course weighted average and
37 an overall average from their mark report β€” each exam weighted by its **kind**44 an overall average from their mark report β€” each exam weighted by its **kind**
38 (midterms can count double, orals once: weights are set per kind in settings,45 (midterms can count double, orals once: weights are set per kind in settings,
39 not per exam). Exams run **sync** (one46 not per exam). Exams run **sync** (one
@@ -55,7 +62,7 @@ whoever saved them. Teachers
55 watch attendance, per-student remaining time,62 watch attendance, per-student remaining time,
56 sittings, walk-outs, no-shows (`absent` once the window closes), submissions,63 sittings, walk-outs, no-shows (`absent` once the window closes), submissions,
57 and marks land live on a monitor endpoint (snapshot or SSE stream). Courses also hand out64 and marks land live on a monitor endpoint (snapshot or SSE stream). Courses also hand out
58-**homework**: assigned to the whole class or a named subset (the unnamed never65+**homework**: assigned to the whole course or a named subset (the unnamed never
59 even see it), tagged with a course subject, due by a required future `due_at`66 even see it), tagged with a course subject, due by a required future `due_at`
60 β€” students hand in text and/or **files of any type** (same size cap, 10 per67 β€” students hand in text and/or **files of any type** (same size cap, 10 per
61 submission, served back only as forced downloads), editable until the teacher68 submission, served back only as forced downloads), editable until the teacher
@@ -514,6 +521,8 @@ course enrollments.
514 | Delete a course | teacher | Only the **creator**, or a `manager`+ β€” an assigned teacher runs the course but doesn't own it |521 | Delete a course | teacher | Only the **creator**, or a `manager`+ β€” an assigned teacher runs the course but doesn't own it |
515 | 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`) |522 | 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`) |
516 | View a course's roster, an exam's result list / statistics | teacher | Course-management rights |523 | View a course's roster, an exam's result list / statistics | teacher | Course-management rights |
524+| 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` |
525+| 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 |
517 | 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 |526 | 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 |
518 | Grade students | teacher | Target must be an **enrolled student**; grading never targets oneself |527 | Grade students | teacher | Target must be an **enrolled student**; grading never targets oneself |
519 | 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 |528 | 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.
561 `Auth` is the minimum role; `no` means no session required, `student` means any570 `Auth` is the minimum role; `no` means no session required, `student` means any
562 logged-in user.571 logged-in user.
563 572
564-A course is a regular class (kind `course`, the default), an *etΓΌt* (kind573+A course is a regular taught course (kind `course`, the default), an *etΓΌt* (kind
565 `study` β€” a supervised study session), or a *kulΓΌp* (kind `club` β€” a student574 `study` β€” a supervised study session), or a *kulΓΌp* (kind `club` β€” a student
566 club). The three kinds behave identically everywhere β€” enrollment, exams,575 club). The three kinds behave identically everywhere β€” enrollment, exams,
567 sessions, marks β€” the kind is a label the UI renders differently, settable at576 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.
701 | DELETE | `/classes/{id}` | manager | Delete a class β€” `409` while it still holds students or courses |710 | DELETE | `/classes/{id}` | manager | Delete a class β€” `409` while it still holds students or courses |
702 | 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) |711 | 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) |
703 | GET | `/classes/{id}/members` | teacher | List the class roster Β· paged |712 | GET | `/classes/{id}/members` | teacher | List the class roster Β· paged |
704-| DELETE | `/classes/{id}/members/{user}` | manager | Remove a student and sweep the enrollments the class pumped for them |713+| 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) |
705 | 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) |714 | 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) |
706 | GET | `/classes/{id}/courses` | teacher | List the class's attached courses Β· paged |715 | GET | `/classes/{id}/courses` | teacher | List the class's attached courses Β· paged |
707-| DELETE | `/classes/{id}/courses/{course}` | teacher | Detach a course (that course's manager) and sweep the enrollments the class pumped |716+| DELETE | `/classes/{id}/courses/{course}` | teacher | Detach a course (that course's manager) β€” the same sweep along the course axis |
708 | POST | `/courses/{id}/sessions` | teacher | `{topic?, teacher_id?, starts_at, ends_at?}` β€” add a lesson (course manager; teacher defaults to the caller) |717 | POST | `/courses/{id}/sessions` | teacher | `{topic?, teacher_id?, starts_at, ends_at?}` β€” add a lesson (course manager; teacher defaults to the caller) |
709 | GET | `/courses/{id}/sessions` | student | List the course's sessions, most recent first (enrolled, creator, assigned teacher, or manager+) Β· paged |718 | GET | `/courses/{id}/sessions` | student | List the course's sessions, most recent first (enrolled, creator, assigned teacher, or manager+) Β· paged |
710 | POST | `/courses/{id}/subjects` | teacher | `{name, description?}` β€” add a curriculum subject (course manager) |719 | 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.
825 | GET | `/terms` | student | List terms, newest first Β· paged |834 | GET | `/terms` | student | List terms, newest first Β· paged |
826 | GET | `/terms/{id}` | student | Get one term |835 | GET | `/terms/{id}` | student | Get one term |
827 | PATCH | `/terms/{id}` | manager | Edit a term (the merged range must stay ordered) |836 | PATCH | `/terms/{id}` | manager | Edit a term (the merged range must stay ordered) |
828-| DELETE | `/terms/{id}` | manager | Delete a term β€” `409` while any course still links to it |837+| DELETE | `/terms/{id}` | manager | Delete a term β€” `409` while any course or class still links to it |
829 | 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 |838 | 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 |
830 | GET | `/meals/menus` | student | List menus with their dishes, newest day first Β· `?from=&to=` inclusive `YYYY-MM-DD` range Β· paged |839 | GET | `/meals/menus` | student | List menus with their dishes, newest day first Β· `?from=&to=` inclusive `YYYY-MM-DD` range Β· paged |
831 | GET | `/meals/menus/{id}` | student | One menu with its dishes |840 | 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
1258 1267
1259 Academic structure is data too. **Terms** (`/terms`) model whatever calendar1268 Academic structure is data too. **Terms** (`/terms`) model whatever calendar
1260 the school runs β€” semester, trimester, quarter systems are just rows with a1269 the school runs β€” semester, trimester, quarter systems are just rows with a
1261-name and a date range. Courses may link to one via `term_id` (nullable), and1270+name and a date range. Courses *and classes* may link to one via `term_id` (nullable),
1262-deleting a term is refused with a `409` while any course still links to it β€”1271+and deleting a term is refused with a `409` while any of them still links to
1263-unlink those courses (`PATCH /courses/{id}` with `"term_id": null`) or delete1272+it β€” unlink them (`PATCH /courses/{id}` or `PATCH /classes/{id}` with
1264-them first, so the calendar never disappears under them. Term dates may lie in the past,1273+`"term_id": null`) or delete them first, so the calendar never disappears
1274+under them. Term dates may lie in the past,
1265 deliberately: a school adopting the app mid-year backfills its calendar β€”1275 deliberately: a school adopting the app mid-year backfills its calendar β€”
1266 unlike exam/lesson/event times, which reject backdating.1276 unlike exam/lesson/event times, which reject backdating.
1267 1277
@@ -2131,6 +2141,89 @@ for every course the user has roll-call rows in β€” attendance is a historical
2131 record, so unenrolling hides marks from the marks report but never hides an2141 record, so unenrolling hides marks from the marks report but never hides an
2132 absence.2142 absence.
2133 2143
2144+## Classes (şube)
2145+
2146+A **class** is the group a school actually teaches in β€” 9-A, 10-B β€” and here
2147+it is a bulk-enrollment tool rather than a second kind of membership. A class
2148+row carries a name, an optional free-text `grade` label in the school's own
2149+vocabulary (`"9"`, `"Lise 2"`; `""` means no grade, exactly like omitting it)
2150+and an optional `term_id`; nothing else about a course changes because a class
2151+exists. Schools that run electives or a college-style timetable simply never
2152+create one β€” individual enrollment is untouched, and classes are a
2153+convenience.
2154+
2155+**The pump.** A class holds **members** (students) and **attached courses**,
2156+and owes the product of the two: every member enrolled in every attached
2157+course. So both writes push the same way β€” attaching a course
2158+(`POST /classes/{id}/courses`) enrolls the whole roster into it, adding a
2159+member (`POST /classes/{id}/members`) enrolls them into every course the class
2160+already carries β€” and what gets written is an ordinary `enrollment` row, the
2161+same one `POST /courses/{id}/enrollments` writes, counted against the same
2162+`enrollment_count`. Each row a class writes is tagged with it as the row's
2163+`source`; **no `source` means placed by hand**, and that one bit is what makes
2164+the sweeps below safe. It is internal bookkeeping, not API surface: no
2165+enrollment response returns it.
2166+
2167+**Already enrolled is skipped.** A pair that already has an enrollment row is
2168+left exactly as it stands β€” no second seat charged, no `source` rewritten. A
2169+student a teacher enrolled by hand *stays* hand-placed when the class later
2170+attaches that course, so the class never quietly adopts someone else's roster
2171+decision.
2172+
2173+**Capacity is all-or-nothing.** Attaching a course, or adding a member, claims
2174+one seat per pair that needs a new row, each against its own course's
2175+`capacity` β€” and if any single course has no room the whole call is a `409`
2176+naming it (`course:<key> is full, so the class cannot take this student`,
2177+`course:<key> cannot hold the whole class`). Nothing lands, not even the seats
2178+claimed earlier in the same run: a half-enrolled class is worse than a refused
2179+one, and the refusal names the course whose capacity to raise.
2180+
2181+**Removals take back only what the class pumped, and repair before they
2182+delete.** Removing a member (`DELETE /classes/{id}/members/{user}`) or
2183+detaching a course (`DELETE /classes/{id}/courses/{course}`) sweeps the
2184+enrollment rows whose `source` is *this* class and no others β€” hand-placed
2185+rows survive every class operation. Even a tagged row is not automatically
2186+deleted: if a **second class** still claims that pair (it holds the same
2187+student *and* that course attached), the row is re-tagged to that class
2188+instead, because the row it skipped writing is the row now being swept and the
2189+student is still owed the seat. The heir is the lowest class id among the
2190+claimants, so repeating a sweep lands on the same class. Only a row nobody is
2191+left to claim is deleted and its seat handed back. Sweeps also tolerate rows
2192+that are already gone β€” deleting a course wipes its enrollments wholesale
2193+while the class memberships survive β€” so "this class has a member" and "that
2194+member holds a pumped row" are independent facts.
2195+
2196+**A manual unenroll wins, permanently.** `DELETE /courses/{id}/enrollments/{user}`
2197+on a pumped student is allowed and sticks: nothing re-pumps them while they
2198+remain a member, because the pump runs on writes, never on a schedule. Staff
2199+put them back by enrolling them by hand (which makes the row hand-placed) or
2200+by detaching and re-attaching the course.
2201+
2202+**Delete guards.** A class still holding members or attached courses refuses
2203+deletion with a `409` ("remove its members and detach its courses first") β€”
2204+the roster it owes is never dropped out from under the courses silently. A
2205+term linked by any class refuses deletion the same way courses make it refuse.
2206+Deleting a **course** detaches it from every class it was on (its enrollments
2207+go with it), and a role change that takes a user off `student` drops their
2208+class memberships exactly as it drops their enrollments β€” a membership left
2209+behind would keep pumping them back into courses.
2210+
2211+**Who may.** Creating, editing and deleting a class, and adding or removing
2212+its members, is **manager+** β€” a class is school structure, not classroom
2213+work. Attaching or detaching a course takes management rights on **that
2214+course** (its creator, a teacher assigned to it, or manager+), since the call
2215+writes that course's roster and nothing else: the same right enrolling one
2216+student takes. Every read (`GET /classes`, `/classes/{id}`, its members and
2217+its courses, all paged, newest first) is **teacher+**.
2218+
2219+**Codes.** Adding a member or attaching a course answers `201`; a repeat is a
2220+`409` ("the student is already in this class", "the course is already on this
2221+class"). An id in the **body** that names nothing β€” an unknown `user_id` or
2222+`course_id`, or a member who is not a `student` β€” is a `400`; an id in the
2223+**path** that names nothing (the class, or a member/course that was not on it)
2224+is a `404`. Bounds: name ≀ 200 characters, grade ≀ 20, both published in the
2225+`course` group of `GET /limits`.
2226+
2134 ## Quick tour (curl)2227 ## Quick tour (curl)
2135 2228
2136 ```sh2229 ```sh
src/lib.rsmodified+4 -4
@@ -36,7 +36,7 @@ use crate::state::AppState;
36 info(36 info(
37 title = "Hezarfen Backend API",37 title = "Hezarfen Backend API",
38 version = env!("CARGO_PKG_VERSION"),38 version = env!("CARGO_PKG_VERSION"),
39- 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.",39+ 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.",
40 ),40 ),
41 modifiers(&SecurityAddon),41 modifiers(&SecurityAddon),
42 tags(42 tags(
@@ -49,8 +49,8 @@ use crate::state::AppState;
49 (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"),49 (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"),
50 (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"),50 (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"),
51 (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"),51 (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"),
52- (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"),52+ (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"),
53- (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"),53+ (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"),
54 (name = "sessions", description = "Lesson sessions and their roll call (session teacher or course manager marks enrolled students; manager+ marks the teacher)"),54 (name = "sessions", description = "Lesson sessions and their roll call (session teacher or course manager marks enrolled students; manager+ marks the teacher)"),
55 (name = "work", description = "Staff work log: check-in/check-out stamped by the server clock, manager corrections"),55 (name = "work", description = "Staff work log: check-in/check-out stamped by the server clock, manager corrections"),
56 (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"),56 (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;
65 (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"),65 (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"),
66 (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"),66 (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"),
67 (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"),67 (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"),
68- (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+"),68+ (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+"),
69 ),69 ),
70 )]70 )]
71 struct ApiDoc;71 struct ApiDoc;