diff --git a/README.md b/README.md index b239ef6..40e5e6c 100644 --- a/README.md +++ b/README.md @@ -843,10 +843,10 @@ window filtering, before paging; negative values are a `400` naming the field. | GET | `/classes/{id}` | teacher | Get one class | | PATCH | `/classes/{id}` | manager | Edit a class (`null` clears `grade`/`term_id`/`teacher_id`; `409` if the `term_id` it moves off changed since the read — nothing written, re-read and retry) | | 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, if one of them no longer exists — detach that link first — if already a member, or once the class holds `max_class_members`) | +| POST | `/classes/{id}/members` | manager | `{user_id}` — add a **student**; enrolls them into every attached course (`409` if one is full, naming it, if one of them no longer exists — detach that link first — if already a member, or once the class holds `max_class_members`; every one of those carries a machine `code`) | | GET | `/classes/{id}/members` | teacher | List the class roster, newest added first · paged | | 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, if already attached, or once the class holds `max_class_courses`) | +| 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, if already attached, or once the class holds `max_class_courses`; every one of those carries a machine `code`) | | GET | `/classes/{id}/courses` | teacher | List the class's attached courses, newest attached first · paged | | DELETE | `/classes/{id}/courses/{course}` | teacher | Detach a course (that course's manager) — the same sweep along the course axis; a link left behind by a **deleted** course detaches too, rather than `404`-ing forever | | POST | `/classes/blueprints` | manager | Create a grade's course blueprint and stock every section already at that grade (best-effort; returns `matched` + `skipped`) | @@ -2977,14 +2977,26 @@ whole grade — the sections after the first one are not asked again — and nev again on a later pump), `class_at_course_ceiling`, `class_roster_too_large` (the section holds more students than one attach may enroll at once), `course_full` (no free -seat for the whole section), `linked_course_missing` (another course -already attached to that section no longer exists — detach it first), and +seat for the whole section), and `blueprint_deleted` (the template itself was deleted while the pump ran — nothing was attached, and there is nothing left to retry). That last one **ends the run**: it says nothing about the (section, course) pair it names, so every remaining section would only repeat it. It is reported once, the sections already stocked stay stocked, and the call still succeeds. +**The manual attaches answer the same vocabulary.** A `409` from +`POST /classes/{id}/members` or `POST /classes/{id}/courses` is +`{"error": "", "code": ""}` — the prose unchanged, the +code out of the set above plus two a pump never reports: `duplicate` (already a +member / already attached) and `linked_course_missing` (another course already +attached to that section no longer exists — detach it first), which only +`POST /classes/{id}/members` can meet, since a member add is the one attach +that walks the section's existing course links while a pump attaches a course +it has just proved alive. One cause therefore reads the same whether a manager +hit it by hand or a pump hit it in bulk, which is what lets a bilingual client +branch and word it once. `code` is published on those two routes only and is simply **absent** +from every other error body. + **Removal spares what a human placed.** Every attachment a blueprint makes is tagged with it. Dropping a course from the list detaches it only where the blueprint attached it (sweeping the enrollments it pumped, repairing to a rival diff --git a/src/domain/class_blueprint.rs b/src/domain/class_blueprint.rs index ebdc47b..665b631 100644 --- a/src/domain/class_blueprint.rs +++ b/src/domain/class_blueprint.rs @@ -158,36 +158,19 @@ struct Held { course: CourseId, } -/// Why this attach did not land, or `None` when it did. A duplicate is not a -/// skip: the course is already on the class, which is exactly what the -/// blueprint asks for, and re-running a pump must therefore report nothing. +/// Why this attach did not land, or `None` when it did — the shared vocabulary +/// of [`Attached::refusal_code`], which is where the codes and the set they +/// close over are documented. /// -/// A machine code, not a sentence: the client owns the wording and this API -/// only says *which* refusal it was, the shape every other enum here has -/// (roles, course kinds, the badge catalog). The set is closed and documented -/// on `SkipResponse.reason`. -/// -/// Each code names the record that actually failed. The pump's two "gone" -/// answers are a *class* delete ([`Attached::Gone`] → `class_deleted`, the -/// class counter's claim matching nothing on a row a re-read no longer finds) -/// and a *course* delete ([`Attached::PivotGone`] → `course_deleted`, the -/// course's own claim matching nothing) — and telling a manager the class -/// vanished when the course did sends them to look at a section that is -/// standing right there. `linked_course_missing` is a third: *another* course -/// already attached to this class no longer exists, and it must be detached -/// before this attach can be retried. `blueprint_deleted` is the pump losing -/// the template itself mid-run — the only skip that says nothing about the -/// (class, course) pair it names. +/// One divergence, and it lives here because only a pump has it: a duplicate is +/// not a skip. The course is already on the class, which is exactly what the +/// blueprint asks for, so re-running a pump must report nothing — while a *hand* +/// attach's duplicate is a genuine refusal (`duplicate`), because that call +/// asked for the row and did not get it. fn skip_reason(landed: &Attached) -> Option<&'static str> { match landed { - Attached::Made(_) | Attached::Duplicate => None, - Attached::Gone => Some("class_deleted"), - Attached::PivotGone => Some("course_deleted"), - Attached::ClassFull => Some("class_at_course_ceiling"), - Attached::ClassOverloaded => Some("class_roster_too_large"), - Attached::Full(_) => Some("course_full"), - Attached::CourseGone(_) => Some("linked_course_missing"), - Attached::SourceGone => Some("blueprint_deleted"), + Attached::Duplicate => None, + other => other.refusal_code(), } } @@ -1106,11 +1089,21 @@ mod tests { /// vocabulary a bilingual client branches and translates on, so a reworded /// one is a silent contract break. A new [`Attached`] variant fails the /// match arm above, and this pins what the existing ones say. + /// + /// Each one is also checked against [`Attached::refusal_code`], the manual + /// routes' half of the same vocabulary: `duplicate` is the *only* place the + /// two are allowed to differ, so a second spelling of any other code cannot + /// drift in on either side. #[test] fn every_refusal_the_pump_can_answer_is_a_skip() { - // `Made` shares `Duplicate`'s arm, and building one needs a live link - // row — the arm itself is the only thing to check there. + // `Made` is the other `None` there, and building one needs a live link + // row — the arm itself is the only thing to check for it. assert!(skip_reason(&Attached::Duplicate).is_none()); + assert_eq!( + Attached::::Duplicate.refusal_code(), + Some("duplicate"), + "a hand attach's duplicate is a refusal even though a pump's is not" + ); for (refusal, code) in [ (Attached::Gone, "class_deleted"), (Attached::PivotGone, "course_deleted"), @@ -1128,6 +1121,11 @@ mod tests { Some(code), "{refusal:?} must be reported as its own code, not swallowed or reworded" ); + assert_eq!( + refusal.refusal_code(), + skip_reason(&refusal), + "{refusal:?} must read the same on a manual 409 as in a pump's skip list" + ); } } } diff --git a/src/domain/class_course.rs b/src/domain/class_course.rs index b09b495..fa4b43f 100644 --- a/src/domain/class_course.rs +++ b/src/domain/class_course.rs @@ -93,31 +93,45 @@ impl ClassCourse { attached_by: &UserId, db: &Database, ) -> Result { - match Self::attach_sourced(class, course, attached_by, None, db).await? { + let landed = Self::attach_sourced(class, course, attached_by, None, db).await?; + // Read off the refusal, never respelled here: this route and a + // blueprint pump answer one vocabulary. `Made` is the only `None`, and + // it takes the `Ok` arm below. + let code = landed.refusal_code().unwrap_or_default(); + match landed { Attached::Made(saved) => Ok(saved), - Attached::Duplicate => Err(AppError::Conflict("the course is already on this class")), + Attached::Duplicate => Err(AppError::ConflictCoded { + code, + message: "the course is already on this class".into(), + }), // The class or the course: either end of the link being gone is a // 404 on this route, and only a blueprint's skip list needs them // told apart. Attached::Gone | Attached::PivotGone => Err(AppError::NotFound), - Attached::ClassFull => Err(AppError::ConflictOwned(format!( - "this class already holds {MAX_CLASS_COURSES} courses" - ))), + Attached::ClassFull => Err(AppError::ConflictCoded { + code, + message: format!("this class already holds {MAX_CLASS_COURSES} courses"), + }), // The other axis: attaching one course enrolls the whole roster, so // a class over *that* ceiling cannot take a course however few it // carries. Only a class predating the ceiling can be here. - Attached::ClassOverloaded => Err(AppError::ConflictOwned(format!( - "this class holds more than {MAX_CLASS_MEMBERS} students — \ - remove some before attaching a course" - ))), - Attached::Full(full) => Err(AppError::ConflictOwned(format!( - "{full} cannot hold the whole class" - ))), + Attached::ClassOverloaded => Err(AppError::ConflictCoded { + code, + message: format!( + "this class holds more than {MAX_CLASS_MEMBERS} students — \ + remove some before attaching a course" + ), + }), + Attached::Full(full) => Err(AppError::ConflictCoded { + code, + message: format!("{full} cannot hold the whole class"), + }), // Another of the class's links points at a deleted course. This // axis claims its own pivot, so it is never *this* course. - Attached::CourseGone(course) => Err(AppError::ConflictOwned(format!( - "{course} no longer exists — detach it from this class first" - ))), + Attached::CourseGone(course) => Err(AppError::ConflictCoded { + code, + message: format!("{course} no longer exists — detach it from this class first"), + }), // This path passes no source, so the claim that answers this is // never in the transaction it ran. Attached::SourceGone => Err(AppError::Internal( @@ -250,8 +264,8 @@ mod tests { let again = ClassCourse::attach(&class, &algebra, &manager, &db).await; assert!( - matches!(again, Err(AppError::Conflict(_))), - "a second attach is a 409: {again:?}" + matches!(again, Err(AppError::ConflictCoded { code, .. }) if code == "duplicate"), + "a second attach is a 409 coded `duplicate`: {again:?}" ); } @@ -271,8 +285,9 @@ mod tests { let refused = ClassCourse::attach(&class, &tight, &manager, &db).await; assert!( - matches!(refused, Err(AppError::ConflictOwned(ref message)) if message.contains(tight.key())), - "the refusal must name the course: {refused:?}" + matches!(refused, Err(AppError::ConflictCoded { code, ref message }) + if code == "course_full" && message.contains(tight.key())), + "the refusal must be coded `course_full` and name the course: {refused:?}" ); assert_eq!( rows("SELECT VALUE id FROM enrollment", &db).await, diff --git a/src/domain/class_member.rs b/src/domain/class_member.rs index 703fd6c..f729396 100644 --- a/src/domain/class_member.rs +++ b/src/domain/class_member.rs @@ -88,7 +88,7 @@ impl ClassMember { added_by: added_by.clone(), added_at: Some(Timestamp::now()), }; - match attach( + let landed = attach( class, Axis::Member, &member.id.record(), @@ -98,32 +98,45 @@ impl ClassMember { None, db, ) - .await? - { + .await?; + // Read off the refusal, never respelled here: this route and a + // blueprint pump answer one vocabulary. `Made` is the only `None`, and + // it takes the `Ok` arm below. + let code = landed.refusal_code().unwrap_or_default(); + match landed { Attached::Made(saved) => Ok(saved), - Attached::Duplicate => Err(AppError::Conflict("the student is already in this class")), + Attached::Duplicate => Err(AppError::ConflictCoded { + code, + message: "the student is already in this class".into(), + }), // The member axis claims no pivot, so `PivotGone` cannot arrive // here; the class being gone is the only 404 this route can see. Attached::Gone | Attached::PivotGone => Err(AppError::NotFound), - Attached::ClassFull => Err(AppError::ConflictOwned(format!( - "this class already holds {MAX_CLASS_MEMBERS} students" - ))), + Attached::ClassFull => Err(AppError::ConflictCoded { + code, + message: format!("this class already holds {MAX_CLASS_MEMBERS} students"), + }), // The other axis: adding one student enrolls them into every // attached course, so a class over *that* ceiling cannot take a // member however much room its roster has. - Attached::ClassOverloaded => Err(AppError::ConflictOwned(format!( - "this class holds more than {MAX_CLASS_COURSES} courses — \ - detach some before adding a student" - ))), - Attached::Full(course) => Err(AppError::ConflictOwned(format!( - "{course} is full, so the class cannot take this student" - ))), + Attached::ClassOverloaded => Err(AppError::ConflictCoded { + code, + message: format!( + "this class holds more than {MAX_CLASS_COURSES} courses — \ + detach some before adding a student" + ), + }), + Attached::Full(course) => Err(AppError::ConflictCoded { + code, + message: format!("{course} is full, so the class cannot take this student"), + }), // Not a capacity problem, and told apart from one on purpose: no // number anyone can raise unblocks this class, only detaching the // link the deleted course left behind. - Attached::CourseGone(course) => Err(AppError::ConflictOwned(format!( - "{course} no longer exists — detach it from this class first" - ))), + Attached::CourseGone(course) => Err(AppError::ConflictCoded { + code, + message: format!("{course} no longer exists — detach it from this class first"), + }), // Only an attach run on a blueprint's behalf states that claim, and // a membership is nobody's but its own. Attached::SourceGone => Err(AppError::Internal( @@ -355,8 +368,8 @@ pub(crate) mod tests { let again = ClassMember::add(&class, &student, &manager, &db).await; assert!( - matches!(again, Err(AppError::Conflict(_))), - "a second add is a 409: {again:?}" + matches!(again, Err(AppError::ConflictCoded { code, .. }) if code == "duplicate"), + "a second add is a 409 coded `duplicate`: {again:?}" ); assert_eq!( counter("class_member_count", class.record(), &db).await, @@ -388,8 +401,10 @@ pub(crate) mod tests { let named = format!("{}:{}", crate::constant::COURSE_TABLE, full.key()); let refused = ClassMember::add(&class, &student, &manager, &db).await; assert!( - matches!(refused, Err(AppError::ConflictOwned(ref message)) if message.contains(&named)), - "the refusal must name the course that had no seat as {named}: {refused:?}" + matches!(refused, Err(AppError::ConflictCoded { code, ref message }) + if code == "course_full" && message.contains(&named)), + "the refusal must be coded `course_full` and name the course that had no seat \ + as {named}: {refused:?}" ); assert_eq!( rows("SELECT VALUE id FROM enrollment", &db).await, diff --git a/src/domain/class_pump.rs b/src/domain/class_pump.rs index d9b836a..8ca44b4 100644 --- a/src/domain/class_pump.rs +++ b/src/domain/class_pump.rs @@ -126,6 +126,44 @@ pub(crate) enum Attached { SourceGone, } +impl Attached { + /// This refusal as a **machine code**, or `None` for the attach that + /// landed. The client owns the wording and the language; this only says + /// *which* refusal it was — the shape every other enum here has (roles, + /// course kinds, the badge catalog). + /// + /// The single home for that vocabulary, because both readers answer it: a + /// blueprint pump reports it as a skip + /// ([`crate::domain::class_blueprint`]) and a hand attach as the `code` on + /// its `409` ([`crate::error::AppError::ConflictCoded`]). Spelled once, so + /// one cause can never grow two codes. + /// + /// Each code names the record that actually failed. The two "gone" answers + /// are a *class* delete ([`Attached::Gone`] → `class_deleted`, the class + /// counter's claim matching nothing on a row a re-read no longer finds) and + /// a *course* delete ([`Attached::PivotGone`] → `course_deleted`, the + /// course's own claim matching nothing) — and telling a manager the class + /// vanished when the course did sends them to look at a section that is + /// standing right there. `linked_course_missing` is a third: *another* + /// course already attached to this class no longer exists, and it must be + /// detached before this attach can be retried. `blueprint_deleted` is a + /// pump losing the template itself mid-run — the only refusal that says + /// nothing about the (class, course) pair it names. + pub(crate) fn refusal_code(&self) -> Option<&'static str> { + match self { + Attached::Made(_) => None, + Attached::Duplicate => Some("duplicate"), + Attached::Gone => Some("class_deleted"), + Attached::PivotGone => Some("course_deleted"), + Attached::ClassFull => Some("class_at_course_ceiling"), + Attached::ClassOverloaded => Some("class_roster_too_large"), + Attached::Full(_) => Some("course_full"), + Attached::CourseGone(_) => Some("linked_course_missing"), + Attached::SourceGone => Some("blueprint_deleted"), + } + } +} + /// Which way the pump runs: the loop below needs a `(course, user)` pair per /// enrollment, and each caller supplies one side as a constant and reads the /// other off the class's *other* link table. diff --git a/src/error.rs b/src/error.rs index 5157739..554e639 100644 --- a/src/error.rs +++ b/src/error.rs @@ -10,6 +10,12 @@ use utoipa::ToSchema; pub struct ErrorResponse { /// Human-readable failure reason. pub error: String, + /// Machine-readable refusal code, present only where a route documents its + /// vocabulary (today: the two manual class-attach routes, which answer the + /// codes a blueprint pump reports as a skip). Absent everywhere else, so a + /// client branches on it where it is published and reads `error` otherwise. + #[serde(skip_serializing_if = "Option::is_none")] + pub code: Option, } /// Why a newtype refused to be constructed from raw input. Always maps to `400`. @@ -57,6 +63,12 @@ pub enum AppError { /// [`AppError::Conflict`]. #[error("conflict: {0}")] ConflictOwned(String), + /// A 409 that also carries a **machine code**, so a client branches on the + /// cause instead of parsing the sentence (which it cannot translate). The + /// prose is unchanged from what the same refusal always said — `code` is + /// additive, and only a route that publishes its vocabulary uses this. + #[error("conflict: {message}")] + ConflictCoded { code: &'static str, message: String }, /// A request body (file upload) over the allowed size. Owned string: the /// school-configured limit is only known at runtime. #[error("payload too large: {0}")] @@ -148,6 +160,14 @@ impl IntoResponse for AppError { ) .into_response(); } + // The one conflict with a second key, so it builds its body here. + AppError::ConflictCoded { code, message } => { + return ( + StatusCode::CONFLICT, + Json(json!({ "error": message, "code": code })), + ) + .into_response(); + } AppError::Validation(v) => (StatusCode::BAD_REQUEST, v.to_string()), AppError::NotFound => (StatusCode::NOT_FOUND, "not found".to_string()), AppError::Unauthorized => (StatusCode::UNAUTHORIZED, "unauthorized".to_string()), diff --git a/src/lib.rs b/src/lib.rs index 4c2800c..192c8d5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,7 +50,7 @@ use crate::state::AppState; (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 = "Calendar events and attendance. An event's `audience` is its expected-attendee roster, not a visibility wall: everyone sees every event. Aim it at the whole school, one role, a course's enrollment, a class section's (şube) roster, or a hand-built registration list. Rosters resolve live, so role changes, (un)enrollments and class-roster changes move people in and out by themselves. 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` (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. Both rights are re-checked against the caller's live role on every request: `creator` is a historical column no demotion sweeps, so an account that falls below `teacher` keeps neither management nor deletion of a course it made (the course stays reachable to its assigned teachers and to manager+), and the course drops out of their `/courses`, `/exams` and `/homework` catalogs unless they are enrolled in it. A session's `teacher` column carries the same floor: teaching a session grants neither its roll call nor a view of it once the account falls below `teacher`. 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 = "Class sections (ş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). A class may also name a homeroom teacher (sınıf öğretmeni) with `teacher_id` — any teacher+ account, a pure label that grants nothing, cleared on every class it held the moment that account is demoted below `teacher`. 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. Two reads sit outside that bar so a student can learn their own section: `GET /classes/me` (any authenticated role — staff, never members, get an empty page) and `GET /classes/user/{user}` (teacher+, or a parent linked to that student); both hide the class's `creator` (always a manager or admin) from a caller below teacher+, since the office's account names are otherwise unreachable at that level. Naming a homeroom teacher who is demoted while the request runs is a `409`: the assignment is taken back, and a create is rolled back whole. A grade may also carry a **blueprint** (`/classes/blueprints`): the list of courses every section at that grade takes. It reaches sections in both directions — creating or editing one retro-pumps every class already at the grade, and a class created afterwards at a blueprinted grade is stocked from it by `POST /classes` itself, whose `201` therefore answers `{class, skipped, stocked_from}` (`stocked_from` is the grade label of the template that stocked it, `null` when none covers the grade, which is what tells that apart from a template that applied cleanly; a stocking that could not be carried out reads `null` too, and the retry for both is the idempotent `POST /classes/{id}/blueprint`). Pumping is best-effort — a section that cannot take a course (it is at its course ceiling, or the course has no free seat for the whole section) is skipped and returned in `skipped`, while every other section is still stocked, so a blueprint edit can leave a deliberately partial state. The same body carries `matched`, the number of sections the pump actually reached: a grade label is free text matched exactly, so `\"9 \"` and `\"9-A\"` are not `\"9\"`, and `matched: 0` with an empty `skipped` is a saved template that stocked nothing rather than one that stocked everything. `GET /classes?grade=