Send the school's class names with the report payload
Browse files at this commit49f96655eecb9d8998a1b9c6ab4be1785310ba11Parent: 8ce2e1d- feat
- send the school's class names with the report payload
5 changed files +97 -3
- .sqlx/query-a1451a96ea5c3c080d934a4f60d8d4f4f7f3ef907fa211f2952951fa5fac2637.json +38 -0
- src/ai/insight.rs +16 -3
- src/db/insight.rs +31 -0
- src/web/insights.rs +1 -0
- tests/insight_report.rs +11 -0
.sqlx/query-a1451a96ea5c3c080d934a4f60d8d4f4f7f3ef907fa211f2952951fa5fac2637.jsonadded+38 -0
| @@ -0,0 +1,38 @@ | ||
| 1 | +{ | |
| 2 | + "db_name": "PostgreSQL", | |
| 3 | + "query": "SELECT id, name FROM class_group ORDER BY name, id", | |
| 4 | + "describe": { | |
| 5 | + "columns": [ | |
| 6 | + { | |
| 7 | + "ordinal": 0, | |
| 8 | + "name": "id", | |
| 9 | + "type_info": "Uuid", | |
| 10 | + "origin": { | |
| 11 | + "Table": { | |
| 12 | + "table": "class_group", | |
| 13 | + "name": "id" | |
| 14 | + } | |
| 15 | + } | |
| 16 | + }, | |
| 17 | + { | |
| 18 | + "ordinal": 1, | |
| 19 | + "name": "name", | |
| 20 | + "type_info": "Text", | |
| 21 | + "origin": { | |
| 22 | + "Table": { | |
| 23 | + "table": "class_group", | |
| 24 | + "name": "name" | |
| 25 | + } | |
| 26 | + } | |
| 27 | + } | |
| 28 | + ], | |
| 29 | + "parameters": { | |
| 30 | + "Left": [] | |
| 31 | + }, | |
| 32 | + "nullable": [ | |
| 33 | + false, | |
| 34 | + false | |
| 35 | + ] | |
| 36 | + }, | |
| 37 | + "hash": "a1451a96ea5c3c080d934a4f60d8d4f4f7f3ef907fa211f2952951fa5fac2637" | |
| 38 | +} |
src/ai/insight.rsmodified+16 -3
| @@ -220,6 +220,14 @@ pub struct ReportRequest { | ||
| 220 | 220 | /// The school's own identity, so the document prints a display name |
| 221 | 221 | /// rather than a slug. |
| 222 | 222 | pub school: ReportSchool, |
| 223 | + /// Every class (şube) of the school, id and display name: the summaries' | |
| 224 | + /// evidence carries class **ids**, and a document that groups by class | |
| 225 | + /// must print the name a reader recognizes. A sibling key rather than a | |
| 226 | + /// member of [`Self::school`]: it is a lookup for the rows, not part of | |
| 227 | + /// the school's identity. A class a row names but this list does not | |
| 228 | + /// carry (a deleted one) is absent on purpose — the renderer falls back | |
| 229 | + /// to an honest label, never a name invented here. | |
| 230 | + pub classes: Vec<ClassLabel>, | |
| 223 | 231 | /// Every stored summary (with its attention items) in the school. |
| 224 | 232 | pub summaries: Vec<SummaryRow>, |
| 225 | 233 | pub recommendations: Vec<RecommendationRow>, |
| @@ -358,9 +366,9 @@ fn malformed(err: serde_json::Error) -> AiError { | ||
| 358 | 366 | // names exist, what each payload is, and how a refusal reads. |
| 359 | 367 | |
| 360 | 368 | pub use crate::db::insight::{ |
| 361 | - AttentionRow, PendingList, ProfileRow, ProfileWriteRequest, PurgeRequest, RecommendationRow, | |
| 362 | - RecommendationWriteRequest, ReportSchool, RunRow, RunWriteRequest, SchoolDirectory, | |
| 363 | - SegmentConfidences, SegmentLabels, SegmentRow, SegmentWriteRequest, SummaryRow, | |
| 369 | + AttentionRow, ClassLabel, PendingList, ProfileRow, ProfileWriteRequest, PurgeRequest, | |
| 370 | + RecommendationRow, RecommendationWriteRequest, ReportSchool, RunRow, RunWriteRequest, | |
| 371 | + SchoolDirectory, SegmentConfidences, SegmentLabels, SegmentRow, SegmentWriteRequest, SummaryRow, | |
| 364 | 372 | SummaryWriteRequest, TableVerdicts, WriteReceipt, |
| 365 | 373 | }; |
| 366 | 374 | |
| @@ -609,6 +617,10 @@ mod tests { | ||
| 609 | 617 | slug: "demo".into(), |
| 610 | 618 | name: "Demo Okulu".into(), |
| 611 | 619 | }, |
| 620 | + classes: vec![ClassLabel { | |
| 621 | + id: "class-1".into(), | |
| 622 | + name: "8-A".into(), | |
| 623 | + }], | |
| 612 | 624 | summaries: Vec::new(), |
| 613 | 625 | recommendations: Vec::new(), |
| 614 | 626 | profiles: Vec::new(), |
| @@ -621,6 +633,7 @@ mod tests { | ||
| 621 | 633 | "run_day": "2026-09-17", |
| 622 | 634 | "requested_by": "user-9", |
| 623 | 635 | "school": { "id": "school-1", "slug": "demo", "name": "Demo Okulu" }, |
| 636 | + "classes": [{ "id": "class-1", "name": "8-A" }], | |
| 624 | 637 | "summaries": [], |
| 625 | 638 | "recommendations": [], |
| 626 | 639 | "profiles": [], |
src/db/insight.rsmodified+31 -0
| @@ -326,6 +326,16 @@ pub struct ReportSchool { | ||
| 326 | 326 | pub name: String, |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | +/// One class (şube) as a rendered document labels it: the id the summaries' | |
| 330 | +/// own evidence carries, and the display name a reader should see in its | |
| 331 | +/// place. A document that prints the id instead is a machine identifier on | |
| 332 | +/// the most human-facing artifact the product ships. | |
| 333 | +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)] | |
| 334 | +pub struct ClassLabel { | |
| 335 | + pub id: String, | |
| 336 | + pub name: String, | |
| 337 | +} | |
| 338 | + | |
| 329 | 339 | // ---- shared validation ----------------------------------------------------- |
| 330 | 340 | |
| 331 | 341 | /// Refuse a batch past [`MAX_INSIGHT_BATCH_ROWS`] rather than taking it |
| @@ -874,6 +884,27 @@ pub async fn school_identity( | ||
| 874 | 884 | })) |
| 875 | 885 | } |
| 876 | 886 | |
| 887 | +/// Every class (şube) of the school, id and display name, in name order. | |
| 888 | +/// | |
| 889 | +/// The service's summaries carry class ids inside their own evidence objects, | |
| 890 | +/// so a document that groups by class has only those ids to print — and an id | |
| 891 | +/// is not a label. This is the lookup that turns them into names. It is sent | |
| 892 | +/// whole rather than narrowed to the ids the current rows mention: a school's | |
| 893 | +/// class list is tens of rows, and a partial list would make the renderer's | |
| 894 | +/// fallback depend on how complete this read's filters were. | |
| 895 | +pub async fn all_classes(db: &Database) -> Result<Vec<ClassLabel>, AppError> { | |
| 896 | + let rows = sqlx::query!("SELECT id, name FROM class_group ORDER BY name, id") | |
| 897 | + .fetch_all(db) | |
| 898 | + .await?; | |
| 899 | + Ok(rows | |
| 900 | + .into_iter() | |
| 901 | + .map(|row| ClassLabel { | |
| 902 | + id: row.id.to_string(), | |
| 903 | + name: row.name, | |
| 904 | + }) | |
| 905 | + .collect()) | |
| 906 | +} | |
| 907 | + | |
| 877 | 908 | // ---- the school-wide reads the report payload carries ----------------------- |
| 878 | 909 | // |
| 879 | 910 | // Every read above is per-student or per-audience, because that is every |
src/web/insights.rsmodified+1 -0
| @@ -413,6 +413,7 @@ async fn generate_report( | ||
| 413 | 413 | run_day: run_day.clone(), |
| 414 | 414 | requested_by: user.get_id().key(), |
| 415 | 415 | school, |
| 416 | + classes: db::insight::all_classes(&st.db).await?, | |
| 416 | 417 | summaries: db::insight::all_summaries(&st.db).await?, |
| 417 | 418 | recommendations: db::insight::all_recommendations(&st.db).await?, |
| 418 | 419 | profiles: db::insight::all_profiles(&st.db).await?, |
tests/insight_report.rsmodified+11 -0
| @@ -429,6 +429,7 @@ async fn a_generated_report_is_stored_and_served_to_its_manager() { | ||
| 429 | 429 | let manager_id = common::me_id(&app, &manager).await; |
| 430 | 430 | let student = common::login(&app, "ali").await; |
| 431 | 431 | let student_id = common::me_id(&app, &student).await; |
| 432 | + let class_id = common::create_class(&app, &manager, "8-A", json!({})).await; | |
| 432 | 433 | seed_report_rows(&db, "2026-09-16", &student_id, &manager_id).await; |
| 433 | 434 | |
| 434 | 435 | let res = generate(&app, &manager, "2026-09-16").await; |
| @@ -463,6 +464,16 @@ async fn a_generated_report_is_stored_and_served_to_its_manager() { | ||
| 463 | 464 | .is_some_and(|name| !name.is_empty()), |
| 464 | 465 | "the school's display name travels" |
| 465 | 466 | ); |
| 467 | + // The class (şube) lookup: the summaries' evidence carries class ids, and | |
| 468 | + // the document must print the name a reader recognizes. | |
| 469 | + let classes = request.payload["classes"] | |
| 470 | + .as_array() | |
| 471 | + .expect("classes is a list"); | |
| 472 | + let seeded = classes | |
| 473 | + .iter() | |
| 474 | + .find(|row| row["id"] == class_id.as_str()) | |
| 475 | + .expect("the school's own class is in the payload"); | |
| 476 | + assert_eq!(seeded["name"], "8-A"); | |
| 466 | 477 | let summaries = request.payload["summaries"] |
| 467 | 478 | .as_array() |
| 468 | 479 | .expect("summaries is a list"); |