Zero clippy/rustc warnings project-wide
Browse files at this commit932f8610f3c1c8a812b2183c09afc2bdc6cea81cParent: 17365d7- style
- zero clippy/rustc warnings project-wide
107 changed files +352 -484
- src/constant.rs +0 -4
- src/database.rs +4 -9
- src/db/answer_image.rs +1 -1
- src/db/appointment.rs +0 -4
- src/db/attendance.rs +1 -1
- src/db/badge.rs +0 -7
- src/db/bank_question.rs +10 -11
- src/db/board.rs +1 -1
- src/db/builder.rs +2 -4
- src/db/chatbot_message.rs +2 -2
- src/db/chatbot_thread.rs +1 -1
- src/db/class_blueprint.rs +1 -1
- src/db/class_group.rs +27 -27
- src/db/class_pump.rs +1 -15
- src/db/course.rs +28 -28
- src/db/course_note.rs +1 -1
- src/db/course_session.rs +1 -1
- src/db/enrollment.rs +1 -1
- src/db/event.rs +5 -5
- src/db/exam.rs +5 -5
- src/db/exam_answer.rs +1 -1
- src/db/exam_attempt.rs +2 -3
- src/db/exam_question.rs +18 -18
- src/db/exam_result.rs +2 -2
- src/db/field_update.rs +29 -79
- src/db/homework.rs +12 -12
- src/db/homework_submission.rs +1 -2
- src/db/meal_booking.rs +6 -6
- src/db/note.rs +1 -1
- src/db/payment_ledger.rs +2 -2
- src/db/pomodoro.rs +1 -1
- src/db/pool_question.rs +5 -6
- src/db/profile.rs +0 -7
- src/db/question_image.rs +1 -1
- src/db/session.rs +2 -2
- src/db/session_attendance.rs +1 -1
- src/db/settings.rs +3 -3
- src/db/solution.rs +2 -3
- src/db/subject.rs +1 -1
- src/db/term.rs +1 -1
- src/domain/answer_image.rs +2 -2
- src/domain/attendance.rs +1 -1
- src/domain/board.rs +1 -1
- src/domain/builder.rs +0 -2
- src/domain/class_course.rs +0 -6
- src/domain/class_member.rs +1 -7
- src/domain/dietary_profile.rs +1 -1
- src/domain/enrollment.rs +1 -1
- src/domain/exam_answer.rs +2 -2
- src/domain/exam_attempt.rs +1 -1
- src/domain/exam_result.rs +4 -4
- src/domain/fee_plan_assignment.rs +1 -1
- src/domain/homework.rs +3 -3
- src/domain/meal_booking.rs +1 -1
- src/domain/meal_ledger.rs +5 -5
- src/domain/message.rs +3 -3
- src/domain/note_file.rs +1 -1
- src/domain/payment_ledger.rs +1 -1
- src/domain/pool_question.rs +1 -1
- src/domain/preferences.rs +3 -3
- src/domain/role.rs +1 -1
- src/domain/session.rs +0 -1
- src/domain/settings.rs +1 -9
- src/domain/solution.rs +2 -2
- src/domain/text_fold.rs +2 -2
- src/service/appointment.rs +6 -6
- src/service/appointment_slot.rs +4 -4
- src/service/bank_question.rs +1 -1
- src/service/board.rs +3 -3
- src/service/class_blueprint.rs +3 -3
- src/service/class_course.rs +1 -1
- src/service/class_member.rs +1 -1
- src/service/exam_attempt.rs +3 -6
- src/service/fee_plan_assignment.rs +3 -3
- src/service/meal_booking.rs +4 -4
- src/service/meal_ledger.rs +2 -2
- src/service/payment_ledger.rs +5 -5
- src/service/subject.rs +2 -2
- src/service/term.rs +1 -1
- src/service/user.rs +5 -5
- src/tenant.rs +1 -3
- src/web/appointments.rs +2 -2
- src/web/bank_questions.rs +6 -6
- src/web/board_ws.rs +3 -3
- src/web/boards.rs +2 -2
- src/web/chatbot.rs +1 -1
- src/web/classes.rs +11 -11
- src/web/courses.rs +4 -4
- src/web/dto.rs +1 -1
- src/web/events.rs +7 -7
- src/web/exam_ws.rs +1 -2
- src/web/exams/attempts.rs +2 -2
- src/web/exams/mod.rs +2 -2
- src/web/exams/questions.rs +4 -4
- src/web/exams/review.rs +2 -2
- src/web/meals.rs +13 -13
- src/web/messages.rs +2 -2
- src/web/mod.rs +3 -3
- src/web/payments.rs +5 -5
- src/web/questions.rs +5 -5
- src/web/sessions.rs +6 -7
- src/web/users.rs +1 -1
- tests/integration.rs +1 -1
- tests/name_refs.rs +0 -2
- tests/regress_homework_orphans.rs +0 -1
- tests/regress_role_sweep.rs +1 -1
- tests/regress_roles.rs +0 -1
src/constant.rsmodified+0 -4
| @@ -785,10 +785,6 @@ pub const BANK_VISIBILITY_SCHOOL: &str = "school"; | |||
| 785 | 785 | ||
| 786 | // --- fixed keys and literals ------------------------------------------- | 786 | // --- fixed keys and literals ------------------------------------------- |
| 787 | 787 | ||
| 788 | -/// The settings singleton's fixed key: one school per deployment, one settings | ||
| 789 | -/// row. | ||
| 790 | -pub const SETTINGS_KEY: &str = "school"; | ||
| 791 | - | ||
| 792 | /// A fixed password whose hash is the login decoy (see | 788 | /// A fixed password whose hash is the login decoy (see |
| 793 | /// [`crate::domain::user::PasswordHash::verify_decoy`]). Not a secret — it | 789 | /// [`crate::domain::user::PasswordHash::verify_decoy`]). Not a secret — it |
| 794 | /// never matches a real account. | 790 | /// never matches a real account. |
src/database.rsmodified+4 -9
| @@ -255,11 +255,9 @@ async fn ensure_template( | |||
| 255 | ))) | 255 | ))) |
| 256 | .execute(control) | 256 | .execute(control) |
| 257 | .await | 257 | .await |
| 258 | - { | 258 | + && !is_duplicate_database(&err) { |
| 259 | - if !is_duplicate_database(&err) { | ||
| 260 | return Err(err.into()); | 259 | return Err(err.into()); |
| 261 | } | 260 | } |
| 262 | - } | ||
| 263 | // One migrator connection, made and closed: the template is never served. | 261 | // One migrator connection, made and closed: the template is never served. |
| 264 | let pool = pool_options(1) | 262 | let pool = pool_options(1) |
| 265 | .connect_with(base.clone().database(name)) | 263 | .connect_with(base.clone().database(name)) |
| @@ -685,19 +683,16 @@ async fn ensure_test_template(maintenance: &PgPool, base: &PgConnectOptions) -> | |||
| 685 | .await | 683 | .await |
| 686 | .map(|(count,)| count > 0) | 684 | .map(|(count,)| count > 0) |
| 687 | .unwrap_or_else(|err| panic!("probe for the school template {name}: {err}")); | 685 | .unwrap_or_else(|err| panic!("probe for the school template {name}: {err}")); |
| 688 | - if !exists { | 686 | + if !exists |
| 689 | - if let Err(err) = sqlx::query(sqlx::AssertSqlSafe(create_database_sql( | 687 | + && let Err(err) = sqlx::query(sqlx::AssertSqlSafe(create_database_sql( |
| 690 | "CREATE DATABASE", | 688 | "CREATE DATABASE", |
| 691 | &name, | 689 | &name, |
| 692 | ))) | 690 | ))) |
| 693 | .execute(&mut *session) | 691 | .execute(&mut *session) |
| 694 | .await | 692 | .await |
| 695 | - { | 693 | + && !is_duplicate_database(&err) { |
| 696 | - if !is_duplicate_database(&err) { | ||
| 697 | panic!("create the school template {name}: {err}"); | 694 | panic!("create the school template {name}: {err}"); |
| 698 | } | 695 | } |
| 699 | - } | ||
| 700 | - } | ||
| 701 | let pool = pool_options(1) | 696 | let pool = pool_options(1) |
| 702 | .connect_with(base.clone().database(&name)) | 697 | .connect_with(base.clone().database(&name)) |
| 703 | .await | 698 | .await |
src/db/answer_image.rsmodified+1 -1
| @@ -271,7 +271,7 @@ mod tests { | |||
| 271 | crate::db::exam_question::create( | 271 | crate::db::exam_question::create( |
| 272 | db, | 272 | db, |
| 273 | exam, | 273 | exam, |
| 274 | - subject.get_id().clone(), | 274 | + *subject.get_id(), |
| 275 | crate::domain::exam_question::QuestionText::try_new("3 + 3?").unwrap(), | 275 | crate::domain::exam_question::QuestionText::try_new("3 + 3?").unwrap(), |
| 276 | crate::domain::exam_question::QuestionPoints::try_new(1).unwrap(), | 276 | crate::domain::exam_question::QuestionPoints::try_new(1).unwrap(), |
| 277 | spec, | 277 | spec, |
src/db/appointment.rsmodified+0 -4
| @@ -16,10 +16,6 @@ use crate::domain::user::UserId; | |||
| 16 | use crate::error::AppError; | 16 | use crate::error::AppError; |
| 17 | use sqlx::{query, query_as, PgConnection, Postgres}; | 17 | use sqlx::{query, query_as, PgConnection, Postgres}; |
| 18 | 18 | ||
| 19 | -/// The appointment row's columns, in [`Appointment`]'s field order. | ||
| 20 | -const COLS: &str = "id, slot, requester, status, reason, proposed_starts_at, proposed_ends_at, \ | ||
| 21 | - proposed_by, decided_by, cancelled_by, cancel_reason, reject_reason, created_at"; | ||
| 22 | - | ||
| 23 | /// Is `[starts_at, ends_at)` already taken for either party? Both sides are | 19 | /// Is `[starts_at, ends_at)` already taken for either party? Both sides are |
| 24 | /// checked: a teacher can't be in two meetings at once, and neither can a | 20 | /// checked: a teacher can't be in two meetings at once, and neither can a |
| 25 | /// requester (a parent with two children's teachers, say). | 21 | /// requester (a parent with two children's teachers, say). |
src/db/attendance.rsmodified+1 -1
| @@ -194,7 +194,7 @@ mod tests { | |||
| 194 | }) | 194 | }) |
| 195 | }; | 195 | }; |
| 196 | let marked = { | 196 | let marked = { |
| 197 | - let (db, id, marker, gate) = (db.clone(), id.clone(), marker.clone(), gate); | 197 | + let (db, id, marker, gate) = (db.clone(), id.clone(), marker, gate); |
| 198 | let student = a_person(&db, "student").await; | 198 | let student = a_person(&db, "student").await; |
| 199 | let status = AttendanceStatus::try_new("present", &allowed).unwrap(); | 199 | let status = AttendanceStatus::try_new("present", &allowed).unwrap(); |
| 200 | tokio::spawn(async move { | 200 | tokio::spawn(async move { |
src/db/badge.rsmodified+0 -7
| @@ -152,13 +152,6 @@ mod tests { | |||
| 152 | count | 152 | count |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | - fn stats(homework_submitted: i64) -> BadgeStats { | ||
| 156 | - BadgeStats { | ||
| 157 | - homework_submitted, | ||
| 158 | - ..Default::default() | ||
| 159 | - } | ||
| 160 | - } | ||
| 161 | - | ||
| 162 | #[tokio::test] | 155 | #[tokio::test] |
| 163 | async fn load_defaults_every_counter_to_zero() { | 156 | async fn load_defaults_every_counter_to_zero() { |
| 164 | let (db, _leases) = init_test_db().await; | 157 | let (db, _leases) = init_test_db().await; |
src/db/bank_question.rsmodified+10 -11
| @@ -410,7 +410,7 @@ mod tests { | |||
| 410 | /// A real subject row: a template's subject reference is a foreign key | 410 | /// A real subject row: a template's subject reference is a foreign key |
| 411 | /// too (and the subject needs a real course under it). | 411 | /// too (and the subject needs a real course under it). |
| 412 | async fn a_subject(db: &Database) -> SubjectId { | 412 | async fn a_subject(db: &Database) -> SubjectId { |
| 413 | - crate::db::subject::create( | 413 | + *crate::db::subject::create( |
| 414 | db, | 414 | db, |
| 415 | &crate::db::course::a_test_course(db).await, | 415 | &crate::db::course::a_test_course(db).await, |
| 416 | crate::domain::subject::SubjectName::try_new("topic").unwrap(), | 416 | crate::domain::subject::SubjectName::try_new("topic").unwrap(), |
| @@ -419,7 +419,6 @@ mod tests { | |||
| 419 | .await | 419 | .await |
| 420 | .unwrap() | 420 | .unwrap() |
| 421 | .get_id() | 421 | .get_id() |
| 422 | - .clone() | ||
| 423 | } | 422 | } |
| 424 | 423 | ||
| 425 | fn spec() -> QuestionSpec { | 424 | fn spec() -> QuestionSpec { |
| @@ -477,7 +476,7 @@ mod tests { | |||
| 477 | let other = a_person(&db, "other").await; | 476 | let other = a_person(&db, "other").await; |
| 478 | let private = create( | 477 | let private = create( |
| 479 | &db, | 478 | &db, |
| 480 | - owner.clone(), | 479 | + owner, |
| 481 | a_subject(&db).await, | 480 | a_subject(&db).await, |
| 482 | QuestionText::try_new("secret").unwrap(), | 481 | QuestionText::try_new("secret").unwrap(), |
| 483 | QuestionPoints::try_new(1).unwrap(), | 482 | QuestionPoints::try_new(1).unwrap(), |
| @@ -487,7 +486,7 @@ mod tests { | |||
| 487 | .unwrap(); | 486 | .unwrap(); |
| 488 | let published = create( | 487 | let published = create( |
| 489 | &db, | 488 | &db, |
| 490 | - owner.clone(), | 489 | + owner, |
| 491 | a_subject(&db).await, | 490 | a_subject(&db).await, |
| 492 | QuestionText::try_new("shared").unwrap(), | 491 | QuestionText::try_new("shared").unwrap(), |
| 493 | QuestionPoints::try_new(1).unwrap(), | 492 | QuestionPoints::try_new(1).unwrap(), |
| @@ -590,14 +589,14 @@ mod tests { | |||
| 590 | let (db, _leases) = crate::database::init_test_db().await; | 589 | let (db, _leases) = crate::database::init_test_db().await; |
| 591 | let owner = a_person(&db, "owner").await; | 590 | let owner = a_person(&db, "owner").await; |
| 592 | let other = a_person(&db, "other").await; | 591 | let other = a_person(&db, "other").await; |
| 593 | - async fn mine<'a>( | 592 | + async fn mine( |
| 594 | db: &Database, | 593 | db: &Database, |
| 595 | owner: &UserId, | 594 | owner: &UserId, |
| 596 | text: &str, | 595 | text: &str, |
| 597 | ) -> Result<BankQuestion, AppError> { | 596 | ) -> Result<BankQuestion, AppError> { |
| 598 | create( | 597 | create( |
| 599 | db, | 598 | db, |
| 600 | - owner.clone(), | 599 | + *owner, |
| 601 | a_subject(db).await, | 600 | a_subject(db).await, |
| 602 | QuestionText::try_new(text).unwrap(), | 601 | QuestionText::try_new(text).unwrap(), |
| 603 | QuestionPoints::try_new(1).unwrap(), | 602 | QuestionPoints::try_new(1).unwrap(), |
| @@ -671,14 +670,14 @@ mod tests { | |||
| 671 | // compiler now checks the way the old constant asserted. | 670 | // compiler now checks the way the old constant asserted. |
| 672 | let (db, _leases) = crate::database::init_test_db().await; | 671 | let (db, _leases) = crate::database::init_test_db().await; |
| 673 | let owner = a_person(&db, "owner").await; | 672 | let owner = a_person(&db, "owner").await; |
| 674 | - async fn template<'a>( | 673 | + async fn template( |
| 675 | db: &Database, | 674 | db: &Database, |
| 676 | owner: &UserId, | 675 | owner: &UserId, |
| 677 | text: &str, | 676 | text: &str, |
| 678 | ) -> Result<BankQuestion, AppError> { | 677 | ) -> Result<BankQuestion, AppError> { |
| 679 | create( | 678 | create( |
| 680 | db, | 679 | db, |
| 681 | - owner.clone(), | 680 | + *owner, |
| 682 | a_subject(db).await, | 681 | a_subject(db).await, |
| 683 | QuestionText::try_new(text).unwrap(), | 682 | QuestionText::try_new(text).unwrap(), |
| 684 | QuestionPoints::try_new(1).unwrap(), | 683 | QuestionPoints::try_new(1).unwrap(), |
| @@ -714,7 +713,7 @@ mod tests { | |||
| 714 | crate::db::exam_question::create_from_bank( | 713 | crate::db::exam_question::create_from_bank( |
| 715 | db, | 714 | db, |
| 716 | exam, | 715 | exam, |
| 717 | - subject.clone(), | 716 | + *subject, |
| 718 | source.get_text().clone(), | 717 | source.get_text().clone(), |
| 719 | source.get_points(), | 718 | source.get_points(), |
| 720 | source.spec(), | 719 | source.spec(), |
| @@ -731,7 +730,7 @@ mod tests { | |||
| 731 | crate::db::exam_question::create( | 730 | crate::db::exam_question::create( |
| 732 | &db, | 731 | &db, |
| 733 | &exam, | 732 | &exam, |
| 734 | - subject.get_id().clone(), | 733 | + *subject.get_id(), |
| 735 | QuestionText::try_new("mine").unwrap(), | 734 | QuestionText::try_new("mine").unwrap(), |
| 736 | QuestionPoints::try_new(1).unwrap(), | 735 | QuestionPoints::try_new(1).unwrap(), |
| 737 | spec(), | 736 | spec(), |
| @@ -789,7 +788,7 @@ mod tests { | |||
| 789 | for i in 0..5 { | 788 | for i in 0..5 { |
| 790 | create( | 789 | create( |
| 791 | &db, | 790 | &db, |
| 792 | - owner.clone(), | 791 | + owner, |
| 793 | a_subject(&db).await, | 792 | a_subject(&db).await, |
| 794 | QuestionText::try_new(&format!("question {i}")).unwrap(), | 793 | QuestionText::try_new(&format!("question {i}")).unwrap(), |
| 795 | QuestionPoints::try_new(1).unwrap(), | 794 | QuestionPoints::try_new(1).unwrap(), |
src/db/board.rsmodified+1 -1
| @@ -18,7 +18,7 @@ pub async fn create( | |||
| 18 | ) -> Result<Board, AppError> { | 18 | ) -> Result<Board, AppError> { |
| 19 | let board = Board { | 19 | let board = Board { |
| 20 | id: BoardId::generate(), | 20 | id: BoardId::generate(), |
| 21 | - creator: creator.clone(), | 21 | + creator: *creator, |
| 22 | title, | 22 | title, |
| 23 | participants: checked_participants(participants)?, | 23 | participants: checked_participants(participants)?, |
| 24 | locked: false, | 24 | locked: false, |
src/db/builder.rsmodified+2 -4
| @@ -68,10 +68,9 @@ pub async fn create_session( | |||
| 68 | BuilderSession, | 68 | BuilderSession, |
| 69 | r#"INSERT INTO builder_session (id, builder, token, created_at, expires_at) | 69 | r#"INSERT INTO builder_session (id, builder, token, created_at, expires_at) |
| 70 | VALUES ($1, $2, $3, $4, $5) | 70 | VALUES ($1, $2, $3, $4, $5) |
| 71 | - RETURNING id, | 71 | + RETURNING |
| 72 | builder AS "builder: BuilderId", | 72 | builder AS "builder: BuilderId", |
| 73 | token AS "token: SessionToken", | 73 | token AS "token: SessionToken", |
| 74 | - created_at AS "created_at: Timestamp", | ||
| 75 | expires_at AS "expires_at: Timestamp""#, | 74 | expires_at AS "expires_at: Timestamp""#, |
| 76 | crate::domain::monotonic_id::next_uuid(), | 75 | crate::domain::monotonic_id::next_uuid(), |
| 77 | builder.uuid(), | 76 | builder.uuid(), |
| @@ -87,10 +86,9 @@ pub async fn create_session( | |||
| 87 | pub async fn find_by_token(db: &Database, token: &str) -> Result<Option<BuilderSession>, AppError> { | 86 | pub async fn find_by_token(db: &Database, token: &str) -> Result<Option<BuilderSession>, AppError> { |
| 88 | let session = sqlx::query_as!( | 87 | let session = sqlx::query_as!( |
| 89 | BuilderSession, | 88 | BuilderSession, |
| 90 | - r#"SELECT id, | 89 | + r#"SELECT |
| 91 | builder AS "builder: BuilderId", | 90 | builder AS "builder: BuilderId", |
| 92 | token AS "token: SessionToken", | 91 | token AS "token: SessionToken", |
| 93 | - created_at AS "created_at: Timestamp", | ||
| 94 | expires_at AS "expires_at: Timestamp" | 92 | expires_at AS "expires_at: Timestamp" |
| 95 | FROM builder_session WHERE token = $1"#, | 93 | FROM builder_session WHERE token = $1"#, |
| 96 | token | 94 | token |
src/db/chatbot_message.rsmodified+2 -2
| @@ -84,7 +84,7 @@ pub async fn append_user( | |||
| 84 | ChatbotMessage { | 84 | ChatbotMessage { |
| 85 | id: ChatbotMessageId::generate(), | 85 | id: ChatbotMessageId::generate(), |
| 86 | thread_id: thread.clone(), | 86 | thread_id: thread.clone(), |
| 87 | - user_id: user.clone(), | 87 | + user_id: *user, |
| 88 | role: crate::domain::chatbot_message::MessageRole::User, | 88 | role: crate::domain::chatbot_message::MessageRole::User, |
| 89 | content, | 89 | content, |
| 90 | status: MessageStatus::Complete, | 90 | status: MessageStatus::Complete, |
| @@ -109,7 +109,7 @@ pub async fn append_pending_assistant( | |||
| 109 | ChatbotMessage { | 109 | ChatbotMessage { |
| 110 | id: ChatbotMessageId::generate(), | 110 | id: ChatbotMessageId::generate(), |
| 111 | thread_id: thread.clone(), | 111 | thread_id: thread.clone(), |
| 112 | - user_id: user.clone(), | 112 | + user_id: *user, |
| 113 | role: crate::domain::chatbot_message::MessageRole::Assistant, | 113 | role: crate::domain::chatbot_message::MessageRole::Assistant, |
| 114 | content: ChatContent::empty(), | 114 | content: ChatContent::empty(), |
| 115 | status: MessageStatus::Pending, | 115 | status: MessageStatus::Pending, |
src/db/chatbot_thread.rsmodified+1 -1
| @@ -409,7 +409,7 @@ mod tests { | |||
| 409 | }) | 409 | }) |
| 410 | }; | 410 | }; |
| 411 | let turn = { | 411 | let turn = { |
| 412 | - let (id, db, user, gate) = (id.clone(), db.clone(), user.clone(), gate); | 412 | + let (id, db, user, gate) = (id.clone(), db.clone(), user, gate); |
| 413 | tokio::spawn(async move { | 413 | tokio::spawn(async move { |
| 414 | gate.wait().await; | 414 | gate.wait().await; |
| 415 | chatbot_message::append_user( | 415 | chatbot_message::append_user( |
src/db/class_blueprint.rsmodified+1 -1
| @@ -80,7 +80,7 @@ pub async fn create( | |||
| 80 | id: ClassBlueprintId::for_grade(&grade), | 80 | id: ClassBlueprintId::for_grade(&grade), |
| 81 | grade: grade.clone(), | 81 | grade: grade.clone(), |
| 82 | courses: courses.clone(), | 82 | courses: courses.clone(), |
| 83 | - creator: creator.clone(), | 83 | + creator: *creator, |
| 84 | }; | 84 | }; |
| 85 | let creator = *creator; | 85 | let creator = *creator; |
| 86 | tx_with_retry(db, false, async move |tx| { | 86 | tx_with_retry(db, false, async move |tx| { |
src/db/class_group.rsmodified+27 -27
| @@ -5,7 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | use crate::constant::{CLASS_GROUP_TABLE, TERM_CLASS_COUNT_FIELD}; | 6 | use crate::constant::{CLASS_GROUP_TABLE, TERM_CLASS_COUNT_FIELD}; |
| 7 | use crate::database::{Database, tx_with_retry}; | 7 | use crate::database::{Database, tx_with_retry}; |
| 8 | -use crate::db::field_update::FieldUpdate; | 8 | +use crate::db::field_update::{FieldUpdate, Refcount}; |
| 9 | use crate::db::page::PagedList; | 9 | use crate::db::page::PagedList; |
| 10 | use crate::domain::class_group::{ClassGrade, ClassGroup, ClassGroupId, ClassName}; | 10 | use crate::domain::class_group::{ClassGrade, ClassGroup, ClassGroupId, ClassName}; |
| 11 | use crate::domain::term::{self, TermId}; | 11 | use crate::domain::term::{self, TermId}; |
| @@ -168,15 +168,15 @@ pub async fn update( | |||
| 168 | "teacher", | 168 | "teacher", |
| 169 | teacher.map(|teacher| teacher.map(|teacher| teacher.uuid())), | 169 | teacher.map(|teacher| teacher.map(|teacher| teacher.uuid())), |
| 170 | ) | 170 | ) |
| 171 | - .refcount( | 171 | + .refcount(Refcount { |
| 172 | - "term", | 172 | + counter_table: "term", |
| 173 | - TERM_CLASS_COUNT_FIELD, | 173 | + counter_field: TERM_CLASS_COUNT_FIELD, |
| 174 | - "term", | 174 | + link: "term", |
| 175 | expected, | 175 | expected, |
| 176 | - claim.map(|term| term.uuid()), | 176 | + claim: claim.map(|term| term.uuid()), |
| 177 | - release.map(|term| term.uuid()), | 177 | + release: release.map(|term| term.uuid()), |
| 178 | - term::gone_error(), | 178 | + refused: term::gone_error(), |
| 179 | - ) | 179 | + }) |
| 180 | .run::<ClassGroup>(db) | 180 | .run::<ClassGroup>(db) |
| 181 | .await | 181 | .await |
| 182 | } | 182 | } |
| @@ -416,8 +416,8 @@ mod tests { | |||
| 416 | 416 | ||
| 417 | let bare = class_of(None, &db).await; | 417 | let bare = class_of(None, &db).await; |
| 418 | assert_eq!(teacher_of(bare.get_id(), &db).await, None); | 418 | assert_eq!(teacher_of(bare.get_id(), &db).await, None); |
| 419 | - let held = class_of(Some(ada.clone()), &db).await; | 419 | + let held = class_of(Some(ada), &db).await; |
| 420 | - assert_eq!(teacher_of(held.get_id(), &db).await, Some(ada.clone())); | 420 | + assert_eq!(teacher_of(held.get_id(), &db).await, Some(ada)); |
| 421 | 421 | ||
| 422 | // A name-only PATCH must not re-state the teacher out of its snapshot. | 422 | // A name-only PATCH must not re-state the teacher out of its snapshot. |
| 423 | let renamed = update( | 423 | let renamed = update( |
| @@ -433,7 +433,7 @@ mod tests { | |||
| 433 | assert_eq!(renamed.get_name().as_str(), "9-B"); | 433 | assert_eq!(renamed.get_name().as_str(), "9-B"); |
| 434 | assert_eq!(teacher_of(renamed.get_id(), &db).await, Some(ada)); | 434 | assert_eq!(teacher_of(renamed.get_id(), &db).await, Some(ada)); |
| 435 | 435 | ||
| 436 | - let moved = update(&db, renamed, None, None, None, Some(Some(boole.clone()))) | 436 | + let moved = update(&db, renamed, None, None, None, Some(Some(boole))) |
| 437 | .await | 437 | .await |
| 438 | .unwrap(); | 438 | .unwrap(); |
| 439 | assert_eq!(teacher_of(moved.get_id(), &db).await, Some(boole)); | 439 | assert_eq!(teacher_of(moved.get_id(), &db).await, Some(boole)); |
| @@ -473,9 +473,9 @@ mod tests { | |||
| 473 | let (db, _leases) = crate::database::init_test_db().await; | 473 | let (db, _leases) = crate::database::init_test_db().await; |
| 474 | let ada = a_named_user(&db, "ada").await; | 474 | let ada = a_named_user(&db, "ada").await; |
| 475 | let boole = a_named_user(&db, "boole").await; | 475 | let boole = a_named_user(&db, "boole").await; |
| 476 | - let first = class_of(Some(ada.clone()), &db).await; | 476 | + let first = class_of(Some(ada), &db).await; |
| 477 | - let second = class_of(Some(ada.clone()), &db).await; | 477 | + let second = class_of(Some(ada), &db).await; |
| 478 | - let other = class_of(Some(boole.clone()), &db).await; | 478 | + let other = class_of(Some(boole), &db).await; |
| 479 | let none = class_of(None, &db).await; | 479 | let none = class_of(None, &db).await; |
| 480 | 480 | ||
| 481 | unassign_everywhere(&db, &ada).await.unwrap(); | 481 | unassign_everywhere(&db, &ada).await.unwrap(); |
| @@ -503,8 +503,8 @@ mod tests { | |||
| 503 | let (db, _leases) = crate::database::init_test_db().await; | 503 | let (db, _leases) = crate::database::init_test_db().await; |
| 504 | let term = a_term(&db).await; | 504 | let term = a_term(&db).await; |
| 505 | 505 | ||
| 506 | - let linked = class_on(Some(term.get_id().clone()), &db).await; | 506 | + let linked = class_on(Some(*term.get_id()), &db).await; |
| 507 | - let patched = class_on(Some(term.get_id().clone()), &db).await; | 507 | + let patched = class_on(Some(*term.get_id()), &db).await; |
| 508 | assert_eq!( | 508 | assert_eq!( |
| 509 | one_i64(&db, "SELECT COALESCE(class_count, 0) FROM term".to_string()).await, | 509 | one_i64(&db, "SELECT COALESCE(class_count, 0) FROM term".to_string()).await, |
| 510 | 2, | 510 | 2, |
| @@ -543,7 +543,7 @@ mod tests { | |||
| 543 | for field in ["class_member_count", "class_course_count"] { | 543 | for field in ["class_member_count", "class_course_count"] { |
| 544 | let (db, _leases) = crate::database::init_test_db().await; | 544 | let (db, _leases) = crate::database::init_test_db().await; |
| 545 | let term = a_term(&db).await; | 545 | let term = a_term(&db).await; |
| 546 | - let class = class_on(Some(term.get_id().clone()), &db).await; | 546 | + let class = class_on(Some(*term.get_id()), &db).await; |
| 547 | sqlx::query(sqlx::AssertSqlSafe(format!( | 547 | sqlx::query(sqlx::AssertSqlSafe(format!( |
| 548 | "UPDATE class_group SET {field} = 1 WHERE id = $1" | 548 | "UPDATE class_group SET {field} = 1 WHERE id = $1" |
| 549 | ))) | 549 | ))) |
| @@ -594,7 +594,7 @@ mod tests { | |||
| 594 | async fn a_refused_create_writes_neither_row_nor_count() { | 594 | async fn a_refused_create_writes_neither_row_nor_count() { |
| 595 | let (db, _leases) = crate::database::init_test_db().await; | 595 | let (db, _leases) = crate::database::init_test_db().await; |
| 596 | let term = a_term(&db).await; | 596 | let term = a_term(&db).await; |
| 597 | - let id = term.get_id().clone(); | 597 | + let id = *term.get_id(); |
| 598 | assert!(crate::db::term::delete(&db, term).await.unwrap()); | 598 | assert!(crate::db::term::delete(&db, term).await.unwrap()); |
| 599 | 599 | ||
| 600 | let error = create( | 600 | let error = create( |
| @@ -637,9 +637,9 @@ mod tests { | |||
| 637 | crate::db::term::create(&db, TermName::try_new("2028").unwrap(), at(100), at(200)) | 637 | crate::db::term::create(&db, TermName::try_new("2028").unwrap(), at(100), at(200)) |
| 638 | .await | 638 | .await |
| 639 | .unwrap(); | 639 | .unwrap(); |
| 640 | - let dead_id = dead.get_id().clone(); | 640 | + let dead_id = *dead.get_id(); |
| 641 | assert!(crate::db::term::delete(&db, dead).await.unwrap()); | 641 | assert!(crate::db::term::delete(&db, dead).await.unwrap()); |
| 642 | - let class = class_on(Some(from.get_id().clone()), &db).await; | 642 | + let class = class_on(Some(*from.get_id()), &db).await; |
| 643 | 643 | ||
| 644 | let error = update( | 644 | let error = update( |
| 645 | &db, | 645 | &db, |
| @@ -666,7 +666,7 @@ mod tests { | |||
| 666 | class, | 666 | class, |
| 667 | None, | 667 | None, |
| 668 | None, | 668 | None, |
| 669 | - Some(Some(to.get_id().clone())), | 669 | + Some(Some(*to.get_id())), |
| 670 | None, | 670 | None, |
| 671 | ) | 671 | ) |
| 672 | .await | 672 | .await |
| @@ -701,14 +701,14 @@ mod tests { | |||
| 701 | crate::db::term::create(&db, TermName::try_new("2028").unwrap(), at(100), at(200)) | 701 | crate::db::term::create(&db, TermName::try_new("2028").unwrap(), at(100), at(200)) |
| 702 | .await | 702 | .await |
| 703 | .unwrap(); | 703 | .unwrap(); |
| 704 | - let class = class_on(Some(from.get_id().clone()), &db).await; | 704 | + let class = class_on(Some(*from.get_id()), &db).await; |
| 705 | let stale = class.clone(); | 705 | let stale = class.clone(); |
| 706 | update( | 706 | update( |
| 707 | &db, | 707 | &db, |
| 708 | class, | 708 | class, |
| 709 | None, | 709 | None, |
| 710 | None, | 710 | None, |
| 711 | - Some(Some(to.get_id().clone())), | 711 | + Some(Some(*to.get_id())), |
| 712 | None, | 712 | None, |
| 713 | ) | 713 | ) |
| 714 | .await | 714 | .await |
| @@ -721,7 +721,7 @@ mod tests { | |||
| 721 | stale.clone(), | 721 | stale.clone(), |
| 722 | None, | 722 | None, |
| 723 | None, | 723 | None, |
| 724 | - Some(Some(other.get_id().clone())), | 724 | + Some(Some(*other.get_id())), |
| 725 | None, | 725 | None, |
| 726 | ) | 726 | ) |
| 727 | .await | 727 | .await |
| @@ -733,7 +733,7 @@ mod tests { | |||
| 733 | stale.clone(), | 733 | stale.clone(), |
| 734 | None, | 734 | None, |
| 735 | None, | 735 | None, |
| 736 | - Some(Some(from.get_id().clone())), | 736 | + Some(Some(*from.get_id())), |
| 737 | None, | 737 | None, |
| 738 | ) | 738 | ) |
| 739 | .await | 739 | .await |
| @@ -752,7 +752,7 @@ mod tests { | |||
| 752 | stored, | 752 | stored, |
| 753 | None, | 753 | None, |
| 754 | None, | 754 | None, |
| 755 | - Some(Some(to.get_id().clone())), | 755 | + Some(Some(*to.get_id())), |
| 756 | None, | 756 | None, |
| 757 | ) | 757 | ) |
| 758 | .await | 758 | .await |
src/db/class_pump.rsmodified+1 -15
| @@ -143,18 +143,6 @@ pub(crate) enum Axis { | |||
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | impl Axis { | 145 | impl Axis { |
| 146 | - /// The class counter this axis's link rows are counted on. Taken off the | ||
| 147 | - /// axis rather than passed in beside it, because the two are one fact and a | ||
| 148 | - /// call site that paired the member axis with the course counter would | ||
| 149 | - /// compile, pass every test — both are `&'static str` — and desync the | ||
| 150 | - /// class delete guard forever. | ||
| 151 | - fn counter(self) -> &'static str { | ||
| 152 | - match self { | ||
| 153 | - Axis::Member => "class_member_count", | ||
| 154 | - Axis::Course => "class_course_count", | ||
| 155 | - } | ||
| 156 | - } | ||
| 157 | - | ||
| 158 | /// How many link rows this axis's counter may reach. | 146 | /// How many link rows this axis's counter may reach. |
| 159 | /// | 147 | /// |
| 160 | /// This is what makes the pair loop in [`add_member`]/[`attach_course`] | 148 | /// This is what makes the pair loop in [`add_member`]/[`attach_course`] |
| @@ -444,7 +432,6 @@ pub(crate) async fn add_member( | |||
| 444 | class: class.clone(), | 432 | class: class.clone(), |
| 445 | user, | 433 | user, |
| 446 | added_by: by, | 434 | added_by: by, |
| 447 | - added_at: Some(added_at), | ||
| 448 | })) | 435 | })) |
| 449 | }) | 436 | }) |
| 450 | .await; | 437 | .await; |
| @@ -539,7 +526,6 @@ pub(crate) async fn attach_course( | |||
| 539 | course: course.clone(), | 526 | course: course.clone(), |
| 540 | attached_by: by, | 527 | attached_by: by, |
| 541 | source: source.clone(), | 528 | source: source.clone(), |
| 542 | - attached_at: Some(attached_at), | ||
| 543 | })) | 529 | })) |
| 544 | }) | 530 | }) |
| 545 | .await; | 531 | .await; |
| @@ -906,7 +892,7 @@ async fn release( | |||
| 906 | } | 892 | } |
| 907 | #[cfg(test)] | 893 | #[cfg(test)] |
| 908 | mod tests { | 894 | mod tests { |
| 909 | - use super::*; | 895 | + |
| 910 | use crate::db::class_member::tests::{a_class, counter, fixture_user, rows}; | 896 | use crate::db::class_member::tests::{a_class, counter, fixture_user, rows}; |
| 911 | use crate::domain::class_group::ClassGroupId; | 897 | use crate::domain::class_group::ClassGroupId; |
| 912 | use crate::error::AppError; | 898 | use crate::error::AppError; |
src/db/course.rsmodified+28 -28
| @@ -5,7 +5,7 @@ | |||
| 5 | use crate::constant::COURSE_TABLE; | 5 | use crate::constant::COURSE_TABLE; |
| 6 | use crate::database::{Database, tx_with_retry, unique_violation}; | 6 | use crate::database::{Database, tx_with_retry, unique_violation}; |
| 7 | use crate::db::cap; | 7 | use crate::db::cap; |
| 8 | -use crate::db::field_update::FieldUpdate; | 8 | +use crate::db::field_update::{FieldUpdate, Refcount}; |
| 9 | use crate::db::page::PagedList; | 9 | use crate::db::page::PagedList; |
| 10 | use crate::domain::course::{Course, CourseDescription, CourseId, CourseKind, CourseTitle}; | 10 | use crate::domain::course::{Course, CourseDescription, CourseId, CourseKind, CourseTitle}; |
| 11 | use crate::domain::term::{self, TermId}; | 11 | use crate::domain::term::{self, TermId}; |
| @@ -220,15 +220,15 @@ pub async fn update( | |||
| 220 | term.map(|term| crate::db::page::Param::OptUuid(term.map(|term| term.uuid()))), | 220 | term.map(|term| crate::db::page::Param::OptUuid(term.map(|term| term.uuid()))), |
| 221 | ) | 221 | ) |
| 222 | .set("capacity", capacity.map(crate::db::page::Param::OptI64)) | 222 | .set("capacity", capacity.map(crate::db::page::Param::OptI64)) |
| 223 | - .refcount( | 223 | + .refcount(Refcount { |
| 224 | - "term", | 224 | + counter_table: "term", |
| 225 | - "course_count", | 225 | + counter_field: "course_count", |
| 226 | - "term", | 226 | + link: "term", |
| 227 | - course.term.as_ref().map(|term| term.uuid()), | 227 | + expected: course.term.as_ref().map(|term| term.uuid()), |
| 228 | - claim.map(|term| term.uuid()), | 228 | + claim: claim.map(|term| term.uuid()), |
| 229 | - release.map(|term| term.uuid()), | 229 | + release: release.map(|term| term.uuid()), |
| 230 | - term::gone_error(), | 230 | + refused: term::gone_error(), |
| 231 | - ) | 231 | + }) |
| 232 | .run::<Course>(db) | 232 | .run::<Course>(db) |
| 233 | .await | 233 | .await |
| 234 | } | 234 | } |
| @@ -801,8 +801,8 @@ mod tests { | |||
| 801 | .await | 801 | .await |
| 802 | .unwrap(); | 802 | .unwrap(); |
| 803 | 803 | ||
| 804 | - let linked = course_on(Some(term.get_id().clone()), &db).await; | 804 | + let linked = course_on(Some(*term.get_id()), &db).await; |
| 805 | - let patched = course_on(Some(term.get_id().clone()), &db).await; | 805 | + let patched = course_on(Some(*term.get_id()), &db).await; |
| 806 | assert!( | 806 | assert!( |
| 807 | !crate::db::term::delete(&db, term.clone()).await.unwrap(), | 807 | !crate::db::term::delete(&db, term.clone()).await.unwrap(), |
| 808 | "two linked courses must refuse the delete" | 808 | "two linked courses must refuse the delete" |
| @@ -885,7 +885,7 @@ mod tests { | |||
| 885 | async fn a_refused_create_writes_neither_row_nor_count() { | 885 | async fn a_refused_create_writes_neither_row_nor_count() { |
| 886 | let (db, _leases) = crate::database::init_test_db().await; | 886 | let (db, _leases) = crate::database::init_test_db().await; |
| 887 | let term = a_term("2026", &db).await; | 887 | let term = a_term("2026", &db).await; |
| 888 | - let id = term.get_id().clone(); | 888 | + let id = *term.get_id(); |
| 889 | assert!(crate::db::term::delete(&db, term).await.unwrap()); | 889 | assert!(crate::db::term::delete(&db, term).await.unwrap()); |
| 890 | 890 | ||
| 891 | let error = create( | 891 | let error = create( |
| @@ -919,7 +919,7 @@ mod tests { | |||
| 919 | let (db, _leases) = crate::database::init_test_db().await; | 919 | let (db, _leases) = crate::database::init_test_db().await; |
| 920 | let from = a_term("2026", &db).await; | 920 | let from = a_term("2026", &db).await; |
| 921 | let to = a_term("2027", &db).await; | 921 | let to = a_term("2027", &db).await; |
| 922 | - let course = course_on(Some(from.get_id().clone()), &db).await; | 922 | + let course = course_on(Some(*from.get_id()), &db).await; |
| 923 | assert_eq!(count_on(from.get_id(), &db).await, 1); | 923 | assert_eq!(count_on(from.get_id(), &db).await, 1); |
| 924 | 924 | ||
| 925 | let moved = update( | 925 | let moved = update( |
| @@ -928,7 +928,7 @@ mod tests { | |||
| 928 | None, | 928 | None, |
| 929 | None, | 929 | None, |
| 930 | None, | 930 | None, |
| 931 | - Some(Some(to.get_id().clone())), | 931 | + Some(Some(*to.get_id())), |
| 932 | None, | 932 | None, |
| 933 | ) | 933 | ) |
| 934 | .await | 934 | .await |
| @@ -957,7 +957,7 @@ mod tests { | |||
| 957 | let from = a_term("2026", &db).await; | 957 | let from = a_term("2026", &db).await; |
| 958 | let to = a_term("2027", &db).await; | 958 | let to = a_term("2027", &db).await; |
| 959 | let other = a_term("2028", &db).await; | 959 | let other = a_term("2028", &db).await; |
| 960 | - let course = course_on(Some(from.get_id().clone()), &db).await; | 960 | + let course = course_on(Some(*from.get_id()), &db).await; |
| 961 | let stale = course.clone(); | 961 | let stale = course.clone(); |
| 962 | update( | 962 | update( |
| 963 | &db, | 963 | &db, |
| @@ -965,7 +965,7 @@ mod tests { | |||
| 965 | None, | 965 | None, |
| 966 | None, | 966 | None, |
| 967 | None, | 967 | None, |
| 968 | - Some(Some(to.get_id().clone())), | 968 | + Some(Some(*to.get_id())), |
| 969 | None, | 969 | None, |
| 970 | ) | 970 | ) |
| 971 | .await | 971 | .await |
| @@ -977,7 +977,7 @@ mod tests { | |||
| 977 | None, | 977 | None, |
| 978 | None, | 978 | None, |
| 979 | None, | 979 | None, |
| 980 | - Some(Some(other.get_id().clone())), | 980 | + Some(Some(*other.get_id())), |
| 981 | None, | 981 | None, |
| 982 | ) | 982 | ) |
| 983 | .await | 983 | .await |
| @@ -1006,7 +1006,7 @@ mod tests { | |||
| 1006 | None, | 1006 | None, |
| 1007 | None, | 1007 | None, |
| 1008 | None, | 1008 | None, |
| 1009 | - Some(Some(to.get_id().clone())), | 1009 | + Some(Some(*to.get_id())), |
| 1010 | None, | 1010 | None, |
| 1011 | ) | 1011 | ) |
| 1012 | .await | 1012 | .await |
| @@ -1017,7 +1017,7 @@ mod tests { | |||
| 1017 | None, | 1017 | None, |
| 1018 | None, | 1018 | None, |
| 1019 | None, | 1019 | None, |
| 1020 | - Some(Some(other.get_id().clone())), | 1020 | + Some(Some(*other.get_id())), |
| 1021 | None, | 1021 | None, |
| 1022 | ) | 1022 | ) |
| 1023 | .await | 1023 | .await |
| @@ -1047,7 +1047,7 @@ mod tests { | |||
| 1047 | let (db, _leases) = crate::database::init_test_db().await; | 1047 | let (db, _leases) = crate::database::init_test_db().await; |
| 1048 | let from = a_term("2026", &db).await; | 1048 | let from = a_term("2026", &db).await; |
| 1049 | let to = a_term("2027", &db).await; | 1049 | let to = a_term("2027", &db).await; |
| 1050 | - let course = course_on(Some(from.get_id().clone()), &db).await; | 1050 | + let course = course_on(Some(*from.get_id()), &db).await; |
| 1051 | let stale = course.clone(); | 1051 | let stale = course.clone(); |
| 1052 | update( | 1052 | update( |
| 1053 | &db, | 1053 | &db, |
| @@ -1055,7 +1055,7 @@ mod tests { | |||
| 1055 | None, | 1055 | None, |
| 1056 | None, | 1056 | None, |
| 1057 | None, | 1057 | None, |
| 1058 | - Some(Some(to.get_id().clone())), | 1058 | + Some(Some(*to.get_id())), |
| 1059 | None, | 1059 | None, |
| 1060 | ) | 1060 | ) |
| 1061 | .await | 1061 | .await |
| @@ -1067,7 +1067,7 @@ mod tests { | |||
| 1067 | None, | 1067 | None, |
| 1068 | None, | 1068 | None, |
| 1069 | None, | 1069 | None, |
| 1070 | - Some(Some(from.get_id().clone())), | 1070 | + Some(Some(*from.get_id())), |
| 1071 | None, | 1071 | None, |
| 1072 | ) | 1072 | ) |
| 1073 | .await | 1073 | .await |
| @@ -1098,7 +1098,7 @@ mod tests { | |||
| 1098 | None, | 1098 | None, |
| 1099 | None, | 1099 | None, |
| 1100 | None, | 1100 | None, |
| 1101 | - Some(Some(to.get_id().clone())), | 1101 | + Some(Some(*to.get_id())), |
| 1102 | None, | 1102 | None, |
| 1103 | ) | 1103 | ) |
| 1104 | .await | 1104 | .await |
| @@ -1118,9 +1118,9 @@ mod tests { | |||
| 1118 | let (db, _leases) = crate::database::init_test_db().await; | 1118 | let (db, _leases) = crate::database::init_test_db().await; |
| 1119 | let from = a_term("2026", &db).await; | 1119 | let from = a_term("2026", &db).await; |
| 1120 | let dead = a_term("2027", &db).await; | 1120 | let dead = a_term("2027", &db).await; |
| 1121 | - let dead_id = dead.get_id().clone(); | 1121 | + let dead_id = *dead.get_id(); |
| 1122 | assert!(crate::db::term::delete(&db, dead).await.unwrap()); | 1122 | assert!(crate::db::term::delete(&db, dead).await.unwrap()); |
| 1123 | - let course = course_on(Some(from.get_id().clone()), &db).await; | 1123 | + let course = course_on(Some(*from.get_id()), &db).await; |
| 1124 | 1124 | ||
| 1125 | let error = update( | 1125 | let error = update( |
| 1126 | &db, | 1126 | &db, |
| @@ -1211,8 +1211,8 @@ mod tests { | |||
| 1211 | }; | 1211 | }; |
| 1212 | let joins: Vec<_> = (0..6) | 1212 | let joins: Vec<_> = (0..6) |
| 1213 | .map(|seat| { | 1213 | .map(|seat| { |
| 1214 | - let (id, db, mgr) = (course.get_id().clone(), db.clone(), mgr.clone()); | 1214 | + let (id, db, mgr) = (course.get_id().clone(), db.clone(), mgr); |
| 1215 | - let student = students[seat].clone(); | 1215 | + let student = students[seat]; |
| 1216 | tokio::spawn(async move { | 1216 | tokio::spawn(async move { |
| 1217 | crate::db::enrollment::enroll(&db, &id, &student, &mgr).await | 1217 | crate::db::enrollment::enroll(&db, &id, &student, &mgr).await |
| 1218 | }) | 1218 | }) |
src/db/course_note.rsmodified+1 -1
| @@ -22,7 +22,7 @@ pub async fn create( | |||
| 22 | let note = CourseNote { | 22 | let note = CourseNote { |
| 23 | id: CourseNoteId::generate(), | 23 | id: CourseNoteId::generate(), |
| 24 | course: course.clone(), | 24 | course: course.clone(), |
| 25 | - author: author.clone(), | 25 | + author: *author, |
| 26 | title, | 26 | title, |
| 27 | content, | 27 | content, |
| 28 | }; | 28 | }; |
src/db/course_session.rsmodified+1 -1
| @@ -25,7 +25,7 @@ pub async fn create( | |||
| 25 | let session = CourseSession { | 25 | let session = CourseSession { |
| 26 | id: CourseSessionId::generate(), | 26 | id: CourseSessionId::generate(), |
| 27 | course: course.clone(), | 27 | course: course.clone(), |
| 28 | - teacher: teacher.clone(), | 28 | + teacher: *teacher, |
| 29 | topic, | 29 | topic, |
| 30 | starts_at, | 30 | starts_at, |
| 31 | ends_at, | 31 | ends_at, |
src/db/enrollment.rsmodified+1 -1
| @@ -303,7 +303,7 @@ mod tests { | |||
| 303 | let student = a_person(&db, "student", "student").await; | 303 | let student = a_person(&db, "student", "student").await; |
| 304 | let ghost = Enrollment { | 304 | let ghost = Enrollment { |
| 305 | course: course.clone(), | 305 | course: course.clone(), |
| 306 | - user: student.clone(), | 306 | + user: student, |
| 307 | enrolled_by: a_person(&db, "mgr", "manager").await, | 307 | enrolled_by: a_person(&db, "mgr", "manager").await, |
| 308 | source: Some(class), | 308 | source: Some(class), |
| 309 | }; | 309 | }; |
src/db/event.rsmodified+5 -5
| @@ -67,14 +67,14 @@ pub async fn members(db: &Database, event: &Event) -> Result<Vec<UserId>, AppErr | |||
| 67 | .await? | 67 | .await? |
| 68 | .0 | 68 | .0 |
| 69 | .iter() | 69 | .iter() |
| 70 | - .map(|user| user.get_id().clone()) | 70 | + .map(|user| *user.get_id()) |
| 71 | .collect()), | 71 | .collect()), |
| 72 | crate::domain::event::EventAudienceKind::Role => { | 72 | crate::domain::event::EventAudienceKind::Role => { |
| 73 | match event.get_audience_role() { | 73 | match event.get_audience_role() { |
| 74 | Some(role) => Ok(crate::db::user::list_by_role(db, role) | 74 | Some(role) => Ok(crate::db::user::list_by_role(db, role) |
| 75 | .await? | 75 | .await? |
| 76 | .iter() | 76 | .iter() |
| 77 | - .map(|user| user.get_id().clone()) | 77 | + .map(|user| *user.get_id()) |
| 78 | .collect()), | 78 | .collect()), |
| 79 | None => Ok(Vec::new()), | 79 | None => Ok(Vec::new()), |
| 80 | } | 80 | } |
| @@ -84,7 +84,7 @@ pub async fn members(db: &Database, event: &Event) -> Result<Vec<UserId>, AppErr | |||
| 84 | .await? | 84 | .await? |
| 85 | .0 | 85 | .0 |
| 86 | .iter() | 86 | .iter() |
| 87 | - .map(|enrollment| enrollment.get_user().clone()) | 87 | + .map(|enrollment| *enrollment.get_user()) |
| 88 | .collect()), | 88 | .collect()), |
| 89 | None => Ok(Vec::new()), | 89 | None => Ok(Vec::new()), |
| 90 | }, | 90 | }, |
| @@ -93,7 +93,7 @@ pub async fn members(db: &Database, event: &Event) -> Result<Vec<UserId>, AppErr | |||
| 93 | .await? | 93 | .await? |
| 94 | .0 | 94 | .0 |
| 95 | .iter() | 95 | .iter() |
| 96 | - .map(|member| member.get_user().clone()) | 96 | + .map(|member| *member.get_user()) |
| 97 | .collect()), | 97 | .collect()), |
| 98 | None => Ok(Vec::new()), | 98 | None => Ok(Vec::new()), |
| 99 | }, | 99 | }, |
| @@ -101,7 +101,7 @@ pub async fn members(db: &Database, event: &Event) -> Result<Vec<UserId>, AppErr | |||
| 101 | Ok(crate::db::registration::list_for_event(db, event.get_id()) | 101 | Ok(crate::db::registration::list_for_event(db, event.get_id()) |
| 102 | .await? | 102 | .await? |
| 103 | .iter() | 103 | .iter() |
| 104 | - .map(|registration| registration.get_user().clone()) | 104 | + .map(|registration| *registration.get_user()) |
| 105 | .collect()) | 105 | .collect()) |
| 106 | } | 106 | } |
| 107 | } | 107 | } |
src/db/exam.rsmodified+5 -5
| @@ -865,7 +865,7 @@ mod tests { | |||
| 865 | let marks: Vec<_> = (0..6) | 865 | let marks: Vec<_> = (0..6) |
| 866 | .map(|seat| { | 866 | .map(|seat| { |
| 867 | let (id, db, kind) = (exam.get_id().clone(), db.clone(), kind.clone()); | 867 | let (id, db, kind) = (exam.get_id().clone(), db.clone(), kind.clone()); |
| 868 | - let (student, teacher) = (students[seat].clone(), teacher.clone()); | 868 | + let (student, teacher) = (students[seat], teacher); |
| 869 | tokio::spawn(async move { | 869 | tokio::spawn(async move { |
| 870 | exam_result::grade( | 870 | exam_result::grade( |
| 871 | &db, | 871 | &db, |
| @@ -978,7 +978,7 @@ mod tests { | |||
| 978 | crate::db::exam_question::create( | 978 | crate::db::exam_question::create( |
| 979 | db, | 979 | db, |
| 980 | exam.get_id(), | 980 | exam.get_id(), |
| 981 | - subject.get_id().clone(), | 981 | + *subject.get_id(), |
| 982 | QuestionText::try_new("3 + 3?").unwrap(), | 982 | QuestionText::try_new("3 + 3?").unwrap(), |
| 983 | QuestionPoints::try_new(5).unwrap(), | 983 | QuestionPoints::try_new(5).unwrap(), |
| 984 | spec, | 984 | spec, |
| @@ -1029,7 +1029,7 @@ mod tests { | |||
| 1029 | }; | 1029 | }; |
| 1030 | let child = { | 1030 | let child = { |
| 1031 | let (db, question, student, pick, gate) = | 1031 | let (db, question, student, pick, gate) = |
| 1032 | - (db.clone(), question.clone(), student.clone(), pick, gate); | 1032 | + (db.clone(), question.clone(), student, pick, gate); |
| 1033 | tokio::spawn(async move { | 1033 | tokio::spawn(async move { |
| 1034 | gate.wait().await; | 1034 | gate.wait().await; |
| 1035 | exam_answer::save(&db, &question, &student, 1, Some(pick), None).await | 1035 | exam_answer::save(&db, &question, &student, 1, Some(pick), None).await |
| @@ -1098,7 +1098,7 @@ mod tests { | |||
| 1098 | }) | 1098 | }) |
| 1099 | }; | 1099 | }; |
| 1100 | let child = { | 1100 | let child = { |
| 1101 | - let (db, exam_id, on, gate) = (db.clone(), id.clone(), subject.get_id().clone(), gate); | 1101 | + let (db, exam_id, on, gate) = (db.clone(), id.clone(), *subject.get_id(), gate); |
| 1102 | tokio::spawn(async move { | 1102 | tokio::spawn(async move { |
| 1103 | gate.wait().await; | 1103 | gate.wait().await; |
| 1104 | let spec = QuestionSpec::try_new( | 1104 | let spec = QuestionSpec::try_new( |
| @@ -1197,7 +1197,7 @@ mod tests { | |||
| 1197 | }; | 1197 | }; |
| 1198 | let child = { | 1198 | let child = { |
| 1199 | let (db, exam_id, on, student, gate) = | 1199 | let (db, exam_id, on, student, gate) = |
| 1200 | - (db.clone(), id.clone(), question.get_id().clone(), student.clone(), gate); | 1200 | + (db.clone(), id.clone(), question.get_id().clone(), student, gate); |
| 1201 | tokio::spawn(async move { | 1201 | tokio::spawn(async move { |
| 1202 | gate.wait().await; | 1202 | gate.wait().await; |
| 1203 | let image = AnswerImage::new( | 1203 | let image = AnswerImage::new( |
src/db/exam_answer.rsmodified+1 -1
| @@ -363,7 +363,7 @@ mod tests { | |||
| 363 | let question = crate::db::exam_question::create( | 363 | let question = crate::db::exam_question::create( |
| 364 | &db, | 364 | &db, |
| 365 | exam.get_id(), | 365 | exam.get_id(), |
| 366 | - subject.get_id().clone(), | 366 | + *subject.get_id(), |
| 367 | crate::domain::exam_question::QuestionText::try_new("pick one").unwrap(), | 367 | crate::domain::exam_question::QuestionText::try_new("pick one").unwrap(), |
| 368 | crate::domain::exam_question::QuestionPoints::try_new(10).unwrap(), | 368 | crate::domain::exam_question::QuestionPoints::try_new(10).unwrap(), |
| 369 | spec, | 369 | spec, |
src/db/exam_attempt.rsmodified+2 -3
| @@ -447,7 +447,7 @@ mod tests { | |||
| 447 | let question = crate::db::exam_question::create( | 447 | let question = crate::db::exam_question::create( |
| 448 | db, | 448 | db, |
| 449 | exam.get_id(), | 449 | exam.get_id(), |
| 450 | - subject.get_id().clone(), | 450 | + *subject.get_id(), |
| 451 | crate::domain::exam_question::QuestionText::try_new("3 + 3?").unwrap(), | 451 | crate::domain::exam_question::QuestionText::try_new("3 + 3?").unwrap(), |
| 452 | QuestionPoints::try_new(5).unwrap(), | 452 | QuestionPoints::try_new(5).unwrap(), |
| 453 | spec, | 453 | spec, |
| @@ -465,7 +465,7 @@ mod tests { | |||
| 465 | .hash_async() | 465 | .hash_async() |
| 466 | .await | 466 | .await |
| 467 | .unwrap(); | 467 | .unwrap(); |
| 468 | - crate::db::user::create( | 468 | + *crate::db::user::create( |
| 469 | db, | 469 | db, |
| 470 | crate::domain::user::Username::try_new("ogrenci").unwrap(), | 470 | crate::domain::user::Username::try_new("ogrenci").unwrap(), |
| 471 | hash, | 471 | hash, |
| @@ -473,7 +473,6 @@ mod tests { | |||
| 473 | .await | 473 | .await |
| 474 | .unwrap() | 474 | .unwrap() |
| 475 | .get_id() | 475 | .get_id() |
| 476 | - .clone() | ||
| 477 | } | 476 | } |
| 478 | 477 | ||
| 479 | #[tokio::test] | 478 | #[tokio::test] |
src/db/exam_question.rsmodified+18 -18
| @@ -258,7 +258,7 @@ pub async fn update( | |||
| 258 | // subject its own stale snapshot held, sent while a rival's move | 258 | // subject its own stale snapshot held, sent while a rival's move |
| 259 | // already landed, writes that stale subject straight back over the | 259 | // already landed, writes that stale subject straight back over the |
| 260 | // winner — a revert with the counters left pointing at the move. | 260 | // winner — a revert with the counters left pointing at the move. |
| 261 | - let retag = (subject != question.subject).then(|| (subject, question.subject.clone())); | 261 | + let retag = (subject != question.subject).then_some((subject, question.subject)); |
| 262 | tx_with_retry(db, false, async move |conn| { | 262 | tx_with_retry(db, false, async move |conn| { |
| 263 | // Freeze first, as always: it outranks every caller gate, and a | 263 | // Freeze first, as always: it outranks every caller gate, and a |
| 264 | // frozen exam answers the same 409 the pre-flight check gave. | 264 | // frozen exam answers the same 409 the pre-flight check gave. |
| @@ -498,7 +498,7 @@ mod tests { | |||
| 498 | 498 | ||
| 499 | async fn a_question(exam: &Exam, on: &SubjectId, db: &Database) -> ExamQuestion { | 499 | async fn a_question(exam: &Exam, on: &SubjectId, db: &Database) -> ExamQuestion { |
| 500 | let (text, points, spec) = body(); | 500 | let (text, points, spec) = body(); |
| 501 | - create(db, exam.get_id(), on.clone(), text, points, spec) | 501 | + create(db, exam.get_id(), *on, text, points, spec) |
| 502 | .await | 502 | .await |
| 503 | .unwrap() | 503 | .unwrap() |
| 504 | } | 504 | } |
| @@ -509,7 +509,7 @@ mod tests { | |||
| 509 | db: &Database, | 509 | db: &Database, |
| 510 | ) -> Result<ExamQuestion, AppError> { | 510 | ) -> Result<ExamQuestion, AppError> { |
| 511 | let (text, points, spec) = body(); | 511 | let (text, points, spec) = body(); |
| 512 | - update(db, question, to.clone(), text, points, spec).await | 512 | + update(db, question, *to, text, points, spec).await |
| 513 | } | 513 | } |
| 514 | 514 | ||
| 515 | /// The stored `exam_question_count` on one subject, absent = zero. | 515 | /// The stored `exam_question_count` on one subject, absent = zero. |
| @@ -540,7 +540,7 @@ mod tests { | |||
| 540 | let (db, _leases) = init_test_db().await; | 540 | let (db, _leases) = init_test_db().await; |
| 541 | let exam = an_exam(&db).await; | 541 | let exam = an_exam(&db).await; |
| 542 | let (from, to) = (a_subject(&db).await, a_subject(&db).await); | 542 | let (from, to) = (a_subject(&db).await, a_subject(&db).await); |
| 543 | - let (from, to) = (from.get_id().clone(), to.get_id().clone()); | 543 | + let (from, to) = (*from.get_id(), *to.get_id()); |
| 544 | let question = a_question(&exam, &from, &db).await; | 544 | let question = a_question(&exam, &from, &db).await; |
| 545 | assert_eq!(count_on(&from, &db).await, 1); | 545 | assert_eq!(count_on(&from, &db).await, 1); |
| 546 | 546 | ||
| @@ -564,7 +564,7 @@ mod tests { | |||
| 564 | .unwrap(); | 564 | .unwrap(); |
| 565 | 565 | ||
| 566 | let (text, points, spec) = body(); | 566 | let (text, points, spec) = body(); |
| 567 | - let error = create(&db, exam.get_id(), to.clone(), text, points, spec) | 567 | + let error = create(&db, exam.get_id(), to, text, points, spec) |
| 568 | .await | 568 | .await |
| 569 | .expect_err("a started exam takes no new questions"); | 569 | .expect_err("a started exam takes no new questions"); |
| 570 | assert!(matches!(error, AppError::Conflict(_)), "{error:?}"); | 570 | assert!(matches!(error, AppError::Conflict(_)), "{error:?}"); |
| @@ -585,7 +585,7 @@ mod tests { | |||
| 585 | let (db, _leases) = init_test_db().await; | 585 | let (db, _leases) = init_test_db().await; |
| 586 | let exam = an_exam(&db).await; | 586 | let exam = an_exam(&db).await; |
| 587 | let subject = a_subject(&db).await; | 587 | let subject = a_subject(&db).await; |
| 588 | - let id = subject.get_id().clone(); | 588 | + let id = *subject.get_id(); |
| 589 | crate::db::subject::delete(&db, subject).await.unwrap(); | 589 | crate::db::subject::delete(&db, subject).await.unwrap(); |
| 590 | 590 | ||
| 591 | let (text, points, spec) = body(); | 591 | let (text, points, spec) = body(); |
| @@ -610,7 +610,7 @@ mod tests { | |||
| 610 | let (db, _leases) = init_test_db().await; | 610 | let (db, _leases) = init_test_db().await; |
| 611 | let exam = an_exam(&db).await; | 611 | let exam = an_exam(&db).await; |
| 612 | let (from, to) = (a_subject(&db).await, a_subject(&db).await); | 612 | let (from, to) = (a_subject(&db).await, a_subject(&db).await); |
| 613 | - let (from, to) = (from.get_id().clone(), to.get_id().clone()); | 613 | + let (from, to) = (*from.get_id(), *to.get_id()); |
| 614 | let question = a_question(&exam, &from, &db).await; | 614 | let question = a_question(&exam, &from, &db).await; |
| 615 | 615 | ||
| 616 | let after = moved(question, &to, &db).await.unwrap(); | 616 | let after = moved(question, &to, &db).await.unwrap(); |
| @@ -623,9 +623,9 @@ mod tests { | |||
| 623 | async fn a_move_to_a_dead_subject_leaves_everything_untouched() { | 623 | async fn a_move_to_a_dead_subject_leaves_everything_untouched() { |
| 624 | let (db, _leases) = init_test_db().await; | 624 | let (db, _leases) = init_test_db().await; |
| 625 | let exam = an_exam(&db).await; | 625 | let exam = an_exam(&db).await; |
| 626 | - let from = a_subject(&db).await.get_id().clone(); | 626 | + let from = *a_subject(&db).await.get_id(); |
| 627 | let dead = a_subject(&db).await; | 627 | let dead = a_subject(&db).await; |
| 628 | - let gone = dead.get_id().clone(); | 628 | + let gone = *dead.get_id(); |
| 629 | crate::db::subject::delete(&db, dead).await.unwrap(); | 629 | crate::db::subject::delete(&db, dead).await.unwrap(); |
| 630 | let question = a_question(&exam, &from, &db).await; | 630 | let question = a_question(&exam, &from, &db).await; |
| 631 | 631 | ||
| @@ -658,9 +658,9 @@ mod tests { | |||
| 658 | async fn a_stale_mover_is_refused_and_claims_nothing() { | 658 | async fn a_stale_mover_is_refused_and_claims_nothing() { |
| 659 | let (db, _leases) = init_test_db().await; | 659 | let (db, _leases) = init_test_db().await; |
| 660 | let exam = an_exam(&db).await; | 660 | let exam = an_exam(&db).await; |
| 661 | - let from = a_subject(&db).await.get_id().clone(); | 661 | + let from = *a_subject(&db).await.get_id(); |
| 662 | - let to = a_subject(&db).await.get_id().clone(); | 662 | + let to = *a_subject(&db).await.get_id(); |
| 663 | - let other = a_subject(&db).await.get_id().clone(); | 663 | + let other = *a_subject(&db).await.get_id(); |
| 664 | let question = a_question(&exam, &from, &db).await; | 664 | let question = a_question(&exam, &from, &db).await; |
| 665 | let stale = question.clone(); | 665 | let stale = question.clone(); |
| 666 | 666 | ||
| @@ -694,8 +694,8 @@ mod tests { | |||
| 694 | async fn a_stale_re_stater_is_refused_and_reverts_nothing() { | 694 | async fn a_stale_re_stater_is_refused_and_reverts_nothing() { |
| 695 | let (db, _leases) = init_test_db().await; | 695 | let (db, _leases) = init_test_db().await; |
| 696 | let exam = an_exam(&db).await; | 696 | let exam = an_exam(&db).await; |
| 697 | - let from = a_subject(&db).await.get_id().clone(); | 697 | + let from = *a_subject(&db).await.get_id(); |
| 698 | - let to = a_subject(&db).await.get_id().clone(); | 698 | + let to = *a_subject(&db).await.get_id(); |
| 699 | let question = a_question(&exam, &from, &db).await; | 699 | let question = a_question(&exam, &from, &db).await; |
| 700 | let stale = question.clone(); | 700 | let stale = question.clone(); |
| 701 | 701 | ||
| @@ -724,14 +724,14 @@ mod tests { | |||
| 724 | async fn a_no_op_re_state_still_lands() { | 724 | async fn a_no_op_re_state_still_lands() { |
| 725 | let (db, _leases) = init_test_db().await; | 725 | let (db, _leases) = init_test_db().await; |
| 726 | let exam = an_exam(&db).await; | 726 | let exam = an_exam(&db).await; |
| 727 | - let on = a_subject(&db).await.get_id().clone(); | 727 | + let on = *a_subject(&db).await.get_id(); |
| 728 | let question = a_question(&exam, &on, &db).await; | 728 | let question = a_question(&exam, &on, &db).await; |
| 729 | 729 | ||
| 730 | let (_, points, spec) = body(); | 730 | let (_, points, spec) = body(); |
| 731 | let after = update( | 731 | let after = update( |
| 732 | &db, | 732 | &db, |
| 733 | question, | 733 | question, |
| 734 | - on.clone(), | 734 | + on, |
| 735 | QuestionText::try_new("4 + 4?").unwrap(), | 735 | QuestionText::try_new("4 + 4?").unwrap(), |
| 736 | points, | 736 | points, |
| 737 | spec, | 737 | spec, |
| @@ -749,8 +749,8 @@ mod tests { | |||
| 749 | async fn a_move_of_a_deleted_question_is_still_a_404() { | 749 | async fn a_move_of_a_deleted_question_is_still_a_404() { |
| 750 | let (db, _leases) = init_test_db().await; | 750 | let (db, _leases) = init_test_db().await; |
| 751 | let exam = an_exam(&db).await; | 751 | let exam = an_exam(&db).await; |
| 752 | - let from = a_subject(&db).await.get_id().clone(); | 752 | + let from = *a_subject(&db).await.get_id(); |
| 753 | - let to = a_subject(&db).await.get_id().clone(); | 753 | + let to = *a_subject(&db).await.get_id(); |
| 754 | let question = a_question(&exam, &from, &db).await; | 754 | let question = a_question(&exam, &from, &db).await; |
| 755 | delete(&db, question.clone()).await.unwrap(); | 755 | delete(&db, question.clone()).await.unwrap(); |
| 756 | 756 | ||
src/db/exam_result.rsmodified+2 -2
| @@ -359,7 +359,7 @@ pub async fn remove( | |||
| 359 | { | 359 | { |
| 360 | *n += 1; | 360 | *n += 1; |
| 361 | } else { | 361 | } else { |
| 362 | - per_grader.push((row.graded_by.clone(), 1)); | 362 | + per_grader.push((row.graded_by, 1)); |
| 363 | } | 363 | } |
| 364 | } | 364 | } |
| 365 | for (grader, n) in &per_grader { | 365 | for (grader, n) in &per_grader { |
| @@ -378,7 +378,7 @@ pub async fn remove( | |||
| 378 | // removed and what the latest standing was. | 378 | // removed and what the latest standing was. |
| 379 | let first = gone.into_iter().next().map(|row| ExamResult { | 379 | let first = gone.into_iter().next().map(|row| ExamResult { |
| 380 | exam: exam.clone(), | 380 | exam: exam.clone(), |
| 381 | - user: user.clone(), | 381 | + user, |
| 382 | seq: row.seq, | 382 | seq: row.seq, |
| 383 | mark: row.mark, | 383 | mark: row.mark, |
| 384 | graded_by: row.graded_by, | 384 | graded_by: row.graded_by, |
src/db/field_update.rsmodified+29 -79
| @@ -59,17 +59,19 @@ fn mark(kind: &'static str) -> AppError { | |||
| 59 | AppError::Internal(kind.to_owned()) | 59 | AppError::Internal(kind.to_owned()) |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | -/// `(counter table, counter field, link column, expected link, claim, release, | 62 | +/// The counter move [`FieldUpdate::refcount`] arms: the table and field that |
| 63 | -/// refusal)`. | 63 | +/// count the link, the column carrying it, the link value the handler's |
| 64 | -type Refcount = ( | 64 | +/// snapshot read, the claim/release pair, and the caller's answer when the |
| 65 | - &'static str, | 65 | +/// claimed counter row is gone. |
| 66 | - &'static str, | 66 | +pub(crate) struct Refcount { |
| 67 | - &'static str, | 67 | + pub(crate) counter_table: &'static str, |
| 68 | - Option<Uuid>, | 68 | + pub(crate) counter_field: &'static str, |
| 69 | - Option<Uuid>, | 69 | + pub(crate) link: &'static str, |
| 70 | - Option<Uuid>, | 70 | + pub(crate) expected: Option<Uuid>, |
| 71 | - AppError, | 71 | + pub(crate) claim: Option<Uuid>, |
| 72 | -); | 72 | + pub(crate) release: Option<Uuid>, |
| 73 | + pub(crate) refused: AppError, | ||
| 74 | +} | ||
| 73 | 75 | ||
| 74 | pub(crate) struct FieldUpdate { | 76 | pub(crate) struct FieldUpdate { |
| 75 | /// The row's own table — an in-crate constant, never user input. | 77 | /// The row's own table — an in-crate constant, never user input. |
| @@ -80,10 +82,7 @@ pub(crate) struct FieldUpdate { | |||
| 80 | sets: Vec<(&'static str, Param)>, | 82 | sets: Vec<(&'static str, Param)>, |
| 81 | /// `(low, high, refusal)` for [`FieldUpdate::ordered`]. | 83 | /// `(low, high, refusal)` for [`FieldUpdate::ordered`]. |
| 82 | ordered: Option<(&'static str, &'static str, AppError)>, | 84 | ordered: Option<(&'static str, &'static str, AppError)>, |
| 83 | - /// `(condition, refusal)` for [`FieldUpdate::guard`]. | 85 | + /// The armed counter move, from [`FieldUpdate::refcount`]. |
| 84 | - guard: Option<(&'static str, AppError)>, | ||
| 85 | - /// `(counter table, counter field, link column, expected link, claim, | ||
| 86 | - /// release, refusal)` for [`FieldUpdate::refcount`]. | ||
| 87 | refcount: Option<Refcount>, | 86 | refcount: Option<Refcount>, |
| 88 | } | 87 | } |
| 89 | 88 | ||
| @@ -95,7 +94,6 @@ impl FieldUpdate { | |||
| 95 | id, | 94 | id, |
| 96 | sets: Vec::new(), | 95 | sets: Vec::new(), |
| 97 | ordered: None, | 96 | ordered: None, |
| 98 | - guard: None, | ||
| 99 | refcount: None, | 97 | refcount: None, |
| 100 | } | 98 | } |
| 101 | } | 99 | } |
| @@ -135,23 +133,6 @@ impl FieldUpdate { | |||
| 135 | self | 133 | self |
| 136 | } | 134 | } |
| 137 | 135 | ||
| 138 | - /// Refuse the write unless `condition` — a predicate on this same row — | ||
| 139 | - /// still holds at write time. The [`FieldUpdate::ordered`] guard for a | ||
| 140 | - /// precondition that is not about a range: a handler that read "nothing | ||
| 141 | - /// references this yet" re-asks the database at the instant it writes, so | ||
| 142 | - /// a reference landing in between refuses the edit instead of being | ||
| 143 | - /// edited out from under. `condition` is always an in-crate SQL literal, | ||
| 144 | - /// never user input. | ||
| 145 | - /// | ||
| 146 | - /// A request that carries no field at all emits no `UPDATE`, so it is not | ||
| 147 | - /// refused: it writes nothing, and reading the row back is a truthful | ||
| 148 | - /// answer to a PATCH that asked for no change. | ||
| 149 | - #[must_use] | ||
| 150 | - pub(crate) fn guard(mut self, condition: &'static str, refused: AppError) -> Self { | ||
| 151 | - self.guard = Some((condition, refused)); | ||
| 152 | - self | ||
| 153 | - } | ||
| 154 | - | ||
| 155 | /// Move a reference counter *with* this write: `claim` takes one on the | 136 | /// Move a reference counter *with* this write: `claim` takes one on the |
| 156 | /// row the link moves to (in `counter_table`), `release` gives one back | 137 | /// row the link moves to (in `counter_table`), `release` gives one back |
| 157 | /// on the row it moves off, and both ride the same transaction as the | 138 | /// on the row it moves off, and both ride the same transaction as the |
| @@ -190,25 +171,8 @@ impl FieldUpdate { | |||
| 190 | /// and leaving the reverted-to term linked at zero (deletable while | 171 | /// and leaving the reverted-to term linked at zero (deletable while |
| 191 | /// linked). Gating the CAS on the counters is what let that through. | 172 | /// linked). Gating the CAS on the counters is what let that through. |
| 192 | #[must_use] | 173 | #[must_use] |
| 193 | - pub(crate) fn refcount( | 174 | + pub(crate) fn refcount(mut self, refcount: Refcount) -> Self { |
| 194 | - mut self, | 175 | + self.refcount = Some(refcount); |
| 195 | - counter_table: &'static str, | ||
| 196 | - counter_field: &'static str, | ||
| 197 | - link: &'static str, | ||
| 198 | - expected: Option<Uuid>, | ||
| 199 | - claim: Option<Uuid>, | ||
| 200 | - release: Option<Uuid>, | ||
| 201 | - refused: AppError, | ||
| 202 | - ) -> Self { | ||
| 203 | - self.refcount = Some(( | ||
| 204 | - counter_table, | ||
| 205 | - counter_field, | ||
| 206 | - link, | ||
| 207 | - expected, | ||
| 208 | - claim, | ||
| 209 | - release, | ||
| 210 | - refused, | ||
| 211 | - )); | ||
| 212 | self | 176 | self |
| 213 | } | 177 | } |
| 214 | 178 | ||
| @@ -223,7 +187,7 @@ impl FieldUpdate { | |||
| 223 | // read and so shifts nothing. Decided here rather than in `refcount` | 187 | // read and so shifts nothing. Decided here rather than in `refcount` |
| 224 | // so the builder's call order cannot silently disarm it — `run` is | 188 | // so the builder's call order cannot silently disarm it — `run` is |
| 225 | // always last. | 189 | // always last. |
| 226 | - let moved = self.refcount.take().filter(|rc| self.is_set(rc.2)); | 190 | + let moved = self.refcount.take().filter(|rc| self.is_set(rc.link)); |
| 227 | if self.sets.is_empty() { | 191 | if self.sets.is_empty() { |
| 228 | let row: Option<T> = sqlx::query_as(AssertSqlSafe(format!( | 192 | let row: Option<T> = sqlx::query_as(AssertSqlSafe(format!( |
| 229 | "SELECT * FROM {} WHERE id = $1", | 193 | "SELECT * FROM {} WHERE id = $1", |
| @@ -270,33 +234,21 @@ impl FieldUpdate { | |||
| 270 | } | 234 | } |
| 271 | _ => (None, None), | 235 | _ => (None, None), |
| 272 | }; | 236 | }; |
| 273 | - let (extra, extra_refused) = match self.guard.take() { | ||
| 274 | - Some((condition, err)) => (Some(condition.to_owned()), Some(err)), | ||
| 275 | - None => (None, None), | ||
| 276 | - }; | ||
| 277 | - // No caller sets both, so the refusal is whichever one is there. | ||
| 278 | - refused = refused.or(extra_refused); | ||
| 279 | // A PATCH that does not carry the link at all writes the same | 237 | // A PATCH that does not carry the link at all writes the same |
| 280 | // unguarded `UPDATE` it always did — it re-states nothing and races | 238 | // unguarded `UPDATE` it always did — it re-states nothing and races |
| 281 | // nobody. The CAS is `IS NOT DISTINCT FROM`, so an absent link | 239 | // nobody. The CAS is `IS NOT DISTINCT FROM`, so an absent link |
| 282 | // (bound `None`) still compares truthfully. | 240 | // (bound `None`) still compares truthfully. |
| 283 | let mut expected_at: Option<usize> = None; | 241 | let mut expected_at: Option<usize> = None; |
| 284 | let cas = moved.as_ref().map(|rc| { | 242 | let cas = moved.as_ref().map(|rc| { |
| 285 | - binds.push(Param::OptUuid(rc.3)); | 243 | + binds.push(Param::OptUuid(rc.expected)); |
| 286 | expected_at = Some(binds.len()); | 244 | expected_at = Some(binds.len()); |
| 287 | - format!("{} IS NOT DISTINCT FROM ${}", rc.2, binds.len()) | 245 | + format!("{} IS NOT DISTINCT FROM ${}", rc.link, binds.len()) |
| 288 | }); | 246 | }); |
| 289 | - // The caller's own guards, kept apart from the CAS: the probe below | 247 | + // The ordered guard is kept apart from the CAS: the probe below has |
| 290 | - // has to ask "did *only* the link move?", and a probe that ignores | 248 | + // to ask "did *only* the link move?", and a probe that ignores it |
| 291 | - // them answers "the link moved" to a write its `.guard()` refused | 249 | + // answers "the link moved" to a write the guard refused outright. |
| 292 | - // outright. | 250 | + let own = ordered.iter().cloned().collect::<Vec<_>>().join(" AND "); |
| 293 | - let own = ordered | 251 | + let conditions: Vec<String> = ordered.into_iter().chain(cas).collect(); |
| 294 | - .iter() | ||
| 295 | - .chain(extra.iter()) | ||
| 296 | - .cloned() | ||
| 297 | - .collect::<Vec<_>>() | ||
| 298 | - .join(" AND "); | ||
| 299 | - let conditions: Vec<String> = ordered.into_iter().chain(extra).chain(cas).collect(); | ||
| 300 | let guard_sql = if conditions.is_empty() { | 252 | let guard_sql = if conditions.is_empty() { |
| 301 | String::new() | 253 | String::new() |
| 302 | } else { | 254 | } else { |
| @@ -320,7 +272,7 @@ impl FieldUpdate { | |||
| 320 | "SELECT 1 FROM {} WHERE id = ${id_at} AND {still_mine}{} \ | 272 | "SELECT 1 FROM {} WHERE id = ${id_at} AND {still_mine}{} \ |
| 321 | IS DISTINCT FROM ${} LIMIT 1", | 273 | IS DISTINCT FROM ${} LIMIT 1", |
| 322 | self.table, | 274 | self.table, |
| 323 | - rc.2, | 275 | + rc.link, |
| 324 | expected_at.expect("the CAS arms with its link"), | 276 | expected_at.expect("the CAS arms with its link"), |
| 325 | ); | 277 | ); |
| 326 | run_with_refcount(db, update, probe, binds, rc).await? | 278 | run_with_refcount(db, update, probe, binds, rc).await? |
| @@ -384,7 +336,7 @@ async fn run_with_refcount( | |||
| 384 | // lifted from an async fn's *pattern parameter* poisons the higher-ranked | 336 | // lifted from an async fn's *pattern parameter* poisons the higher-ranked |
| 385 | // `AsyncFnMut`/`Send` evaluation of any closure that captures it | 337 | // `AsyncFnMut`/`Send` evaluation of any closure that captures it |
| 386 | // ("`Send` would have to be implemented for `&'0 str`, for any lifetime"). | 338 | // ("`Send` would have to be implemented for `&'0 str`, for any lifetime"). |
| 387 | - let (counter_table, counter_field, _link, _expected, claim, release, refused) = refcount; | 339 | + let Refcount { counter_table, counter_field, claim, release, refused, .. } = refcount; |
| 388 | // Owned into the closure: a captured `&str` — even `'static` — drags the | 340 | // Owned into the closure: a captured `&str` — even `'static` — drags the |
| 389 | // async closure's arg lifetime off the higher-ranked one `tx_with_retry` | 341 | // async closure's arg lifetime off the higher-ranked one `tx_with_retry` |
| 390 | // needs ("AsyncFnMut is not general enough" at the route registration). | 342 | // needs ("AsyncFnMut is not general enough" at the route registration). |
| @@ -403,8 +355,7 @@ async fn run_with_refcount( | |||
| 403 | update.clone(), | 355 | update.clone(), |
| 404 | probe.clone(), | 356 | probe.clone(), |
| 405 | binds.clone(), | 357 | binds.clone(), |
| 406 | - &counter_table, | 358 | + (&counter_table, &counter_field), |
| 407 | - &counter_field, | ||
| 408 | claim, | 359 | claim, |
| 409 | release, | 360 | release, |
| 410 | ) | 361 | ) |
| @@ -427,17 +378,16 @@ async fn run_with_refcount( | |||
| 427 | /// One attempt of [`run_with_refcount`]'s transaction: the release, the | 378 | /// One attempt of [`run_with_refcount`]'s transaction: the release, the |
| 428 | /// claim, the guarded row write, and — on an empty write — the probe that | 379 | /// claim, the guarded row write, and — on an empty write — the probe that |
| 429 | /// tells a stale link apart from a row that is simply gone. | 380 | /// tells a stale link apart from a row that is simply gone. |
| 430 | -#[allow(clippy::too_many_arguments)] | ||
| 431 | async fn run_refcount_tx( | 381 | async fn run_refcount_tx( |
| 432 | tx: &mut PgConnection, | 382 | tx: &mut PgConnection, |
| 433 | update: String, | 383 | update: String, |
| 434 | probe: String, | 384 | probe: String, |
| 435 | binds: Vec<Param>, | 385 | binds: Vec<Param>, |
| 436 | - counter_table: &str, | 386 | + counter: (&str, &str), |
| 437 | - counter_field: &str, | ||
| 438 | claim: Option<Uuid>, | 387 | claim: Option<Uuid>, |
| 439 | release: Option<Uuid>, | 388 | release: Option<Uuid>, |
| 440 | ) -> Result<Vec<PgRow>, AppError> { | 389 | ) -> Result<Vec<PgRow>, AppError> { |
| 390 | + let (counter_table, counter_field) = counter; | ||
| 441 | if let Some(release) = release { | 391 | if let Some(release) = release { |
| 442 | sqlx::query(AssertSqlSafe(format!( | 392 | sqlx::query(AssertSqlSafe(format!( |
| 443 | "UPDATE {counter_table} \ | 393 | "UPDATE {counter_table} \ |
src/db/homework.rsmodified+12 -12
| @@ -55,12 +55,12 @@ pub async fn create( | |||
| 55 | let homework = Homework { | 55 | let homework = Homework { |
| 56 | id: HomeworkId::generate(), | 56 | id: HomeworkId::generate(), |
| 57 | course: course.clone(), | 57 | course: course.clone(), |
| 58 | - subject: subject.clone(), | 58 | + subject: *subject, |
| 59 | title, | 59 | title, |
| 60 | description, | 60 | description, |
| 61 | due_at, | 61 | due_at, |
| 62 | assigned, | 62 | assigned, |
| 63 | - created_by: created_by.clone(), | 63 | + created_by: *created_by, |
| 64 | created_at: Timestamp::now(), | 64 | created_at: Timestamp::now(), |
| 65 | }; | 65 | }; |
| 66 | let assigned_values: Vec<uuid::Uuid> = homework | 66 | let assigned_values: Vec<uuid::Uuid> = homework |
| @@ -337,7 +337,7 @@ pub async fn update( | |||
| 337 | // full-row write is exactly the request-scoped SET the old builder | 337 | // full-row write is exactly the request-scoped SET the old builder |
| 338 | // emitted — except it is one static statement instead of a runtime | 338 | // emitted — except it is one static statement instead of a runtime |
| 339 | // build. | 339 | // build. |
| 340 | - let new_subject = subject.clone().unwrap_or_else(|| current.subject.clone()); | 340 | + let new_subject = subject.unwrap_or(current.subject); |
| 341 | let new_title = title.clone().unwrap_or_else(|| current.title.clone()); | 341 | let new_title = title.clone().unwrap_or_else(|| current.title.clone()); |
| 342 | let new_description = match description.clone() { | 342 | let new_description = match description.clone() { |
| 343 | None => current.description.clone(), | 343 | None => current.description.clone(), |
| @@ -587,7 +587,7 @@ mod tests { | |||
| 587 | async fn a_refused_create_writes_neither_row_nor_count() { | 587 | async fn a_refused_create_writes_neither_row_nor_count() { |
| 588 | let (db, _leases) = crate::database::init_test_db().await; | 588 | let (db, _leases) = crate::database::init_test_db().await; |
| 589 | let subject = a_subject("algebra", &db).await; | 589 | let subject = a_subject("algebra", &db).await; |
| 590 | - let id = subject.get_id().clone(); | 590 | + let id = *subject.get_id(); |
| 591 | crate::db::subject::delete(&db, subject).await.unwrap(); | 591 | crate::db::subject::delete(&db, subject).await.unwrap(); |
| 592 | 592 | ||
| 593 | let error = create( | 593 | let error = create( |
| @@ -628,7 +628,7 @@ mod tests { | |||
| 628 | let moved = update( | 628 | let moved = update( |
| 629 | &db, | 629 | &db, |
| 630 | homework, | 630 | homework, |
| 631 | - Some(to.get_id().clone()), | 631 | + Some(*to.get_id()), |
| 632 | None, | 632 | None, |
| 633 | None, | 633 | None, |
| 634 | None, | 634 | None, |
| @@ -661,14 +661,14 @@ mod tests { | |||
| 661 | let (db, _leases) = crate::database::init_test_db().await; | 661 | let (db, _leases) = crate::database::init_test_db().await; |
| 662 | let from = a_subject("algebra", &db).await; | 662 | let from = a_subject("algebra", &db).await; |
| 663 | let dead = a_subject("geometry", &db).await; | 663 | let dead = a_subject("geometry", &db).await; |
| 664 | - let gone = dead.get_id().clone(); | 664 | + let gone = *dead.get_id(); |
| 665 | crate::db::subject::delete(&db, dead).await.unwrap(); | 665 | crate::db::subject::delete(&db, dead).await.unwrap(); |
| 666 | let homework = homework_on(from.get_id(), &db).await; | 666 | let homework = homework_on(from.get_id(), &db).await; |
| 667 | 667 | ||
| 668 | let error = update( | 668 | let error = update( |
| 669 | &db, | 669 | &db, |
| 670 | homework.clone(), | 670 | homework.clone(), |
| 671 | - Some(gone.clone()), | 671 | + Some(gone), |
| 672 | None, | 672 | None, |
| 673 | None, | 673 | None, |
| 674 | None, | 674 | None, |
| @@ -710,7 +710,7 @@ mod tests { | |||
| 710 | update( | 710 | update( |
| 711 | &db, | 711 | &db, |
| 712 | homework, | 712 | homework, |
| 713 | - Some(to.get_id().clone()), | 713 | + Some(*to.get_id()), |
| 714 | None, | 714 | None, |
| 715 | None, | 715 | None, |
| 716 | None, | 716 | None, |
| @@ -722,7 +722,7 @@ mod tests { | |||
| 722 | let error = update( | 722 | let error = update( |
| 723 | &db, | 723 | &db, |
| 724 | stale.clone(), | 724 | stale.clone(), |
| 725 | - Some(other.get_id().clone()), | 725 | + Some(*other.get_id()), |
| 726 | None, | 726 | None, |
| 727 | None, | 727 | None, |
| 728 | None, | 728 | None, |
| @@ -763,7 +763,7 @@ mod tests { | |||
| 763 | update( | 763 | update( |
| 764 | &db, | 764 | &db, |
| 765 | homework, | 765 | homework, |
| 766 | - Some(to.get_id().clone()), | 766 | + Some(*to.get_id()), |
| 767 | None, | 767 | None, |
| 768 | None, | 768 | None, |
| 769 | None, | 769 | None, |
| @@ -775,7 +775,7 @@ mod tests { | |||
| 775 | let error = update( | 775 | let error = update( |
| 776 | &db, | 776 | &db, |
| 777 | stale.clone(), | 777 | stale.clone(), |
| 778 | - Some(from.get_id().clone()), | 778 | + Some(*from.get_id()), |
| 779 | None, | 779 | None, |
| 780 | None, | 780 | None, |
| 781 | None, | 781 | None, |
| @@ -806,7 +806,7 @@ mod tests { | |||
| 806 | let same = update( | 806 | let same = update( |
| 807 | &db, | 807 | &db, |
| 808 | fresh, | 808 | fresh, |
| 809 | - Some(to.get_id().clone()), | 809 | + Some(*to.get_id()), |
| 810 | None, | 810 | None, |
| 811 | None, | 811 | None, |
| 812 | None, | 812 | None, |
src/db/homework_submission.rsmodified+1 -2
| @@ -444,7 +444,7 @@ mod tests { | |||
| 444 | .hash_async() | 444 | .hash_async() |
| 445 | .await | 445 | .await |
| 446 | .unwrap(); | 446 | .unwrap(); |
| 447 | - crate::db::user::create( | 447 | + *crate::db::user::create( |
| 448 | db, | 448 | db, |
| 449 | crate::domain::user::Username::try_new(username).unwrap(), | 449 | crate::domain::user::Username::try_new(username).unwrap(), |
| 450 | hash, | 450 | hash, |
| @@ -452,7 +452,6 @@ mod tests { | |||
| 452 | .await | 452 | .await |
| 453 | .unwrap() | 453 | .unwrap() |
| 454 | .get_id() | 454 | .get_id() |
| 455 | - .clone() | ||
| 456 | } | 455 | } |
| 457 | 456 | ||
| 458 | /// Move the stored deadline the way a teacher's PATCH does, leaving the | 457 | /// Move the stored deadline the way a teacher's PATCH does, leaving the |
src/db/meal_booking.rsmodified+6 -6
| @@ -226,7 +226,8 @@ pub(crate) async fn claim_and_place( | |||
| 226 | // No row (or a rival moved it past this attempt): place a | 226 | // No row (or a rival moved it past this attempt): place a |
| 227 | // fresh one. A rival that landed first answers `Duplicate` | 227 | // fresh one. A rival that landed first answers `Duplicate` |
| 228 | // — nothing here overwrites its row. | 228 | // — nothing here overwrites its row. |
| 229 | - let inserted = sqlx::query_as!( | 229 | + |
| 230 | + sqlx::query_as!( | ||
| 230 | MealBooking, | 231 | MealBooking, |
| 231 | "INSERT INTO meal_booking | 232 | "INSERT INTO meal_booking |
| 232 | (menu, student, booked_by, status, attempt, price_minor, cancelled_at, created_at) | 233 | (menu, student, booked_by, status, attempt, price_minor, cancelled_at, created_at) |
| @@ -243,8 +244,7 @@ pub(crate) async fn claim_and_place( | |||
| 243 | created_at, | 244 | created_at, |
| 244 | ) | 245 | ) |
| 245 | .fetch_optional(&mut *tx) | 246 | .fetch_optional(&mut *tx) |
| 246 | - .await?; | 247 | + .await? |
| 247 | - inserted | ||
| 248 | } | 248 | } |
| 249 | }; | 249 | }; |
| 250 | let Some(placed) = placed else { | 250 | let Some(placed) = placed else { |
| @@ -476,7 +476,7 @@ mod tests { | |||
| 476 | add_dish(&menu, 1_000, &db).await; | 476 | add_dish(&menu, 1_000, &db).await; |
| 477 | let row = MealBooking { | 477 | let row = MealBooking { |
| 478 | menu: menu.clone(), | 478 | menu: menu.clone(), |
| 479 | - student: ali.clone(), | 479 | + student: ali, |
| 480 | booked_by: ali, | 480 | booked_by: ali, |
| 481 | status: MealBookingStatus::Booked, | 481 | status: MealBookingStatus::Booked, |
| 482 | attempt: 1, | 482 | attempt: 1, |
| @@ -663,8 +663,8 @@ mod tests { | |||
| 663 | let seen = menu::read(&db, &menu).await.unwrap().unwrap().get_version(); | 663 | let seen = menu::read(&db, &menu).await.unwrap().unwrap().get_version(); |
| 664 | let row = MealBooking { | 664 | let row = MealBooking { |
| 665 | menu: menu.clone(), | 665 | menu: menu.clone(), |
| 666 | - student: ali.clone(), | 666 | + student: ali, |
| 667 | - booked_by: ali.clone(), | 667 | + booked_by: ali, |
| 668 | status: MealBookingStatus::Booked, | 668 | status: MealBookingStatus::Booked, |
| 669 | attempt: 1, | 669 | attempt: 1, |
| 670 | price_minor: price, | 670 | price_minor: price, |
src/db/note.rsmodified+1 -1
| @@ -17,7 +17,7 @@ pub async fn create( | |||
| 17 | ) -> Result<Note, AppError> { | 17 | ) -> Result<Note, AppError> { |
| 18 | let note = Note { | 18 | let note = Note { |
| 19 | id: NoteId::generate(), | 19 | id: NoteId::generate(), |
| 20 | - user: owner.clone(), | 20 | + user: *owner, |
| 21 | title, | 21 | title, |
| 22 | content, | 22 | content, |
| 23 | }; | 23 | }; |
src/db/payment_ledger.rsmodified+2 -2
| @@ -135,14 +135,14 @@ pub async fn charge_for_installment( | |||
| 135 | exe, | 135 | exe, |
| 136 | PaymentLedger { | 136 | PaymentLedger { |
| 137 | id: PaymentLedgerId::for_installment(&assignment.get_id(), n), | 137 | id: PaymentLedgerId::for_installment(&assignment.get_id(), n), |
| 138 | - student: assignment.get_student().clone(), | 138 | + student: *assignment.get_student(), |
| 139 | kind: PaymentLedgerKind::Charge, | 139 | kind: PaymentLedgerKind::Charge, |
| 140 | amount_minor: installment.get_amount_minor(), | 140 | amount_minor: installment.get_amount_minor(), |
| 141 | source: Some(assignment.get_id().key()), | 141 | source: Some(assignment.get_id().key()), |
| 142 | due_at: Some(installment.get_due_at()), | 142 | due_at: Some(installment.get_due_at()), |
| 143 | method: None, | 143 | method: None, |
| 144 | note: None, | 144 | note: None, |
| 145 | - recorded_by: recorded_by.clone(), | 145 | + recorded_by: *recorded_by, |
| 146 | created_at: Timestamp::now(), | 146 | created_at: Timestamp::now(), |
| 147 | }, | 147 | }, |
| 148 | ) | 148 | ) |
src/db/pomodoro.rsmodified+1 -1
| @@ -437,7 +437,7 @@ mod tests { | |||
| 437 | for round in 1..=20 { | 437 | for round in 1..=20 { |
| 438 | let racers: Vec<_> = (0..4) | 438 | let racers: Vec<_> = (0..4) |
| 439 | .map(|_| { | 439 | .map(|_| { |
| 440 | - let (user, db) = (user.clone(), db.clone()); | 440 | + let (user, db) = (user, db.clone()); |
| 441 | tokio::spawn(async move { | 441 | tokio::spawn(async move { |
| 442 | // Aged past the minimum, so whichever racer wins the | 442 | // Aged past the minimum, so whichever racer wins the |
| 443 | // open row closes a stint that *counts* — a fresh | 443 | // open row closes a stint that *counts* — a fresh |
src/db/pool_question.rsmodified+5 -6
| @@ -152,8 +152,8 @@ pub async fn approve( | |||
| 152 | ) | 152 | ) |
| 153 | .fetch_optional(&mut *tx) | 153 | .fetch_optional(&mut *tx) |
| 154 | .await?; | 154 | .await?; |
| 155 | - if let Some(question) = &approved { | 155 | + if let Some(question) = &approved |
| 156 | - if question.asker != approver { | 156 | + && question.asker != approver { |
| 157 | // The counter columns are NOT NULL DEFAULT 0 — the old | 157 | // The counter columns are NOT NULL DEFAULT 0 — the old |
| 158 | // absent-reads-as-zero coalesce is gone with the schema. | 158 | // absent-reads-as-zero coalesce is gone with the schema. |
| 159 | sqlx::query!( | 159 | sqlx::query!( |
| @@ -171,7 +171,6 @@ pub async fn approve( | |||
| 171 | .execute(&mut *tx) | 171 | .execute(&mut *tx) |
| 172 | .await?; | 172 | .await?; |
| 173 | } | 173 | } |
| 174 | - } | ||
| 175 | Ok(approved) | 174 | Ok(approved) |
| 176 | }) | 175 | }) |
| 177 | .await | 176 | .await |
| @@ -586,20 +585,20 @@ mod tests { | |||
| 586 | let asker = a_user(&db).await; | 585 | let asker = a_user(&db).await; |
| 587 | let helper = a_user(&db).await; | 586 | let helper = a_user(&db).await; |
| 588 | let q = insert(&db, question(&asker)).await.unwrap(); | 587 | let q = insert(&db, question(&asker)).await.unwrap(); |
| 589 | - let id = q.get_id().clone(); | 588 | + let id = *q.get_id(); |
| 590 | 589 | ||
| 591 | // Delete and offer released together: both write the question row, | 590 | // Delete and offer released together: both write the question row, |
| 592 | // so Postgres serializes them and refuses whichever lost. | 591 | // so Postgres serializes them and refuses whichever lost. |
| 593 | let gate = std::sync::Arc::new(tokio::sync::Barrier::new(2)); | 592 | let gate = std::sync::Arc::new(tokio::sync::Barrier::new(2)); |
| 594 | let drop_it = { | 593 | let drop_it = { |
| 595 | - let (db, id, gate) = (db.clone(), id.clone(), gate.clone()); | 594 | + let (db, id, gate) = (db.clone(), id, gate.clone()); |
| 596 | tokio::spawn(async move { | 595 | tokio::spawn(async move { |
| 597 | gate.wait().await; | 596 | gate.wait().await; |
| 598 | delete(&db, &id).await | 597 | delete(&db, &id).await |
| 599 | }) | 598 | }) |
| 600 | }; | 599 | }; |
| 601 | let child = { | 600 | let child = { |
| 602 | - let (db, id, helper, gate) = (db.clone(), id.clone(), helper.clone(), gate); | 601 | + let (db, id, helper, gate) = (db.clone(), id, helper, gate); |
| 603 | tokio::spawn(async move { | 602 | tokio::spawn(async move { |
| 604 | gate.wait().await; | 603 | gate.wait().await; |
| 605 | crate::db::solution::insert( | 604 | crate::db::solution::insert( |
src/db/profile.rsmodified+0 -7
| @@ -9,13 +9,6 @@ use crate::domain::profile::ProfileStats; | |||
| 9 | use crate::domain::user::UserId; | 9 | use crate::domain::user::UserId; |
| 10 | use crate::error::AppError; | 10 | use crate::error::AppError; |
| 11 | 11 | ||
| 12 | -/// The aggregate row of [`load`]. | ||
| 13 | -#[derive(Debug)] | ||
| 14 | -struct PomodoroTotals { | ||
| 15 | - sessions: i64, | ||
| 16 | - focus_ms: i64, | ||
| 17 | -} | ||
| 18 | - | ||
| 19 | /// One round trip, and only one: `courses` and `classes` arrive from the | 12 | /// One round trip, and only one: `courses` and `classes` arrive from the |
| 20 | /// caller, which already holds them as the `total` of the paged class and | 13 | /// caller, which already holds them as the `total` of the paged class and |
| 21 | /// course readers it ran for the profile's own blocks — re-counting them | 14 | /// course readers it ran for the profile's own blocks — re-counting them |
src/db/question_image.rsmodified+1 -1
| @@ -277,7 +277,7 @@ mod tests { | |||
| 277 | crate::db::exam_question::create( | 277 | crate::db::exam_question::create( |
| 278 | db, | 278 | db, |
| 279 | exam, | 279 | exam, |
| 280 | - subject.get_id().clone(), | 280 | + *subject.get_id(), |
| 281 | QuestionText::try_new("pick one").unwrap(), | 281 | QuestionText::try_new("pick one").unwrap(), |
| 282 | QuestionPoints::try_new(1).unwrap(), | 282 | QuestionPoints::try_new(1).unwrap(), |
| 283 | spec, | 283 | spec, |
src/db/session.rsmodified+2 -2
| @@ -17,7 +17,7 @@ pub async fn create(db: &Database, user: &UserId) -> Result<Session, AppError> { | |||
| 17 | Session, | 17 | Session, |
| 18 | r#"INSERT INTO user_session (id, app_user, token, expires_at) | 18 | r#"INSERT INTO user_session (id, app_user, token, expires_at) |
| 19 | VALUES ($1, $2, $3, $4) | 19 | VALUES ($1, $2, $3, $4) |
| 20 | - RETURNING id AS "id: SessionId", | 20 | + RETURNING |
| 21 | app_user AS "user: UserId", | 21 | app_user AS "user: UserId", |
| 22 | token AS "token: SessionToken", | 22 | token AS "token: SessionToken", |
| 23 | expires_at AS "expires_at: Timestamp""#, | 23 | expires_at AS "expires_at: Timestamp""#, |
| @@ -34,7 +34,7 @@ pub async fn create(db: &Database, user: &UserId) -> Result<Session, AppError> { | |||
| 34 | pub async fn find_by_token(db: &Database, token: &str) -> Result<Option<Session>, AppError> { | 34 | pub async fn find_by_token(db: &Database, token: &str) -> Result<Option<Session>, AppError> { |
| 35 | let session = sqlx::query_as!( | 35 | let session = sqlx::query_as!( |
| 36 | Session, | 36 | Session, |
| 37 | - r#"SELECT id AS "id: SessionId", | 37 | + r#"SELECT |
| 38 | app_user AS "user: UserId", | 38 | app_user AS "user: UserId", |
| 39 | token AS "token: SessionToken", | 39 | token AS "token: SessionToken", |
| 40 | expires_at AS "expires_at: Timestamp" | 40 | expires_at AS "expires_at: Timestamp" |
src/db/session_attendance.rsmodified+1 -1
| @@ -682,7 +682,7 @@ mod tests { | |||
| 682 | }) | 682 | }) |
| 683 | }; | 683 | }; |
| 684 | let marked = { | 684 | let marked = { |
| 685 | - let (db, teacher, gate) = (db.clone(), teacher.clone(), gate); | 685 | + let (db, teacher, gate) = (db.clone(), teacher, gate); |
| 686 | let student = a_student(&format!("s{round}"), &db).await; | 686 | let student = a_student(&format!("s{round}"), &db).await; |
| 687 | tokio::spawn(async move { | 687 | tokio::spawn(async move { |
| 688 | gate.wait().await; | 688 | gate.wait().await; |
src/db/settings.rsmodified+3 -3
| @@ -11,7 +11,7 @@ use crate::error::AppError; | |||
| 11 | pub async fn load(db: &Database) -> Result<Settings, AppError> { | 11 | pub async fn load(db: &Database) -> Result<Settings, AppError> { |
| 12 | let settings = sqlx::query_as!( | 12 | let settings = sqlx::query_as!( |
| 13 | Settings, | 13 | Settings, |
| 14 | - r#"SELECT id, | 14 | + r#"SELECT |
| 15 | exam_kinds AS "exam_kinds: Json<Vec<ExamKindDef>>", | 15 | exam_kinds AS "exam_kinds: Json<Vec<ExamKindDef>>", |
| 16 | attendance_statuses, | 16 | attendance_statuses, |
| 17 | grade_bands AS "grade_bands: Json<Vec<GradeBand>>", | 17 | grade_bands AS "grade_bands: Json<Vec<GradeBand>>", |
| @@ -62,7 +62,7 @@ pub async fn save(db: &Database, settings: Settings) -> Result<Settings, AppErro | |||
| 62 | meal_slots = EXCLUDED.meal_slots, | 62 | meal_slots = EXCLUDED.meal_slots, |
| 63 | dietary_tags = EXCLUDED.dietary_tags, | 63 | dietary_tags = EXCLUDED.dietary_tags, |
| 64 | meal_cancel_cutoff_minutes = EXCLUDED.meal_cancel_cutoff_minutes | 64 | meal_cancel_cutoff_minutes = EXCLUDED.meal_cancel_cutoff_minutes |
| 65 | - RETURNING id, | 65 | + RETURNING |
| 66 | exam_kinds AS "exam_kinds: Json<Vec<ExamKindDef>>", | 66 | exam_kinds AS "exam_kinds: Json<Vec<ExamKindDef>>", |
| 67 | attendance_statuses, | 67 | attendance_statuses, |
| 68 | grade_bands AS "grade_bands: Json<Vec<GradeBand>>", | 68 | grade_bands AS "grade_bands: Json<Vec<GradeBand>>", |
| @@ -172,7 +172,7 @@ where | |||
| 172 | AND settings.meal_slots IS NOT DISTINCT FROM $18 | 172 | AND settings.meal_slots IS NOT DISTINCT FROM $18 |
| 173 | AND settings.dietary_tags IS NOT DISTINCT FROM $19 | 173 | AND settings.dietary_tags IS NOT DISTINCT FROM $19 |
| 174 | AND settings.meal_cancel_cutoff_minutes IS NOT DISTINCT FROM $20 | 174 | AND settings.meal_cancel_cutoff_minutes IS NOT DISTINCT FROM $20 |
| 175 | - RETURNING id, | 175 | + RETURNING |
| 176 | exam_kinds AS "exam_kinds: Json<Vec<ExamKindDef>>", | 176 | exam_kinds AS "exam_kinds: Json<Vec<ExamKindDef>>", |
| 177 | attendance_statuses, | 177 | attendance_statuses, |
| 178 | grade_bands AS "grade_bands: Json<Vec<GradeBand>>", | 178 | grade_bands AS "grade_bands: Json<Vec<GradeBand>>", |
src/db/solution.rsmodified+2 -3
| @@ -280,7 +280,7 @@ mod tests { | |||
| 280 | /// so a minted id nothing wrote is a 404. | 280 | /// so a minted id nothing wrote is a 404. |
| 281 | async fn question_row(db: &Database) -> PoolQuestionId { | 281 | async fn question_row(db: &Database) -> PoolQuestionId { |
| 282 | let asker = a_person(db, "asker").await; | 282 | let asker = a_person(db, "asker").await; |
| 283 | - crate::db::pool_question::insert( | 283 | + *crate::db::pool_question::insert( |
| 284 | db, | 284 | db, |
| 285 | PoolQuestion::new( | 285 | PoolQuestion::new( |
| 286 | &asker, | 286 | &asker, |
| @@ -291,7 +291,6 @@ mod tests { | |||
| 291 | .await | 291 | .await |
| 292 | .unwrap() | 292 | .unwrap() |
| 293 | .get_id() | 293 | .get_id() |
| 294 | - .clone() | ||
| 295 | } | 294 | } |
| 296 | 295 | ||
| 297 | #[tokio::test] | 296 | #[tokio::test] |
| @@ -474,7 +473,7 @@ mod tests { | |||
| 474 | } | 473 | } |
| 475 | } | 474 | } |
| 476 | 475 | ||
| 477 | - let counts = counts_for(&db, &[two.clone(), one.clone(), none.clone()]) | 476 | + let counts = counts_for(&db, &[two, one, none]) |
| 478 | .await | 477 | .await |
| 479 | .unwrap(); | 478 | .unwrap(); |
| 480 | assert_eq!(counts.get(two.key().as_str()), Some(&2)); | 479 | assert_eq!(counts.get(two.key().as_str()), Some(&2)); |
src/db/subject.rsmodified+1 -1
| @@ -291,7 +291,7 @@ mod tests { | |||
| 291 | }; | 291 | }; |
| 292 | let asks: Vec<_> = (0..6) | 292 | let asks: Vec<_> = (0..6) |
| 293 | .map(|_| { | 293 | .map(|_| { |
| 294 | - let (id, db, exam) = (subject.get_id().clone(), db.clone(), exam.clone()); | 294 | + let (id, db, exam) = (*subject.get_id(), db.clone(), exam.clone()); |
| 295 | let head_start = if separated { | 295 | let head_start = if separated { |
| 296 | std::time::Duration::from_millis(2) | 296 | std::time::Duration::from_millis(2) |
| 297 | } else { | 297 | } else { |
src/db/term.rsmodified+1 -1
| @@ -312,7 +312,7 @@ mod tests { | |||
| 312 | }; | 312 | }; |
| 313 | let makes: Vec<_> = (0..6) | 313 | let makes: Vec<_> = (0..6) |
| 314 | .map(|_| { | 314 | .map(|_| { |
| 315 | - let (id, db, teacher) = (term.get_id().clone(), db.clone(), teacher.clone()); | 315 | + let (id, db, teacher) = (*term.get_id(), db.clone(), teacher); |
| 316 | let head_start = if separated { | 316 | let head_start = if separated { |
| 317 | std::time::Duration::from_millis(2) | 317 | std::time::Duration::from_millis(2) |
| 318 | } else { | 318 | } else { |
src/domain/answer_image.rsmodified+2 -2
| @@ -37,7 +37,7 @@ impl AnswerImageId { | |||
| 37 | pub fn composite(question: &ExamQuestionId, user: &UserId, seq: i64) -> Self { | 37 | pub fn composite(question: &ExamQuestionId, user: &UserId, seq: i64) -> Self { |
| 38 | Self { | 38 | Self { |
| 39 | question: question.clone(), | 39 | question: question.clone(), |
| 40 | - user: user.clone(), | 40 | + user: *user, |
| 41 | seq, | 41 | seq, |
| 42 | } | 42 | } |
| 43 | } | 43 | } |
| @@ -87,7 +87,7 @@ impl AnswerImage { | |||
| 87 | Self { | 87 | Self { |
| 88 | exam: exam.clone(), | 88 | exam: exam.clone(), |
| 89 | question: question.clone(), | 89 | question: question.clone(), |
| 90 | - user: user.clone(), | 90 | + user: *user, |
| 91 | seq, | 91 | seq, |
| 92 | file: uuid::Uuid::new_v4().to_string(), | 92 | file: uuid::Uuid::new_v4().to_string(), |
| 93 | content_type, | 93 | content_type, |
src/domain/attendance.rsmodified+1 -1
| @@ -17,7 +17,7 @@ impl AttendanceId { | |||
| 17 | pub fn composite(event: &EventId, user: &UserId) -> Self { | 17 | pub fn composite(event: &EventId, user: &UserId) -> Self { |
| 18 | Self { | 18 | Self { |
| 19 | event: event.clone(), | 19 | event: event.clone(), |
| 20 | - user: user.clone(), | 20 | + user: *user, |
| 21 | } | 21 | } |
| 22 | } | 22 | } |
| 23 | 23 | ||
src/domain/board.rsmodified+1 -1
| @@ -201,7 +201,7 @@ mod tests { | |||
| 201 | #[test] | 201 | #[test] |
| 202 | fn participants_are_deduplicated_and_bounded() { | 202 | fn participants_are_deduplicated_and_bounded() { |
| 203 | let one = user("0198f1a2-3b4c-7d5e-8f90-bbbb3c4d5e6f"); | 203 | let one = user("0198f1a2-3b4c-7d5e-8f90-bbbb3c4d5e6f"); |
| 204 | - assert_eq!(checked_participants(vec![one.clone(), one]).unwrap().len(), 1); | 204 | + assert_eq!(checked_participants(vec![one, one]).unwrap().len(), 1); |
| 205 | // One over the ceiling is refused; each key must be a distinct | 205 | // One over the ceiling is refused; each key must be a distinct |
| 206 | // *parseable* UUID, or the parser would collapse them all to nil. | 206 | // *parseable* UUID, or the parser would collapse them all to nil. |
| 207 | let many = (0..=MAX_BOARD_PARTICIPANTS) | 207 | let many = (0..=MAX_BOARD_PARTICIPANTS) |
src/domain/builder.rsmodified+0 -2
| @@ -73,10 +73,8 @@ impl Builder { | |||
| 73 | /// are the same 64 hex chars. | 73 | /// are the same 64 hex chars. |
| 74 | #[derive(Debug, Clone, sqlx::FromRow)] | 74 | #[derive(Debug, Clone, sqlx::FromRow)] |
| 75 | pub struct BuilderSession { | 75 | pub struct BuilderSession { |
| 76 | - pub(crate) id: Uuid, | ||
| 77 | pub(crate) builder: BuilderId, | 76 | pub(crate) builder: BuilderId, |
| 78 | pub(crate) token: SessionToken, | 77 | pub(crate) token: SessionToken, |
| 79 | - pub(crate) created_at: Timestamp, | ||
| 80 | pub(crate) expires_at: Timestamp, | 78 | pub(crate) expires_at: Timestamp, |
| 81 | } | 79 | } |
| 82 | 80 | ||
src/domain/class_course.rsmodified+0 -6
| @@ -10,7 +10,6 @@ | |||
| 10 | use crate::domain::class_blueprint::ClassBlueprintId; | 10 | use crate::domain::class_blueprint::ClassBlueprintId; |
| 11 | use crate::domain::class_group::ClassGroupId; | 11 | use crate::domain::class_group::ClassGroupId; |
| 12 | use crate::domain::course::CourseId; | 12 | use crate::domain::course::CourseId; |
| 13 | -use crate::domain::timestamp::Timestamp; | ||
| 14 | use crate::domain::user::UserId; | 13 | use crate::domain::user::UserId; |
| 15 | 14 | ||
| 16 | /// The identity of one (class, course) pair. Not a row column: the table's | 15 | /// The identity of one (class, course) pair. Not a row column: the table's |
| @@ -49,11 +48,6 @@ pub struct ClassCourse { | |||
| 49 | /// row carrying the key is a blueprint's to take back, so a hand-attached | 48 | /// row carrying the key is a blueprint's to take back, so a hand-attached |
| 50 | /// course survives every blueprint sweep. | 49 | /// course survives every blueprint sweep. |
| 51 | pub(crate) source: Option<ClassBlueprintId>, | 50 | pub(crate) source: Option<ClassBlueprintId>, |
| 52 | - /// When it was attached, and the *only* thing "newest first" can mean | ||
| 53 | - /// here: the row's primary key is the (class, course) pair, so ordering | ||
| 54 | - /// falls to this stamp (or the attached course's id). Optional because | ||
| 55 | - /// rows written before this column carry no stamp. | ||
| 56 | - pub(crate) attached_at: Option<Timestamp>, | ||
| 57 | } | 51 | } |
| 58 | 52 | ||
| 59 | impl ClassCourse { | 53 | impl ClassCourse { |
src/domain/class_member.rsmodified+1 -7
| @@ -8,7 +8,6 @@ | |||
| 8 | //! composite id. | 8 | //! composite id. |
| 9 | 9 | ||
| 10 | use crate::domain::class_group::ClassGroupId; | 10 | use crate::domain::class_group::ClassGroupId; |
| 11 | -use crate::domain::timestamp::Timestamp; | ||
| 12 | use crate::domain::user::UserId; | 11 | use crate::domain::user::UserId; |
| 13 | 12 | ||
| 14 | /// The identity of one (class, user) pair. Not a row column: the table's | 13 | /// The identity of one (class, user) pair. Not a row column: the table's |
| @@ -25,7 +24,7 @@ impl ClassMemberId { | |||
| 25 | pub fn composite(class: &ClassGroupId, user: &UserId) -> Self { | 24 | pub fn composite(class: &ClassGroupId, user: &UserId) -> Self { |
| 26 | Self { | 25 | Self { |
| 27 | class: class.clone(), | 26 | class: class.clone(), |
| 28 | - user: user.clone(), | 27 | + user: *user, |
| 29 | } | 28 | } |
| 30 | } | 29 | } |
| 31 | 30 | ||
| @@ -44,11 +43,6 @@ pub struct ClassMember { | |||
| 44 | #[sqlx(rename = "app_user")] | 43 | #[sqlx(rename = "app_user")] |
| 45 | pub(crate) user: UserId, | 44 | pub(crate) user: UserId, |
| 46 | pub(crate) added_by: UserId, | 45 | pub(crate) added_by: UserId, |
| 47 | - /// When they were added, and the *only* thing "newest first" can mean | ||
| 48 | - /// here: the row's primary key is the (class, user) pair, so ordering | ||
| 49 | - /// falls to this stamp. Optional because rows written before this column | ||
| 50 | - /// carry no stamp. | ||
| 51 | - pub(crate) added_at: Option<Timestamp>, | ||
| 52 | } | 46 | } |
| 53 | 47 | ||
| 54 | impl ClassMember { | 48 | impl ClassMember { |
src/domain/dietary_profile.rsmodified+1 -1
| @@ -31,7 +31,7 @@ pub struct DietaryProfileId { | |||
| 31 | impl DietaryProfileId { | 31 | impl DietaryProfileId { |
| 32 | pub fn of(student: &UserId) -> Self { | 32 | pub fn of(student: &UserId) -> Self { |
| 33 | Self { | 33 | Self { |
| 34 | - student: student.clone(), | 34 | + student: *student, |
| 35 | } | 35 | } |
| 36 | } | 36 | } |
| 37 | 37 | ||
src/domain/enrollment.rsmodified+1 -1
| @@ -17,7 +17,7 @@ impl EnrollmentId { | |||
| 17 | pub fn composite(course: &CourseId, user: &UserId) -> Self { | 17 | pub fn composite(course: &CourseId, user: &UserId) -> Self { |
| 18 | Self { | 18 | Self { |
| 19 | course: course.clone(), | 19 | course: course.clone(), |
| 20 | - user: user.clone(), | 20 | + user: *user, |
| 21 | } | 21 | } |
| 22 | } | 22 | } |
| 23 | 23 | ||
src/domain/exam_answer.rsmodified+2 -2
| @@ -24,7 +24,7 @@ impl ExamAnswerId { | |||
| 24 | pub fn composite(question: &ExamQuestionId, user: &UserId, seq: i64) -> Self { | 24 | pub fn composite(question: &ExamQuestionId, user: &UserId, seq: i64) -> Self { |
| 25 | Self { | 25 | Self { |
| 26 | question: question.clone(), | 26 | question: question.clone(), |
| 27 | - user: user.clone(), | 27 | + user: *user, |
| 28 | seq, | 28 | seq, |
| 29 | } | 29 | } |
| 30 | } | 30 | } |
| @@ -180,7 +180,7 @@ mod tests { | |||
| 180 | ExamAnswer { | 180 | ExamAnswer { |
| 181 | exam: question.get_exam().clone(), | 181 | exam: question.get_exam().clone(), |
| 182 | question: question.get_id().clone(), | 182 | question: question.get_id().clone(), |
| 183 | - user: user.clone(), | 183 | + user: *user, |
| 184 | seq: 1, | 184 | seq: 1, |
| 185 | text: selected | 185 | text: selected |
| 186 | .is_none() | 186 | .is_none() |
src/domain/exam_attempt.rsmodified+1 -1
| @@ -19,7 +19,7 @@ impl ExamAttemptId { | |||
| 19 | pub fn composite(exam: &ExamId, user: &UserId, seq: i64) -> Self { | 19 | pub fn composite(exam: &ExamId, user: &UserId, seq: i64) -> Self { |
| 20 | Self { | 20 | Self { |
| 21 | exam: exam.clone(), | 21 | exam: exam.clone(), |
| 22 | - user: user.clone(), | 22 | + user: *user, |
| 23 | seq, | 23 | seq, |
| 24 | } | 24 | } |
| 25 | } | 25 | } |
src/domain/exam_result.rsmodified+4 -4
| @@ -40,7 +40,7 @@ impl ExamResultId { | |||
| 40 | pub fn composite(exam: &ExamId, user: &UserId, seq: i64) -> Self { | 40 | pub fn composite(exam: &ExamId, user: &UserId, seq: i64) -> Self { |
| 41 | Self { | 41 | Self { |
| 42 | exam: exam.clone(), | 42 | exam: exam.clone(), |
| 43 | - user: user.clone(), | 43 | + user: *user, |
| 44 | seq, | 44 | seq, |
| 45 | } | 45 | } |
| 46 | } | 46 | } |
| @@ -163,9 +163,9 @@ mod tests { | |||
| 163 | }; | 163 | }; |
| 164 | 164 | ||
| 165 | let got = latest_per_pair(vec![ | 165 | let got = latest_per_pair(vec![ |
| 166 | - row(user.clone(), 1, 60), | 166 | + row(user, 1, 60), |
| 167 | - row(other.clone(), 1, 70), | 167 | + row(other, 1, 70), |
| 168 | - row(user.clone(), 2, 85), // retake outranks the seq-1 mark | 168 | + row(user, 2, 85), // retake outranks the seq-1 mark |
| 169 | row(other, 3, 40), // third sitting of the second pair | 169 | row(other, 3, 40), // third sitting of the second pair |
| 170 | ]); | 170 | ]); |
| 171 | assert_eq!(got.len(), 2); | 171 | assert_eq!(got.len(), 2); |
src/domain/fee_plan_assignment.rsmodified+1 -1
| @@ -32,7 +32,7 @@ impl FeePlanAssignmentId { | |||
| 32 | pub fn composite(plan: &FeePlanId, student: &UserId) -> Self { | 32 | pub fn composite(plan: &FeePlanId, student: &UserId) -> Self { |
| 33 | Self { | 33 | Self { |
| 34 | plan: plan.clone(), | 34 | plan: plan.clone(), |
| 35 | - student: student.clone(), | 35 | + student: *student, |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | 38 | ||
src/domain/homework.rsmodified+3 -3
| @@ -182,14 +182,14 @@ mod tests { | |||
| 182 | description: None, | 182 | description: None, |
| 183 | due_at: Timestamp::from_millis(1), | 183 | due_at: Timestamp::from_millis(1), |
| 184 | assigned, | 184 | assigned, |
| 185 | - created_by: a.clone(), | 185 | + created_by: a, |
| 186 | created_at: Timestamp::from_millis(1), | 186 | created_at: Timestamp::from_millis(1), |
| 187 | }; | 187 | }; |
| 188 | // Whole course: NULL or empty list means everyone sees it. | 188 | // Whole course: NULL or empty list means everyone sees it. |
| 189 | assert!(with(None).student_sees(&a)); | 189 | assert!(with(None).student_sees(&a)); |
| 190 | assert!(with(Some(vec![])).student_sees(&b)); | 190 | assert!(with(Some(vec![])).student_sees(&b)); |
| 191 | // Subset: only the named students. | 191 | // Subset: only the named students. |
| 192 | - assert!(with(Some(vec![a.clone()])).student_sees(&a)); | 192 | + assert!(with(Some(vec![a])).student_sees(&a)); |
| 193 | - assert!(!with(Some(vec![a.clone()])).student_sees(&b)); | 193 | + assert!(!with(Some(vec![a])).student_sees(&b)); |
| 194 | } | 194 | } |
| 195 | } | 195 | } |
src/domain/meal_booking.rsmodified+1 -1
| @@ -424,7 +424,7 @@ mod tests { | |||
| 424 | let mut buf = sqlx::postgres::PgArgumentBuffer::default(); | 424 | let mut buf = sqlx::postgres::PgArgumentBuffer::default(); |
| 425 | for status in [MealBookingStatus::Booked, MealBookingStatus::Cancelled] { | 425 | for status in [MealBookingStatus::Booked, MealBookingStatus::Cancelled] { |
| 426 | buf.clear(); | 426 | buf.clear(); |
| 427 | - sqlx::Encode::<sqlx::Postgres>::encode_by_ref(&status, &mut buf); | 427 | + let _ = sqlx::Encode::<sqlx::Postgres>::encode_by_ref(&status, &mut buf).unwrap(); |
| 428 | assert_eq!(std::str::from_utf8(&buf).unwrap(), status.as_str()); | 428 | assert_eq!(std::str::from_utf8(&buf).unwrap(), status.as_str()); |
| 429 | } | 429 | } |
| 430 | } | 430 | } |
src/domain/meal_ledger.rsmodified+5 -5
| @@ -294,13 +294,13 @@ impl MealLedger { | |||
| 294 | booking.get_attempt(), | 294 | booking.get_attempt(), |
| 295 | MealLedgerKind::Charge, | 295 | MealLedgerKind::Charge, |
| 296 | ), | 296 | ), |
| 297 | - student: booking.get_student().clone(), | 297 | + student: *booking.get_student(), |
| 298 | kind: MealLedgerKind::Charge, | 298 | kind: MealLedgerKind::Charge, |
| 299 | amount_minor: amount, | 299 | amount_minor: amount, |
| 300 | source: Some(booking.id().key()), | 300 | source: Some(booking.id().key()), |
| 301 | method: None, | 301 | method: None, |
| 302 | note: None, | 302 | note: None, |
| 303 | - recorded_by: recorded_by.clone(), | 303 | + recorded_by: *recorded_by, |
| 304 | created_at: Timestamp::now(), | 304 | created_at: Timestamp::now(), |
| 305 | }) | 305 | }) |
| 306 | } | 306 | } |
| @@ -330,13 +330,13 @@ impl MealLedger { | |||
| 330 | booking.get_attempt(), | 330 | booking.get_attempt(), |
| 331 | MealLedgerKind::Reversal, | 331 | MealLedgerKind::Reversal, |
| 332 | ), | 332 | ), |
| 333 | - student: booking.get_student().clone(), | 333 | + student: *booking.get_student(), |
| 334 | kind: MealLedgerKind::Reversal, | 334 | kind: MealLedgerKind::Reversal, |
| 335 | amount_minor: amount, | 335 | amount_minor: amount, |
| 336 | source: Some(charge.key().to_string()), | 336 | source: Some(charge.key().to_string()), |
| 337 | method: None, | 337 | method: None, |
| 338 | note: None, | 338 | note: None, |
| 339 | - recorded_by: recorded_by.clone(), | 339 | + recorded_by: *recorded_by, |
| 340 | created_at: Timestamp::now(), | 340 | created_at: Timestamp::now(), |
| 341 | }; | 341 | }; |
| 342 | Some((charge, line)) | 342 | Some((charge, line)) |
| @@ -360,7 +360,7 @@ mod tests { | |||
| 360 | MealLedgerKind::Reversal, | 360 | MealLedgerKind::Reversal, |
| 361 | ] { | 361 | ] { |
| 362 | buf.clear(); | 362 | buf.clear(); |
| 363 | - sqlx::Encode::<sqlx::Postgres>::encode_by_ref(&kind, &mut buf); | 363 | + let _ = sqlx::Encode::<sqlx::Postgres>::encode_by_ref(&kind, &mut buf).unwrap(); |
| 364 | assert_eq!(std::str::from_utf8(&buf).unwrap(), kind.as_str()); | 364 | assert_eq!(std::str::from_utf8(&buf).unwrap(), kind.as_str()); |
| 365 | } | 365 | } |
| 366 | } | 366 | } |
src/domain/message.rsmodified+3 -3
| @@ -264,8 +264,8 @@ mod tests { | |||
| 264 | let recipient = UserId::from_key("018f1a00-0000-7000-8000-000000000002"); | 264 | let recipient = UserId::from_key("018f1a00-0000-7000-8000-000000000002"); |
| 265 | let message = Message { | 265 | let message = Message { |
| 266 | id: MessageId::generate(), | 266 | id: MessageId::generate(), |
| 267 | - sender: sender.clone(), | 267 | + sender, |
| 268 | - recipient: recipient.clone(), | 268 | + recipient, |
| 269 | subject: MessageSubject::try_new("s").unwrap(), | 269 | subject: MessageSubject::try_new("s").unwrap(), |
| 270 | body: MessageBody::try_new("").unwrap(), | 270 | body: MessageBody::try_new("").unwrap(), |
| 271 | label: None, | 271 | label: None, |
| @@ -310,7 +310,7 @@ mod tests { | |||
| 310 | Folder::Deleted, | 310 | Folder::Deleted, |
| 311 | ] { | 311 | ] { |
| 312 | buf.clear(); | 312 | buf.clear(); |
| 313 | - sqlx::Encode::<sqlx::Postgres>::encode_by_ref(&folder, &mut buf); | 313 | + let _ = sqlx::Encode::<sqlx::Postgres>::encode_by_ref(&folder, &mut buf).unwrap(); |
| 314 | assert_eq!(std::str::from_utf8(&buf).unwrap(), folder.as_str()); | 314 | assert_eq!(std::str::from_utf8(&buf).unwrap(), folder.as_str()); |
| 315 | } | 315 | } |
| 316 | } | 316 | } |
src/domain/note_file.rsmodified+1 -1
| @@ -138,7 +138,7 @@ impl NoteFile { | |||
| 138 | pub fn new(note: &NoteId, name: FileName, content_type: FileContentType, size: i64) -> Self { | 138 | pub fn new(note: &NoteId, name: FileName, content_type: FileContentType, size: i64) -> Self { |
| 139 | Self { | 139 | Self { |
| 140 | id: NoteFileId::generate(), | 140 | id: NoteFileId::generate(), |
| 141 | - note: note.clone(), | 141 | + note: *note, |
| 142 | name, | 142 | name, |
| 143 | content_type, | 143 | content_type, |
| 144 | size, | 144 | size, |
src/domain/payment_ledger.rsmodified+1 -1
| @@ -277,7 +277,7 @@ mod tests { | |||
| 277 | PaymentLedgerKind::Refund, | 277 | PaymentLedgerKind::Refund, |
| 278 | ] { | 278 | ] { |
| 279 | buf.clear(); | 279 | buf.clear(); |
| 280 | - sqlx::Encode::<sqlx::Postgres>::encode_by_ref(&kind, &mut buf); | 280 | + let _ = sqlx::Encode::<sqlx::Postgres>::encode_by_ref(&kind, &mut buf).unwrap(); |
| 281 | assert_eq!(std::str::from_utf8(&buf).unwrap(), kind.as_str()); | 281 | assert_eq!(std::str::from_utf8(&buf).unwrap(), kind.as_str()); |
| 282 | } | 282 | } |
| 283 | } | 283 | } |
src/domain/pool_question.rsmodified+1 -1
| @@ -108,7 +108,7 @@ impl PoolQuestion { | |||
| 108 | pub fn new(asker: &UserId, title: PoolQuestionTitle, body: PoolQuestionBody) -> Self { | 108 | pub fn new(asker: &UserId, title: PoolQuestionTitle, body: PoolQuestionBody) -> Self { |
| 109 | Self { | 109 | Self { |
| 110 | id: PoolQuestionId::generate(), | 110 | id: PoolQuestionId::generate(), |
| 111 | - asker: asker.clone(), | 111 | + asker: *asker, |
| 112 | title, | 112 | title, |
| 113 | body, | 113 | body, |
| 114 | status: STATUS_PENDING.to_string(), | 114 | status: STATUS_PENDING.to_string(), |
src/domain/preferences.rsmodified+3 -3
| @@ -207,17 +207,17 @@ mod tests { | |||
| 207 | let mut buf = sqlx::postgres::PgArgumentBuffer::default(); | 207 | let mut buf = sqlx::postgres::PgArgumentBuffer::default(); |
| 208 | for theme in THEMES { | 208 | for theme in THEMES { |
| 209 | buf.clear(); | 209 | buf.clear(); |
| 210 | - sqlx::Encode::<sqlx::Postgres>::encode_by_ref(&theme, &mut buf); | 210 | + let _ = sqlx::Encode::<sqlx::Postgres>::encode_by_ref(&theme, &mut buf).unwrap(); |
| 211 | assert_eq!(std::str::from_utf8(&buf).unwrap(), theme.as_str()); | 211 | assert_eq!(std::str::from_utf8(&buf).unwrap(), theme.as_str()); |
| 212 | } | 212 | } |
| 213 | for language in LANGUAGES { | 213 | for language in LANGUAGES { |
| 214 | buf.clear(); | 214 | buf.clear(); |
| 215 | - sqlx::Encode::<sqlx::Postgres>::encode_by_ref(&language, &mut buf); | 215 | + let _ = sqlx::Encode::<sqlx::Postgres>::encode_by_ref(&language, &mut buf).unwrap(); |
| 216 | assert_eq!(std::str::from_utf8(&buf).unwrap(), language.as_str()); | 216 | assert_eq!(std::str::from_utf8(&buf).unwrap(), language.as_str()); |
| 217 | } | 217 | } |
| 218 | let color = PaletteColor::try_from_str("#fefae0").unwrap(); | 218 | let color = PaletteColor::try_from_str("#fefae0").unwrap(); |
| 219 | buf.clear(); | 219 | buf.clear(); |
| 220 | - sqlx::Encode::<sqlx::Postgres>::encode_by_ref(&color, &mut buf); | 220 | + let _ = sqlx::Encode::<sqlx::Postgres>::encode_by_ref(&color, &mut buf).unwrap(); |
| 221 | assert_eq!(std::str::from_utf8(&buf).unwrap(), "#fefae0"); | 221 | assert_eq!(std::str::from_utf8(&buf).unwrap(), "#fefae0"); |
| 222 | } | 222 | } |
| 223 | } | 223 | } |
src/domain/role.rsmodified+1 -1
| @@ -176,7 +176,7 @@ mod tests { | |||
| 176 | let mut buf = sqlx::postgres::PgArgumentBuffer::default(); | 176 | let mut buf = sqlx::postgres::PgArgumentBuffer::default(); |
| 177 | for role in [Role::Ai, Role::Parent, Role::Student, Role::Teacher, Role::Manager, Role::Admin] { | 177 | for role in [Role::Ai, Role::Parent, Role::Student, Role::Teacher, Role::Manager, Role::Admin] { |
| 178 | buf.clear(); | 178 | buf.clear(); |
| 179 | - sqlx::Encode::<sqlx::Postgres>::encode_by_ref(&role, &mut buf); | 179 | + let _ = sqlx::Encode::<sqlx::Postgres>::encode_by_ref(&role, &mut buf).unwrap(); |
| 180 | assert_eq!(std::str::from_utf8(&buf).unwrap(), role.as_str()); | 180 | assert_eq!(std::str::from_utf8(&buf).unwrap(), role.as_str()); |
| 181 | } | 181 | } |
| 182 | } | 182 | } |
src/domain/session.rsmodified+0 -1
| @@ -50,7 +50,6 @@ impl SessionToken { | |||
| 50 | /// Fields are crate-visible: [`crate::db::session`] mints the rows on login. | 50 | /// Fields are crate-visible: [`crate::db::session`] mints the rows on login. |
| 51 | #[derive(Debug, Clone, sqlx::FromRow)] | 51 | #[derive(Debug, Clone, sqlx::FromRow)] |
| 52 | pub struct Session { | 52 | pub struct Session { |
| 53 | - pub(crate) id: SessionId, | ||
| 54 | #[sqlx(rename = "app_user")] | 53 | #[sqlx(rename = "app_user")] |
| 55 | pub(crate) user: UserId, | 54 | pub(crate) user: UserId, |
| 56 | pub(crate) token: SessionToken, | 55 | pub(crate) token: SessionToken, |
src/domain/settings.rsmodified+1 -9
| @@ -23,7 +23,7 @@ use crate::constant::{ | |||
| 23 | MAX_MAX_CHATBOT_THREADS, MAX_MAX_FILE_BYTES, MAX_MEAL_CANCEL_CUTOFF_MINUTES, | 23 | MAX_MAX_CHATBOT_THREADS, MAX_MAX_FILE_BYTES, MAX_MEAL_CANCEL_CUTOFF_MINUTES, |
| 24 | MAX_MEAL_SERVING_MINUTE, MAX_SETTINGS_ITEM_LEN, MAX_SETTINGS_LIST_LEN, | 24 | MAX_MEAL_SERVING_MINUTE, MAX_SETTINGS_ITEM_LEN, MAX_SETTINGS_LIST_LEN, |
| 25 | MIN_CHATBOT_HISTORY_TURNS, MIN_EXAM_KIND_WEIGHT, MIN_MARK, MIN_MAX_CHATBOT_MESSAGE_LEN, | 25 | MIN_CHATBOT_HISTORY_TURNS, MIN_EXAM_KIND_WEIGHT, MIN_MARK, MIN_MAX_CHATBOT_MESSAGE_LEN, |
| 26 | - MIN_MAX_CHATBOT_THREADS, MIN_MAX_FILE_BYTES, SETTINGS_KEY, | 26 | + MIN_MAX_CHATBOT_THREADS, MIN_MAX_FILE_BYTES, |
| 27 | }; | 27 | }; |
| 28 | use crate::domain::text_fold; | 28 | use crate::domain::text_fold; |
| 29 | use crate::error::ValidationError; | 29 | use crate::error::ValidationError; |
| @@ -196,7 +196,6 @@ impl GradeBand { | |||
| 196 | /// binds them directly in the compare-and-set guard. | 196 | /// binds them directly in the compare-and-set guard. |
| 197 | #[derive(Debug, Clone, sqlx::FromRow)] | 197 | #[derive(Debug, Clone, sqlx::FromRow)] |
| 198 | pub struct Settings { | 198 | pub struct Settings { |
| 199 | - pub(crate) id: String, | ||
| 200 | pub(crate) exam_kinds: Json<Vec<ExamKindDef>>, | 199 | pub(crate) exam_kinds: Json<Vec<ExamKindDef>>, |
| 201 | pub(crate) attendance_statuses: Vec<String>, | 200 | pub(crate) attendance_statuses: Vec<String>, |
| 202 | pub(crate) grade_bands: Json<Vec<GradeBand>>, | 201 | pub(crate) grade_bands: Json<Vec<GradeBand>>, |
| @@ -238,16 +237,10 @@ pub struct SettingsParams { | |||
| 238 | } | 237 | } |
| 239 | 238 | ||
| 240 | impl Settings { | 239 | impl Settings { |
| 241 | - /// The singleton row's key (`settings.id` is `TEXT PRIMARY KEY`). | ||
| 242 | - pub(crate) fn record_id() -> String { | ||
| 243 | - SETTINGS_KEY.to_string() | ||
| 244 | - } | ||
| 245 | - | ||
| 246 | /// The out-of-the-box policy — mirrors the constants that were previously | 240 | /// The out-of-the-box policy — mirrors the constants that were previously |
| 247 | /// hard-coded, so a school that never touches `/settings` sees no change. | 241 | /// hard-coded, so a school that never touches `/settings` sees no change. |
| 248 | pub fn defaults() -> Self { | 242 | pub fn defaults() -> Self { |
| 249 | Self { | 243 | Self { |
| 250 | - id: Self::record_id(), | ||
| 251 | exam_kinds: Json( | 244 | exam_kinds: Json( |
| 252 | DEFAULT_EXAM_KINDS | 245 | DEFAULT_EXAM_KINDS |
| 253 | .map(|(name, weight)| ExamKindDef { | 246 | .map(|(name, weight)| ExamKindDef { |
| @@ -400,7 +393,6 @@ impl Settings { | |||
| 400 | } | 393 | } |
| 401 | 394 | ||
| 402 | Ok(Self { | 395 | Ok(Self { |
| 403 | - id: Self::record_id(), | ||
| 404 | exam_kinds: Json(exam_kinds), | 396 | exam_kinds: Json(exam_kinds), |
| 405 | attendance_statuses, | 397 | attendance_statuses, |
| 406 | grade_bands: Json(grade_bands), | 398 | grade_bands: Json(grade_bands), |
src/domain/solution.rsmodified+2 -2
| @@ -77,8 +77,8 @@ impl Solution { | |||
| 77 | pub fn new(question: &PoolQuestionId, author: &UserId, body: SolutionBody) -> Self { | 77 | pub fn new(question: &PoolQuestionId, author: &UserId, body: SolutionBody) -> Self { |
| 78 | Self { | 78 | Self { |
| 79 | id: SolutionId::generate(), | 79 | id: SolutionId::generate(), |
| 80 | - question: question.clone(), | 80 | + question: *question, |
| 81 | - author: author.clone(), | 81 | + author: *author, |
| 82 | body, | 82 | body, |
| 83 | offered_at: Timestamp::now(), | 83 | offered_at: Timestamp::now(), |
| 84 | image_file: None, | 84 | image_file: None, |
src/domain/text_fold.rsmodified+2 -2
| @@ -118,11 +118,11 @@ mod tests { | |||
| 118 | let sql = search_fold_sql("name"); | 118 | let sql = search_fold_sql("name"); |
| 119 | for (from, to) in TEXT_FOLD_REPLACEMENTS { | 119 | for (from, to) in TEXT_FOLD_REPLACEMENTS { |
| 120 | assert!( | 120 | assert!( |
| 121 | - sql.contains(&format!("replace(")) | 121 | + sql.contains(&"replace(".to_string()) |
| 122 | && sql.contains(&format!("'{from}', '{to}'")), | 122 | && sql.contains(&format!("'{from}', '{to}'")), |
| 123 | "rule {from} -> {to} missing from the emitted expression" | 123 | "rule {from} -> {to} missing from the emitted expression" |
| 124 | ); | 124 | ); |
| 125 | - assert_eq!(search_fold(&from.to_string()), *to); | 125 | + assert_eq!(search_fold(from), *to); |
| 126 | } | 126 | } |
| 127 | } | 127 | } |
| 128 | 128 | ||
src/service/appointment.rsmodified+6 -6
| @@ -87,7 +87,7 @@ pub async fn book( | |||
| 87 | let appointment_row = Appointment { | 87 | let appointment_row = Appointment { |
| 88 | id: AppointmentId::generate(), | 88 | id: AppointmentId::generate(), |
| 89 | slot: Some(slot.clone()), | 89 | slot: Some(slot.clone()), |
| 90 | - requester: requester.clone(), | 90 | + requester: *requester, |
| 91 | status: AppointmentStatus::Pending, | 91 | status: AppointmentStatus::Pending, |
| 92 | reason, | 92 | reason, |
| 93 | proposed_starts_at: None, | 93 | proposed_starts_at: None, |
| @@ -264,7 +264,7 @@ pub async fn reject( | |||
| 264 | let expected = appointment::read_pending(db, id).await?; | 264 | let expected = appointment::read_pending(db, id).await?; |
| 265 | let mut rejected = expected.clone(); | 265 | let mut rejected = expected.clone(); |
| 266 | rejected.status = AppointmentStatus::Rejected; | 266 | rejected.status = AppointmentStatus::Rejected; |
| 267 | - rejected.decided_by = Some(decided_by.clone()); | 267 | + rejected.decided_by = Some(*decided_by); |
| 268 | rejected.reject_reason = reason.clone(); | 268 | rejected.reject_reason = reason.clone(); |
| 269 | if let Some(saved) = appointment::save_if_unchanged(db, &expected, rejected).await? { | 269 | if let Some(saved) = appointment::save_if_unchanged(db, &expected, rejected).await? { |
| 270 | return Ok(saved); | 270 | return Ok(saved); |
| @@ -303,7 +303,7 @@ pub async fn cancel( | |||
| 303 | } | 303 | } |
| 304 | let mut cancelled = expected.clone(); | 304 | let mut cancelled = expected.clone(); |
| 305 | cancelled.status = AppointmentStatus::Cancelled; | 305 | cancelled.status = AppointmentStatus::Cancelled; |
| 306 | - cancelled.cancelled_by = Some(cancelled_by.clone()); | 306 | + cancelled.cancelled_by = Some(*cancelled_by); |
| 307 | cancelled.cancel_reason = reason.clone(); | 307 | cancelled.cancel_reason = reason.clone(); |
| 308 | if let Some(saved) = appointment::save_if_unchanged(db, &expected, cancelled).await? { | 308 | if let Some(saved) = appointment::save_if_unchanged(db, &expected, cancelled).await? { |
| 309 | return Ok(saved); | 309 | return Ok(saved); |
| @@ -352,7 +352,7 @@ pub async fn propose( | |||
| 352 | proposed.decided_by = None; | 352 | proposed.decided_by = None; |
| 353 | proposed.proposed_starts_at = Some(starts_at); | 353 | proposed.proposed_starts_at = Some(starts_at); |
| 354 | proposed.proposed_ends_at = Some(ends_at); | 354 | proposed.proposed_ends_at = Some(ends_at); |
| 355 | - proposed.proposed_by = Some(proposed_by.clone()); | 355 | + proposed.proposed_by = Some(*proposed_by); |
| 356 | if let Some(saved) = appointment::save_if_unchanged(db, &expected, proposed).await? { | 356 | if let Some(saved) = appointment::save_if_unchanged(db, &expected, proposed).await? { |
| 357 | return Ok(saved); | 357 | return Ok(saved); |
| 358 | } | 358 | } |
| @@ -594,7 +594,7 @@ mod tests { | |||
| 594 | 594 | ||
| 595 | let mut late = stale.clone(); | 595 | let mut late = stale.clone(); |
| 596 | late.status = AppointmentStatus::Approved; | 596 | late.status = AppointmentStatus::Approved; |
| 597 | - late.decided_by = Some(teacher.clone()); | 597 | + late.decided_by = Some(teacher); |
| 598 | assert!( | 598 | assert!( |
| 599 | appointment::save_if_unchanged(&db, &stale, late) | 599 | appointment::save_if_unchanged(&db, &stale, late) |
| 600 | .await | 600 | .await |
| @@ -617,7 +617,7 @@ mod tests { | |||
| 617 | // stands, does land — a miss is a retry signal, not a wall. | 617 | // stands, does land — a miss is a retry signal, not a wall. |
| 618 | let mut fresh = after.clone(); | 618 | let mut fresh = after.clone(); |
| 619 | fresh.status = AppointmentStatus::Approved; | 619 | fresh.status = AppointmentStatus::Approved; |
| 620 | - fresh.decided_by = Some(teacher.clone()); | 620 | + fresh.decided_by = Some(teacher); |
| 621 | let saved = appointment::save_if_unchanged(&db, &after, fresh) | 621 | let saved = appointment::save_if_unchanged(&db, &after, fresh) |
| 622 | .await | 622 | .await |
| 623 | .unwrap() | 623 | .unwrap() |
src/service/appointment_slot.rsmodified+4 -4
| @@ -68,7 +68,7 @@ pub async fn create( | |||
| 68 | teacher, | 68 | teacher, |
| 69 | vec![AppointmentSlot { | 69 | vec![AppointmentSlot { |
| 70 | id: AppointmentSlotId::generate(), | 70 | id: AppointmentSlotId::generate(), |
| 71 | - teacher: teacher.clone(), | 71 | + teacher: *teacher, |
| 72 | starts_at, | 72 | starts_at, |
| 73 | ends_at, | 73 | ends_at, |
| 74 | note, | 74 | note, |
| @@ -134,7 +134,7 @@ pub async fn publish_weekly( | |||
| 134 | .iter() | 134 | .iter() |
| 135 | .map(|&(starts_at, ends_at)| AppointmentSlot { | 135 | .map(|&(starts_at, ends_at)| AppointmentSlot { |
| 136 | id: AppointmentSlotId::generate(), | 136 | id: AppointmentSlotId::generate(), |
| 137 | - teacher: teacher.clone(), | 137 | + teacher: *teacher, |
| 138 | starts_at, | 138 | starts_at, |
| 139 | ends_at, | 139 | ends_at, |
| 140 | note: note.clone(), | 140 | note: note.clone(), |
| @@ -506,14 +506,14 @@ mod tests { | |||
| 506 | // really runs. | 506 | // really runs. |
| 507 | let gate = std::sync::Arc::new(tokio::sync::Barrier::new(2)); | 507 | let gate = std::sync::Arc::new(tokio::sync::Barrier::new(2)); |
| 508 | let demoting = { | 508 | let demoting = { |
| 509 | - let (db, target, gate) = (db.clone(), teacher.clone(), gate.clone()); | 509 | + let (db, target, gate) = (db.clone(), teacher, gate.clone()); |
| 510 | tokio::spawn(async move { | 510 | tokio::spawn(async move { |
| 511 | gate.wait().await; | 511 | gate.wait().await; |
| 512 | crate::service::user::set_role(&db, &target, Role::Student).await | 512 | crate::service::user::set_role(&db, &target, Role::Student).await |
| 513 | }) | 513 | }) |
| 514 | }; | 514 | }; |
| 515 | let landed = { | 515 | let landed = { |
| 516 | - let (db, teacher, gate) = (db.clone(), teacher.clone(), gate); | 516 | + let (db, teacher, gate) = (db.clone(), teacher, gate); |
| 517 | tokio::spawn(async move { | 517 | tokio::spawn(async move { |
| 518 | gate.wait().await; | 518 | gate.wait().await; |
| 519 | // The publish a `RequireTeacher` snapshot taken a moment | 519 | // The publish a `RequireTeacher` snapshot taken a moment |
src/service/bank_question.rsmodified+1 -1
| @@ -111,7 +111,7 @@ pub async fn update( | |||
| 111 | // Omitted keeps the stored subject — which may already be `None`, cleared | 111 | // Omitted keeps the stored subject — which may already be `None`, cleared |
| 112 | // by that subject's delete. | 112 | // by that subject's delete. |
| 113 | let subject = match &patch.subject { | 113 | let subject = match &patch.subject { |
| 114 | - Some(subject) => Some(subject.clone()), | 114 | + Some(subject) => Some(*subject), |
| 115 | None => question.get_subject().cloned(), | 115 | None => question.get_subject().cloned(), |
| 116 | }; | 116 | }; |
| 117 | let text = patch | 117 | let text = patch |
src/service/board.rsmodified+3 -3
| @@ -91,7 +91,7 @@ pub async fn resolve_participants( | |||
| 91 | .await? | 91 | .await? |
| 92 | .iter() | 92 | .iter() |
| 93 | .filter(|found| found.get_role().at_least(Role::Student)) | 93 | .filter(|found| found.get_role().at_least(Role::Student)) |
| 94 | - .map(|found| found.get_id().clone()) | 94 | + .map(|found| *found.get_id()) |
| 95 | .collect(); | 95 | .collect(); |
| 96 | let mut users = Vec::with_capacity(wanted.len()); | 96 | let mut users = Vec::with_capacity(wanted.len()); |
| 97 | for user in wanted { | 97 | for user in wanted { |
| @@ -140,7 +140,7 @@ pub async fn invite(db: &Database, board: &Board, invited: Vec<UserId>) -> Resul | |||
| 140 | if candidate.get_id() == board.get_creator() || roster.contains(candidate.get_id()) { | 140 | if candidate.get_id() == board.get_creator() || roster.contains(candidate.get_id()) { |
| 141 | continue; | 141 | continue; |
| 142 | } | 142 | } |
| 143 | - add.push(candidate.get_id().clone()); | 143 | + add.push(*candidate.get_id()); |
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | // Unchanged rosters still write and still fan out: the alternative is a | 146 | // Unchanged rosters still write and still fan out: the alternative is a |
| @@ -220,7 +220,7 @@ pub async fn delete(db: &Database, board: Board) -> Result<Board, AppError> { | |||
| 220 | 220 | ||
| 221 | #[cfg(test)] | 221 | #[cfg(test)] |
| 222 | mod tests { | 222 | mod tests { |
| 223 | - use super::*; | 223 | + |
| 224 | 224 | ||
| 225 | /// The security boundary of the gates this module owns, in one test: an | 225 | /// The security boundary of the gates this module owns, in one test: an |
| 226 | /// outsider is told the board does not exist, an insider without rights is | 226 | /// outsider is told the board does not exist, an insider without rights is |
src/service/class_blueprint.rsmodified+3 -3
| @@ -615,8 +615,8 @@ mod tests { | |||
| 615 | }) | 615 | }) |
| 616 | }; | 616 | }; |
| 617 | let pumping = { | 617 | let pumping = { |
| 618 | - let (db, class, algebra, manager, gate) = | 618 | + let (db, class, _algebra, manager, gate) = |
| 619 | - (db.clone(), class.clone(), algebra.clone(), manager.clone(), gate); | 619 | + (db.clone(), class.clone(), algebra.clone(), manager, gate); |
| 620 | tokio::spawn(async move { | 620 | tokio::spawn(async move { |
| 621 | gate.wait().await; | 621 | gate.wait().await; |
| 622 | apply_to(&db, &blueprint, &class, &manager).await | 622 | apply_to(&db, &blueprint, &class, &manager).await |
| @@ -714,7 +714,7 @@ mod tests { | |||
| 714 | let (db, class, manager, gate, blueprint) = ( | 714 | let (db, class, manager, gate, blueprint) = ( |
| 715 | db.clone(), | 715 | db.clone(), |
| 716 | classes[2].clone(), | 716 | classes[2].clone(), |
| 717 | - manager.clone(), | 717 | + manager, |
| 718 | gate.clone(), | 718 | gate.clone(), |
| 719 | blueprint.clone(), | 719 | blueprint.clone(), |
| 720 | ); | 720 | ); |
src/service/class_course.rsmodified+1 -1
| @@ -411,7 +411,7 @@ mod tests { | |||
| 411 | }; | 411 | }; |
| 412 | let child = { | 412 | let child = { |
| 413 | let (db, class, algebra, manager, gate) = | 413 | let (db, class, algebra, manager, gate) = |
| 414 | - (db.clone(), class.clone(), algebra.clone(), manager.clone(), gate); | 414 | + (db.clone(), class.clone(), algebra.clone(), manager, gate); |
| 415 | tokio::spawn(async move { | 415 | tokio::spawn(async move { |
| 416 | gate.wait().await; | 416 | gate.wait().await; |
| 417 | attach(&db, &class, &algebra, &manager).await | 417 | attach(&db, &class, &algebra, &manager).await |
src/service/class_member.rsmodified+1 -1
| @@ -365,7 +365,7 @@ mod tests { | |||
| 365 | ) | 365 | ) |
| 366 | .await | 366 | .await |
| 367 | .unwrap(); | 367 | .unwrap(); |
| 368 | - let student = account.get_id().clone(); | 368 | + let student = *account.get_id(); |
| 369 | let first = a_class("9-A", &db).await; | 369 | let first = a_class("9-A", &db).await; |
| 370 | let second = a_class("club", &db).await; | 370 | let second = a_class("club", &db).await; |
| 371 | let algebra = a_course("algebra", None, &db).await; | 371 | let algebra = a_course("algebra", None, &db).await; |
src/service/exam_attempt.rsmodified+3 -6
| @@ -28,8 +28,6 @@ use crate::domain::timestamp::Timestamp; | |||
| 28 | use crate::domain::user::{User, UserId}; | 28 | use crate::domain::user::{User, UserId}; |
| 29 | use crate::error::AppError; | 29 | use crate::error::AppError; |
| 30 | 30 | ||
| 31 | -#[cfg(test)] | ||
| 32 | -use crate::constant::EXAM_SAT_TOTAL_FIELD; | ||
| 33 | 31 | ||
| 34 | /// Rejects sitting an exam that can't be sat. A draft is a `404`, not a | 32 | /// Rejects sitting an exam that can't be sat. A draft is a `404`, not a |
| 35 | /// `409` — sitting is a student act, drafts are invisible to students, and a | 33 | /// `409` — sitting is a student act, drafts are invisible to students, and a |
| @@ -179,7 +177,7 @@ pub async fn start( | |||
| 179 | }; | 177 | }; |
| 180 | let attempt = ExamAttempt { | 178 | let attempt = ExamAttempt { |
| 181 | exam: exam.get_id().clone(), | 179 | exam: exam.get_id().clone(), |
| 182 | - user: user.clone(), | 180 | + user: *user, |
| 183 | seq: next_seq, | 181 | seq: next_seq, |
| 184 | started_at: Timestamp::now(), | 182 | started_at: Timestamp::now(), |
| 185 | finished_at: None, | 183 | finished_at: None, |
| @@ -502,7 +500,7 @@ mod tests { | |||
| 502 | let question = crate::db::exam_question::create( | 500 | let question = crate::db::exam_question::create( |
| 503 | db, | 501 | db, |
| 504 | exam.get_id(), | 502 | exam.get_id(), |
| 505 | - subject.get_id().clone(), | 503 | + *subject.get_id(), |
| 506 | crate::domain::exam_question::QuestionText::try_new("3 + 3?").unwrap(), | 504 | crate::domain::exam_question::QuestionText::try_new("3 + 3?").unwrap(), |
| 507 | QuestionPoints::try_new(5).unwrap(), | 505 | QuestionPoints::try_new(5).unwrap(), |
| 508 | spec, | 506 | spec, |
| @@ -520,7 +518,7 @@ mod tests { | |||
| 520 | .hash_async() | 518 | .hash_async() |
| 521 | .await | 519 | .await |
| 522 | .unwrap(); | 520 | .unwrap(); |
| 523 | - crate::db::user::create( | 521 | + *crate::db::user::create( |
| 524 | db, | 522 | db, |
| 525 | crate::domain::user::Username::try_new("ogrenci").unwrap(), | 523 | crate::domain::user::Username::try_new("ogrenci").unwrap(), |
| 526 | hash, | 524 | hash, |
| @@ -528,7 +526,6 @@ mod tests { | |||
| 528 | .await | 526 | .await |
| 529 | .unwrap() | 527 | .unwrap() |
| 530 | .get_id() | 528 | .get_id() |
| 531 | - .clone() | ||
| 532 | } | 529 | } |
| 533 | 530 | ||
| 534 | /// The student's lifetime sitting count, absent reading as zero. | 531 | /// The student's lifetime sitting count, absent reading as zero. |
src/service/fee_plan_assignment.rsmodified+3 -3
| @@ -331,7 +331,7 @@ mod tests { | |||
| 331 | async fn an_edit_racing_an_assign_leaves_the_plan_and_the_money_agreeing() { | 331 | async fn an_edit_racing_an_assign_leaves_the_plan_and_the_money_agreeing() { |
| 332 | let (db, _leases) = crate::database::init_test_db().await; | 332 | let (db, _leases) = crate::database::init_test_db().await; |
| 333 | let mut reached = 0; | 333 | let mut reached = 0; |
| 334 | - for round in 0..20 { | 334 | + for _round in 0..20 { |
| 335 | let manager = a_person(&db, "mgr", "manager").await; | 335 | let manager = a_person(&db, "mgr", "manager").await; |
| 336 | let student = a_person(&db, "stu", "student").await; | 336 | let student = a_person(&db, "stu", "student").await; |
| 337 | let plan = a_plan( | 337 | let plan = a_plan( |
| @@ -360,7 +360,7 @@ mod tests { | |||
| 360 | }; | 360 | }; |
| 361 | let assign = { | 361 | let assign = { |
| 362 | let (db, plan, manager, student) = | 362 | let (db, plan, manager, student) = |
| 363 | - (db.clone(), plan.clone(), manager.clone(), student.clone()); | 363 | + (db.clone(), plan.clone(), manager, student); |
| 364 | tokio::spawn(async move { assign(&db, &plan, &student, &manager).await }) | 364 | tokio::spawn(async move { assign(&db, &plan, &student, &manager).await }) |
| 365 | }; | 365 | }; |
| 366 | let (edit, assign) = (edit.await.unwrap(), assign.await.unwrap()); | 366 | let (edit, assign) = (edit.await.unwrap(), assign.await.unwrap()); |
| @@ -462,7 +462,7 @@ mod tests { | |||
| 462 | }; | 462 | }; |
| 463 | let assign = { | 463 | let assign = { |
| 464 | let (db, plan, manager, student) = | 464 | let (db, plan, manager, student) = |
| 465 | - (db.clone(), plan.clone(), manager.clone(), student.clone()); | 465 | + (db.clone(), plan.clone(), manager, student); |
| 466 | tokio::spawn(async move { | 466 | tokio::spawn(async move { |
| 467 | if hold_back_the_assign { | 467 | if hold_back_the_assign { |
| 468 | tokio::time::sleep(head_start).await; | 468 | tokio::time::sleep(head_start).await; |
src/service/meal_booking.rsmodified+4 -4
| @@ -123,8 +123,8 @@ pub async fn book( | |||
| 123 | let price = meal_ledger::price_snapshot(db, menu).await?; | 123 | let price = meal_ledger::price_snapshot(db, menu).await?; |
| 124 | let fresh_row = MealBooking { | 124 | let fresh_row = MealBooking { |
| 125 | menu: menu.clone(), | 125 | menu: menu.clone(), |
| 126 | - student: student.clone(), | 126 | + student: *student, |
| 127 | - booked_by: booked_by.clone(), | 127 | + booked_by: *booked_by, |
| 128 | status: MealBookingStatus::Booked, | 128 | status: MealBookingStatus::Booked, |
| 129 | attempt, | 129 | attempt, |
| 130 | price_minor: price, | 130 | price_minor: price, |
| @@ -559,8 +559,8 @@ mod tests { | |||
| 559 | let price = meal_ledger::price_snapshot(&db, &menu).await.unwrap(); | 559 | let price = meal_ledger::price_snapshot(&db, &menu).await.unwrap(); |
| 560 | let row = MealBooking { | 560 | let row = MealBooking { |
| 561 | menu: menu.clone(), | 561 | menu: menu.clone(), |
| 562 | - student: ali.clone(), | 562 | + student: ali, |
| 563 | - booked_by: ali.clone(), | 563 | + booked_by: ali, |
| 564 | status: MealBookingStatus::Booked, | 564 | status: MealBookingStatus::Booked, |
| 565 | attempt: 1, | 565 | attempt: 1, |
| 566 | price_minor: price, | 566 | price_minor: price, |
src/service/meal_ledger.rsmodified+2 -2
| @@ -95,13 +95,13 @@ pub async fn credit( | |||
| 95 | Some(key) => MealLedgerId::for_request(student, key), | 95 | Some(key) => MealLedgerId::for_request(student, key), |
| 96 | None => MealLedgerId::generate(), | 96 | None => MealLedgerId::generate(), |
| 97 | }, | 97 | }, |
| 98 | - student: student.clone(), | 98 | + student: *student, |
| 99 | kind: MealLedgerKind::Credit, | 99 | kind: MealLedgerKind::Credit, |
| 100 | amount_minor, | 100 | amount_minor, |
| 101 | source: None, | 101 | source: None, |
| 102 | method, | 102 | method, |
| 103 | note, | 103 | note, |
| 104 | - recorded_by: recorded_by.clone(), | 104 | + recorded_by: *recorded_by, |
| 105 | created_at: Timestamp::now(), | 105 | created_at: Timestamp::now(), |
| 106 | }, | 106 | }, |
| 107 | ) | 107 | ) |
src/service/payment_ledger.rsmodified+5 -5
| @@ -203,7 +203,7 @@ async fn against( | |||
| 203 | } | 203 | } |
| 204 | return Ok(existing); | 204 | return Ok(existing); |
| 205 | } | 205 | } |
| 206 | - let taken = payment_ledger::applied_to(&mut *tx, &target.id.key(), target.kind).await?; | 206 | + let taken = payment_ledger::applied_to(&mut *tx, target.id.key(), target.kind).await?; |
| 207 | if taken.saturating_add(amount_minor.as_minor()) > target.amount_minor.as_minor() { | 207 | if taken.saturating_add(amount_minor.as_minor()) > target.amount_minor.as_minor() { |
| 208 | // The fold cannot say *why* the room is gone: a reversal is a | 208 | // The fold cannot say *why* the room is gone: a reversal is a |
| 209 | // child of the line it undoes and folds in at `+amount` exactly | 209 | // child of the line it undoes and folds in at `+amount` exactly |
| @@ -228,7 +228,7 @@ async fn against( | |||
| 228 | &mut *tx, | 228 | &mut *tx, |
| 229 | PaymentLedger { | 229 | PaymentLedger { |
| 230 | id: keyed.clone().unwrap_or_else(PaymentLedgerId::generate), | 230 | id: keyed.clone().unwrap_or_else(PaymentLedgerId::generate), |
| 231 | - student: target.student.clone(), | 231 | + student: target.student, |
| 232 | kind, | 232 | kind, |
| 233 | amount_minor, | 233 | amount_minor, |
| 234 | source: Some(target.id.key().to_string()), | 234 | source: Some(target.id.key().to_string()), |
| @@ -285,7 +285,7 @@ pub async fn reversal( | |||
| 285 | &mut *tx, | 285 | &mut *tx, |
| 286 | PaymentLedger { | 286 | PaymentLedger { |
| 287 | id: PaymentLedgerId::for_reversal(line.get_id()), | 287 | id: PaymentLedgerId::for_reversal(line.get_id()), |
| 288 | - student: line.student.clone(), | 288 | + student: line.student, |
| 289 | kind: PaymentLedgerKind::Reversal, | 289 | kind: PaymentLedgerKind::Reversal, |
| 290 | amount_minor: line.amount_minor, | 290 | amount_minor: line.amount_minor, |
| 291 | source: Some(line.id.key().to_string()), | 291 | source: Some(line.id.key().to_string()), |
| @@ -402,14 +402,14 @@ mod tests { | |||
| 402 | // is a 500, never that other line handed back as this one. | 402 | // is a 500, never that other line handed back as this one. |
| 403 | let intruder = PaymentLedger { | 403 | let intruder = PaymentLedger { |
| 404 | id: charge.get_id().clone(), | 404 | id: charge.get_id().clone(), |
| 405 | - student: charge.student.clone(), | 405 | + student: charge.student, |
| 406 | kind: PaymentLedgerKind::Credit, | 406 | kind: PaymentLedgerKind::Credit, |
| 407 | amount_minor: LedgerAmount::try_new(1).unwrap(), | 407 | amount_minor: LedgerAmount::try_new(1).unwrap(), |
| 408 | source: Some(charge.id.key().to_owned()), | 408 | source: Some(charge.id.key().to_owned()), |
| 409 | due_at: None, | 409 | due_at: None, |
| 410 | method: None, | 410 | method: None, |
| 411 | note: None, | 411 | note: None, |
| 412 | - recorded_by: manager.clone(), | 412 | + recorded_by: manager, |
| 413 | created_at: Timestamp::now(), | 413 | created_at: Timestamp::now(), |
| 414 | }; | 414 | }; |
| 415 | assert!( | 415 | assert!( |
src/service/subject.rsmodified+2 -2
| @@ -70,7 +70,7 @@ pub async fn in_course(db: &Database, id: &str, course: &CourseId) -> Result<Sub | |||
| 70 | reason: "subject belongs to a different course", | 70 | reason: "subject belongs to a different course", |
| 71 | })); | 71 | })); |
| 72 | } | 72 | } |
| 73 | - Ok(subject.get_id().clone()) | 73 | + Ok(*subject.get_id()) |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | /// Turn a request-supplied subject id into a validated reference, checking only | 76 | /// Turn a request-supplied subject id into a validated reference, checking only |
| @@ -85,5 +85,5 @@ pub async fn must_exist(db: &Database, id: &str) -> Result<SubjectId, AppError> | |||
| 85 | field: "subject_id", | 85 | field: "subject_id", |
| 86 | reason: "subject does not exist", | 86 | reason: "subject does not exist", |
| 87 | }))?; | 87 | }))?; |
| 88 | - Ok(subject.get_id().clone()) | 88 | + Ok(*subject.get_id()) |
| 89 | } | 89 | } |
src/service/term.rsmodified+1 -1
| @@ -51,7 +51,7 @@ pub async fn resolve(db: &Database, id: Option<&str>) -> Result<Option<TermId>, | |||
| 51 | if resolved.is_archived() { | 51 | if resolved.is_archived() { |
| 52 | return Err(archived_error()); | 52 | return Err(archived_error()); |
| 53 | } | 53 | } |
| 54 | - Ok(Some(resolved.get_id().clone())) | 54 | + Ok(Some(*resolved.get_id())) |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | /// Refuse when the named term is archived. A missing row is `Ok(())`: a | 57 | /// Refuse when the named term is archived. A missing row is `Ok(())`: a |
src/service/user.rsmodified+5 -5
| @@ -243,7 +243,7 @@ mod tests { | |||
| 243 | &db, | 243 | &db, |
| 244 | creator.get_id(), | 244 | creator.get_id(), |
| 245 | BoardTitle::try_new("Geometri").unwrap(), | 245 | BoardTitle::try_new("Geometri").unwrap(), |
| 246 | - vec![guest.get_id().clone()], | 246 | + vec![*guest.get_id()], |
| 247 | ) | 247 | ) |
| 248 | .await | 248 | .await |
| 249 | .unwrap(); | 249 | .unwrap(); |
| @@ -283,12 +283,12 @@ mod tests { | |||
| 283 | &db, | 283 | &db, |
| 284 | creator.get_id(), | 284 | creator.get_id(), |
| 285 | BoardTitle::try_new("Geometri").unwrap(), | 285 | BoardTitle::try_new("Geometri").unwrap(), |
| 286 | - vec![guest.get_id().clone()], | 286 | + vec![*guest.get_id()], |
| 287 | ) | 287 | ) |
| 288 | .await | 288 | .await |
| 289 | .unwrap(); | 289 | .unwrap(); |
| 290 | let mark = |epoch| { | 290 | let mark = |epoch| { |
| 291 | - let (id, author, db) = (board.get_id().clone(), guest.get_id().clone(), db.clone()); | 291 | + let (id, author, db) = (board.get_id().clone(), *guest.get_id(), db.clone()); |
| 292 | async move { crate::db::board_stroke::append(&db, &id, &author, "{\"p\":[1]}", epoch).await } | 292 | async move { crate::db::board_stroke::append(&db, &id, &author, "{\"p\":[1]}", epoch).await } |
| 293 | }; | 293 | }; |
| 294 | mark(0).await.unwrap(); | 294 | mark(0).await.unwrap(); |
| @@ -307,7 +307,7 @@ mod tests { | |||
| 307 | assert_eq!(stored.get_closed_at(), Some(stamp)); | 307 | assert_eq!(stored.get_closed_at(), Some(stamp)); |
| 308 | assert_eq!( | 308 | assert_eq!( |
| 309 | stored.get_participants(), | 309 | stored.get_participants(), |
| 310 | - [guest.get_id().clone()], | 310 | + [*guest.get_id()], |
| 311 | "closing must not empty the roster it did not touch" | 311 | "closing must not empty the roster it did not touch" |
| 312 | ); | 312 | ); |
| 313 | assert_eq!( | 313 | assert_eq!( |
| @@ -366,7 +366,7 @@ mod tests { | |||
| 366 | let soon = |offset| Timestamp::from_millis(Timestamp::now().as_millis() + offset); | 366 | let soon = |offset| Timestamp::from_millis(Timestamp::now().as_millis() + offset); |
| 367 | let reason = || AppointmentReason::try_new("görüşme").unwrap(); | 367 | let reason = || AppointmentReason::try_new("görüşme").unwrap(); |
| 368 | let slot = |owner: &User, offset: i64, db: Database| { | 368 | let slot = |owner: &User, offset: i64, db: Database| { |
| 369 | - let owner = owner.get_id().clone(); | 369 | + let owner = *owner.get_id(); |
| 370 | async move { | 370 | async move { |
| 371 | crate::service::appointment_slot::create( | 371 | crate::service::appointment_slot::create( |
| 372 | &db, | 372 | &db, |
src/tenant.rsmodified+1 -3
| @@ -443,11 +443,9 @@ impl Tenants { | |||
| 443 | ))) | 443 | ))) |
| 444 | .execute(&self.control) | 444 | .execute(&self.control) |
| 445 | .await | 445 | .await |
| 446 | - { | 446 | + && !is_duplicate_database(&err) { |
| 447 | - if !is_duplicate_database(&err) { | ||
| 448 | return Err(err.into()); | 447 | return Err(err.into()); |
| 449 | } | 448 | } |
| 450 | - } | ||
| 451 | let pool = school_pool(&self.base, &db_name).await?; | 449 | let pool = school_pool(&self.base, &db_name).await?; |
| 452 | let migrated = migrate_school(&pool).await; | 450 | let migrated = migrate_school(&pool).await; |
| 453 | if migrated.is_err() { | 451 | if migrated.is_err() { |
src/web/appointments.rsmodified+2 -2
| @@ -231,8 +231,8 @@ async fn appointment_responses( | |||
| 231 | // higher-ranked, which axum then refuses as not `Send` enough. | 231 | // higher-ranked, which axum then refuses as not `Send` enough. |
| 232 | let mut ids = Vec::with_capacity(rows.len() * 2); | 232 | let mut ids = Vec::with_capacity(rows.len() * 2); |
| 233 | for (row, slot) in rows.iter().zip(&slots) { | 233 | for (row, slot) in rows.iter().zip(&slots) { |
| 234 | - ids.push(row.get_requester().clone()); | 234 | + ids.push(*row.get_requester()); |
| 235 | - ids.extend(slot.as_ref().map(|slot| slot.get_teacher().clone())); | 235 | + ids.extend(slot.as_ref().map(|slot| *slot.get_teacher())); |
| 236 | ids.extend(row.get_proposed_by().cloned()); | 236 | ids.extend(row.get_proposed_by().cloned()); |
| 237 | ids.extend(row.get_decided_by().cloned()); | 237 | ids.extend(row.get_decided_by().cloned()); |
| 238 | ids.extend(row.get_cancelled_by().cloned()); | 238 | ids.extend(row.get_cancelled_by().cloned()); |
src/web/bank_questions.rsmodified+6 -6
| @@ -464,7 +464,7 @@ async fn create_question( | |||
| 464 | &[], | 464 | &[], |
| 465 | )?; | 465 | )?; |
| 466 | let question = | 466 | let question = |
| 467 | - bank_question::create(&st.db, user.get_id().clone(), subject, text, points, spec).await?; | 467 | + bank_question::create(&st.db, *user.get_id(), subject, text, points, spec).await?; |
| 468 | Ok(( | 468 | Ok(( |
| 469 | StatusCode::CREATED, | 469 | StatusCode::CREATED, |
| 470 | Json(BankQuestionResponse::new(&question, &[])), | 470 | Json(BankQuestionResponse::new(&question, &[])), |
| @@ -504,7 +504,7 @@ async fn list_questions( | |||
| 504 | let (limit, offset) = page.resolve()?; | 504 | let (limit, offset) = page.resolve()?; |
| 505 | let subject = filter.subject.as_deref().map(SubjectId::from_key); | 505 | let subject = filter.subject.as_deref().map(SubjectId::from_key); |
| 506 | let owner = filter.owner.as_deref().map(|owner| match owner { | 506 | let owner = filter.owner.as_deref().map(|owner| match owner { |
| 507 | - "me" => user.get_id().clone(), | 507 | + "me" => *user.get_id(), |
| 508 | id => UserId::from_key(id), | 508 | id => UserId::from_key(id), |
| 509 | }); | 509 | }); |
| 510 | // Same newtype the PATCH validates against, so an unknown shelf is the same | 510 | // Same newtype the PATCH validates against, so an unknown shelf is the same |
| @@ -517,7 +517,7 @@ async fn list_questions( | |||
| 517 | // The visibility gate is one of those SQL filters, never a post-filter over | 517 | // The visibility gate is one of those SQL filters, never a post-filter over |
| 518 | // the page: `total` counts what the caller may see, so paging can't hand | 518 | // the page: `total` counts what the caller may see, so paging can't hand |
| 519 | // back short pages full of holes where someone else's private templates sat. | 519 | // back short pages full of holes where someone else's private templates sat. |
| 520 | - let viewer = (!user.get_role().at_least(Role::Admin)).then(|| user.get_id().clone()); | 520 | + let viewer = (!user.get_role().at_least(Role::Admin)).then(|| *user.get_id()); |
| 521 | // Filters, order, and window are all SQL — `total` comes from a count over | 521 | // Filters, order, and window are all SQL — `total` comes from a count over |
| 522 | // the same WHERE, so a client can page past the first window. | 522 | // the same WHERE, so a client can page past the first window. |
| 523 | let (questions, total) = bank_question::list( | 523 | let (questions, total) = bank_question::list( |
| @@ -554,7 +554,7 @@ async fn list_questions( | |||
| 554 | ) | 554 | ) |
| 555 | }) | 555 | }) |
| 556 | .collect(); | 556 | .collect(); |
| 557 | - let people = person_map(questions.iter().map(|q| q.get_owner().clone()), &st.db).await?; | 557 | + let people = person_map(questions.iter().map(|q| *q.get_owner()), &st.db).await?; |
| 558 | 558 | ||
| 559 | let empty: Vec<BankQuestionImage> = Vec::new(); | 559 | let empty: Vec<BankQuestionImage> = Vec::new(); |
| 560 | let items = questions | 560 | let items = questions |
| @@ -959,8 +959,8 @@ mod tests { | |||
| 959 | .unwrap(); | 959 | .unwrap(); |
| 960 | let question = bank_question::create( | 960 | let question = bank_question::create( |
| 961 | &db, | 961 | &db, |
| 962 | - owner.get_id().clone(), | 962 | + *owner.get_id(), |
| 963 | - subject.get_id().clone(), | 963 | + *subject.get_id(), |
| 964 | QuestionText::try_new("2 + 2 = ?").unwrap(), | 964 | QuestionText::try_new("2 + 2 = ?").unwrap(), |
| 965 | QuestionPoints::try_new(1).unwrap(), | 965 | QuestionPoints::try_new(1).unwrap(), |
| 966 | QuestionSpec::try_new(QuestionKind::try_new("text").unwrap(), None, None, &[]).unwrap(), | 966 | QuestionSpec::try_new(QuestionKind::try_new("text").unwrap(), None, None, &[]).unwrap(), |
src/web/board_ws.rsmodified+3 -3
| @@ -140,7 +140,7 @@ pub async fn board_ws( | |||
| 140 | return Err(AppError::NotFound); | 140 | return Err(AppError::NotFound); |
| 141 | } | 141 | } |
| 142 | let board_id = board.get_id().clone(); | 142 | let board_id = board.get_id().clone(); |
| 143 | - let user_id = user.get_id().clone(); | 143 | + let user_id = *user.get_id(); |
| 144 | Ok(ws.on_upgrade(move |socket| room(socket, st, slug, board_id, user_id))) | 144 | Ok(ws.on_upgrade(move |socket| room(socket, st, slug, board_id, user_id))) |
| 145 | } | 145 | } |
| 146 | 146 | ||
| @@ -690,12 +690,12 @@ mod tests { | |||
| 690 | ) | 690 | ) |
| 691 | .await | 691 | .await |
| 692 | .unwrap(); | 692 | .unwrap(); |
| 693 | - let mate_id = mate.get_id().clone(); | 693 | + let mate_id = *mate.get_id(); |
| 694 | let board = board::create( | 694 | let board = board::create( |
| 695 | &db, | 695 | &db, |
| 696 | creator.get_id(), | 696 | creator.get_id(), |
| 697 | BoardTitle::try_new("Tahta").unwrap(), | 697 | BoardTitle::try_new("Tahta").unwrap(), |
| 698 | - vec![mate_id.clone()], | 698 | + vec![mate_id], |
| 699 | ) | 699 | ) |
| 700 | .await | 700 | .await |
| 701 | .unwrap(); | 701 | .unwrap(); |
src/web/boards.rsmodified+2 -2
| @@ -640,7 +640,7 @@ impl InviteSource { | |||
| 640 | .await? | 640 | .await? |
| 641 | .0 | 641 | .0 |
| 642 | .iter() | 642 | .iter() |
| 643 | - .map(|member| member.get_user().clone()) | 643 | + .map(|member| *member.get_user()) |
| 644 | .collect(), | 644 | .collect(), |
| 645 | ) | 645 | ) |
| 646 | } | 646 | } |
| @@ -661,7 +661,7 @@ impl InviteSource { | |||
| 661 | .await? | 661 | .await? |
| 662 | .0 | 662 | .0 |
| 663 | .iter() | 663 | .iter() |
| 664 | - .map(|enrollment| enrollment.get_user().clone()) | 664 | + .map(|enrollment| *enrollment.get_user()) |
| 665 | .collect(), | 665 | .collect(), |
| 666 | ) | 666 | ) |
| 667 | } | 667 | } |
src/web/chatbot.rsmodified+1 -1
| @@ -755,7 +755,7 @@ async fn stream_message( | |||
| 755 | let (tx, rx) = mpsc::channel(REPLY_CHUNKS + 2); | 755 | let (tx, rx) = mpsc::channel(REPLY_CHUNKS + 2); |
| 756 | let (message_id, user_id, db) = ( | 756 | let (message_id, user_id, db) = ( |
| 757 | ChatbotMessageId::from_key(&mid), | 757 | ChatbotMessageId::from_key(&mid), |
| 758 | - user.get_id().clone(), | 758 | + *user.get_id(), |
| 759 | st.db.clone(), | 759 | st.db.clone(), |
| 760 | ); | 760 | ); |
| 761 | tokio::spawn(async move { | 761 | tokio::spawn(async move { |
src/web/classes.rsmodified+11 -11
| @@ -188,7 +188,7 @@ struct CreateClassResponse { | |||
| 188 | /// must also be left out of the response. | 188 | /// must also be left out of the response. |
| 189 | fn class_people(class: &ClassGroup, with_creator: bool) -> impl Iterator<Item = UserId> + '_ { | 189 | fn class_people(class: &ClassGroup, with_creator: bool) -> impl Iterator<Item = UserId> + '_ { |
| 190 | with_creator | 190 | with_creator |
| 191 | - .then(|| class.get_creator().clone()) | 191 | + .then(|| *class.get_creator()) |
| 192 | .into_iter() | 192 | .into_iter() |
| 193 | .chain(class.get_teacher().cloned()) | 193 | .chain(class.get_teacher().cloned()) |
| 194 | } | 194 | } |
| @@ -363,7 +363,7 @@ async fn create_class( | |||
| 363 | name, | 363 | name, |
| 364 | grade, | 364 | grade, |
| 365 | term, | 365 | term, |
| 366 | - teacher.as_ref().map(|t| t.get_id().clone()), | 366 | + teacher.as_ref().map(|t| *t.get_id()), |
| 367 | ) | 367 | ) |
| 368 | .await?; | 368 | .await?; |
| 369 | // The row is written; a demotion that raced this request's role check swept | 369 | // The row is written; a demotion that raced this request's role check swept |
| @@ -578,14 +578,14 @@ async fn update_class( | |||
| 578 | 578 | ||
| 579 | let assigned = teacher | 579 | let assigned = teacher |
| 580 | .as_ref() | 580 | .as_ref() |
| 581 | - .and_then(|teacher| teacher.as_ref().map(|teacher| teacher.get_id().clone())); | 581 | + .and_then(|teacher| teacher.as_ref().map(|teacher| *teacher.get_id())); |
| 582 | let updated = class_group::update( | 582 | let updated = class_group::update( |
| 583 | &st.db, | 583 | &st.db, |
| 584 | class, | 584 | class, |
| 585 | name, | 585 | name, |
| 586 | grade, | 586 | grade, |
| 587 | term, | 587 | term, |
| 588 | - teacher.map(|teacher| teacher.map(|teacher| teacher.get_id().clone())), | 588 | + teacher.map(|teacher| teacher.map(|teacher| *teacher.get_id())), |
| 589 | ) | 589 | ) |
| 590 | .await?; | 590 | .await?; |
| 591 | // Only when this request named a teacher: a PATCH that left the column | 591 | // Only when this request named a teacher: a PATCH that left the column |
| @@ -801,7 +801,7 @@ async fn list_members( | |||
| 801 | // Join people onto the page alone — the lookup shrinks with the window. | 801 | // Join people onto the page alone — the lookup shrinks with the window. |
| 802 | let people = person_map( | 802 | let people = person_map( |
| 803 | rows.iter() | 803 | rows.iter() |
| 804 | - .flat_map(|row| [row.get_user().clone(), row.get_added_by().clone()]), | 804 | + .flat_map(|row| [*row.get_user(), *row.get_added_by()]), |
| 805 | &st.db, | 805 | &st.db, |
| 806 | ) | 806 | ) |
| 807 | .await?; | 807 | .await?; |
| @@ -927,7 +927,7 @@ async fn list_class_courses( | |||
| 927 | let (limit, offset) = page.resolve()?; | 927 | let (limit, offset) = page.resolve()?; |
| 928 | let class = class_or_404(&id, &st.db).await?; | 928 | let class = class_or_404(&id, &st.db).await?; |
| 929 | let (rows, total) = class_course::list_for_class(&st.db, class.get_id(), limit, offset).await?; | 929 | let (rows, total) = class_course::list_for_class(&st.db, class.get_id(), limit, offset).await?; |
| 930 | - let people = person_map(rows.iter().map(|row| row.get_attached_by().clone()), &st.db).await?; | 930 | + let people = person_map(rows.iter().map(|row| *row.get_attached_by()), &st.db).await?; |
| 931 | let items = rows | 931 | let items = rows |
| 932 | .iter() | 932 | .iter() |
| 933 | .map(|row| ClassCourseResponse::new(row, &people)) | 933 | .map(|row| ClassCourseResponse::new(row, &people)) |
| @@ -1179,7 +1179,7 @@ async fn blueprint_body( | |||
| 1179 | pumped: &Pumped, | 1179 | pumped: &Pumped, |
| 1180 | db: &Database, | 1180 | db: &Database, |
| 1181 | ) -> Result<BlueprintPumpResponse, AppError> { | 1181 | ) -> Result<BlueprintPumpResponse, AppError> { |
| 1182 | - let people = person_map([blueprint.get_creator().clone()], db).await?; | 1182 | + let people = person_map([*blueprint.get_creator()], db).await?; |
| 1183 | Ok(BlueprintPumpResponse { | 1183 | Ok(BlueprintPumpResponse { |
| 1184 | blueprint: BlueprintResponse::new(blueprint, &people), | 1184 | blueprint: BlueprintResponse::new(blueprint, &people), |
| 1185 | matched: pumped.matched, | 1185 | matched: pumped.matched, |
| @@ -1251,7 +1251,7 @@ async fn list_blueprints( | |||
| 1251 | let people = person_map( | 1251 | let people = person_map( |
| 1252 | blueprints | 1252 | blueprints |
| 1253 | .iter() | 1253 | .iter() |
| 1254 | - .map(|blueprint| blueprint.get_creator().clone()), | 1254 | + .map(|blueprint| *blueprint.get_creator()), |
| 1255 | &st.db, | 1255 | &st.db, |
| 1256 | ) | 1256 | ) |
| 1257 | .await?; | 1257 | .await?; |
| @@ -1282,7 +1282,7 @@ async fn get_blueprint( | |||
| 1282 | Path(grade): Path<String>, | 1282 | Path(grade): Path<String>, |
| 1283 | ) -> Result<Json<BlueprintResponse>, AppError> { | 1283 | ) -> Result<Json<BlueprintResponse>, AppError> { |
| 1284 | let blueprint = blueprint_or_404(&grade, &st.db).await?; | 1284 | let blueprint = blueprint_or_404(&grade, &st.db).await?; |
| 1285 | - let people = person_map([blueprint.get_creator().clone()], &st.db).await?; | 1285 | + let people = person_map([*blueprint.get_creator()], &st.db).await?; |
| 1286 | Ok(Json(BlueprintResponse::new(&blueprint, &people))) | 1286 | Ok(Json(BlueprintResponse::new(&blueprint, &people))) |
| 1287 | } | 1287 | } |
| 1288 | 1288 | ||
| @@ -1540,8 +1540,8 @@ mod tests { | |||
| 1540 | teacher_or_none(Some(teacher.get_id().key().as_str()), &db) | 1540 | teacher_or_none(Some(teacher.get_id().key().as_str()), &db) |
| 1541 | .await | 1541 | .await |
| 1542 | .unwrap() | 1542 | .unwrap() |
| 1543 | - .map(|found| found.get_id().clone()), | 1543 | + .map(|found| *found.get_id()), |
| 1544 | - Some(teacher.get_id().clone()), | 1544 | + Some(*teacher.get_id()), |
| 1545 | "a teacher account is the one thing that resolves" | 1545 | "a teacher account is the one thing that resolves" |
| 1546 | ); | 1546 | ); |
| 1547 | } | 1547 | } |
src/web/courses.rsmodified+4 -4
| @@ -273,7 +273,7 @@ pub(crate) async fn visible_courses(user: &User, db: &Database) -> Result<Vec<Co | |||
| 273 | } | 273 | } |
| 274 | } | 274 | } |
| 275 | // Both sources come newest-first; re-sort so the merged list is too. | 275 | // Both sources come newest-first; re-sort so the merged list is too. |
| 276 | - courses.sort_by(|a, b| b.get_id().key().cmp(&a.get_id().key())); | 276 | + courses.sort_by_key(|course| std::cmp::Reverse(course.get_id().key())); |
| 277 | Ok(courses) | 277 | Ok(courses) |
| 278 | } | 278 | } |
| 279 | 279 | ||
| @@ -692,7 +692,7 @@ async fn enroll( | |||
| 692 | let target = UserId::from_key(&req.user_id); | 692 | let target = UserId::from_key(&req.user_id); |
| 693 | let enrollment = | 693 | let enrollment = |
| 694 | service::enrollment::enroll(&st.db, course.get_id(), &target, user.get_id()).await?; | 694 | service::enrollment::enroll(&st.db, course.get_id(), &target, user.get_id()).await?; |
| 695 | - let people = person_map([target, user.get_id().clone()], &st.db).await?; | 695 | + let people = person_map([target, *user.get_id()], &st.db).await?; |
| 696 | Ok(Json(EnrollmentResponse::new(&enrollment, &people))) | 696 | Ok(Json(EnrollmentResponse::new(&enrollment, &people))) |
| 697 | } | 697 | } |
| 698 | 698 | ||
| @@ -735,7 +735,7 @@ async fn list_roster( | |||
| 735 | // Join people onto the page alone — the lookup shrinks with the window. | 735 | // Join people onto the page alone — the lookup shrinks with the window. |
| 736 | let people = person_map( | 736 | let people = person_map( |
| 737 | rows.iter() | 737 | rows.iter() |
| 738 | - .flat_map(|e| [e.get_user().clone(), e.get_enrolled_by().clone()]), | 738 | + .flat_map(|e| [*e.get_user(), *e.get_enrolled_by()]), |
| 739 | &st.db, | 739 | &st.db, |
| 740 | ) | 740 | ) |
| 741 | .await?; | 741 | .await?; |
| @@ -1271,7 +1271,7 @@ async fn list_course_sessions( | |||
| 1271 | let (rows, total) = | 1271 | let (rows, total) = |
| 1272 | service::course_session::list_for_course(&st.db, course.get_id(), limit, offset).await?; | 1272 | service::course_session::list_for_course(&st.db, course.get_id(), limit, offset).await?; |
| 1273 | // Join teachers onto the page alone — the lookup shrinks with the window. | 1273 | // Join teachers onto the page alone — the lookup shrinks with the window. |
| 1274 | - let people = person_map(rows.iter().map(|s| s.get_teacher().clone()), &st.db).await?; | 1274 | + let people = person_map(rows.iter().map(|s| *s.get_teacher()), &st.db).await?; |
| 1275 | let items = rows | 1275 | let items = rows |
| 1276 | .iter() | 1276 | .iter() |
| 1277 | .map(|s| SessionResponse::new(s, &people)) | 1277 | .map(|s| SessionResponse::new(s, &people)) |
src/web/dto.rsmodified+1 -1
| @@ -241,7 +241,7 @@ pub struct CourseResponse { | |||
| 241 | /// assigned to run it. Feed this into `person_map` so the response can resolve | 241 | /// assigned to run it. Feed this into `person_map` so the response can resolve |
| 242 | /// all of them — a name the map is missing renders as an unknown person. | 242 | /// all of them — a name the map is missing renders as an unknown person. |
| 243 | pub fn course_people(course: &Course) -> impl Iterator<Item = UserId> + '_ { | 243 | pub fn course_people(course: &Course) -> impl Iterator<Item = UserId> + '_ { |
| 244 | - std::iter::once(course.get_creator().clone()).chain(course.get_teachers().iter().cloned()) | 244 | + std::iter::once(*course.get_creator()).chain(course.get_teachers().iter().cloned()) |
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | impl CourseResponse { | 247 | impl CourseResponse { |
src/web/events.rsmodified+7 -7
| @@ -566,7 +566,7 @@ async fn mark( | |||
| 566 | let status = AttendanceStatus::try_new(&req.status, school.get_attendance_statuses())?; | 566 | let status = AttendanceStatus::try_new(&req.status, school.get_attendance_statuses())?; |
| 567 | let target = match req.user_id { | 567 | let target = match req.user_id { |
| 568 | Some(ref key) => UserId::from_key(key), | 568 | Some(ref key) => UserId::from_key(key), |
| 569 | - None => user.get_id().clone(), | 569 | + None => *user.get_id(), |
| 570 | }; | 570 | }; |
| 571 | 571 | ||
| 572 | // Target user must exist. | 572 | // Target user must exist. |
| @@ -628,7 +628,7 @@ async fn list_attendance( | |||
| 628 | // Join people onto the page alone — the lookup shrinks with the window. | 628 | // Join people onto the page alone — the lookup shrinks with the window. |
| 629 | let people = person_map( | 629 | let people = person_map( |
| 630 | rows.iter() | 630 | rows.iter() |
| 631 | - .flat_map(|a| [a.get_user().clone(), a.get_marked_by().clone()]), | 631 | + .flat_map(|a| [*a.get_user(), *a.get_marked_by()]), |
| 632 | &st.db, | 632 | &st.db, |
| 633 | ) | 633 | ) |
| 634 | .await?; | 634 | .await?; |
| @@ -723,7 +723,7 @@ async fn roster( | |||
| 723 | 723 | ||
| 724 | let mut members = service::event::members(&st.db, &event).await?; | 724 | let mut members = service::event::members(&st.db, &event).await?; |
| 725 | // ULID keys sort by creation instant — a stable order keeps pages coherent. | 725 | // ULID keys sort by creation instant — a stable order keeps pages coherent. |
| 726 | - members.sort_by(|a, b| a.key().cmp(&b.key())); | 726 | + members.sort_by_key(|a| a.key()); |
| 727 | let (marks, _) = crate::service::attendance::list_for_event(&st.db, &event_id, None, 0).await?; | 727 | let (marks, _) = crate::service::attendance::list_for_event(&st.db, &event_id, None, 0).await?; |
| 728 | let by_user: HashMap<String, &Attendance> = marks | 728 | let by_user: HashMap<String, &Attendance> = marks |
| 729 | .iter() | 729 | .iter() |
| @@ -737,7 +737,7 @@ async fn roster( | |||
| 737 | let ids = window.iter().cloned().chain(window.iter().filter_map(|m| { | 737 | let ids = window.iter().cloned().chain(window.iter().filter_map(|m| { |
| 738 | by_user | 738 | by_user |
| 739 | .get(m.key().as_str()) | 739 | .get(m.key().as_str()) |
| 740 | - .map(|attendance| attendance.get_marked_by().clone()) | 740 | + .map(|attendance| *attendance.get_marked_by()) |
| 741 | })); | 741 | })); |
| 742 | let people = person_map(ids, &st.db).await?; | 742 | let people = person_map(ids, &st.db).await?; |
| 743 | let items = window | 743 | let items = window |
| @@ -813,7 +813,7 @@ async fn register( | |||
| 813 | 813 | ||
| 814 | let target = match req.user_id { | 814 | let target = match req.user_id { |
| 815 | Some(ref key) => UserId::from_key(key), | 815 | Some(ref key) => UserId::from_key(key), |
| 816 | - None => user.get_id().clone(), | 816 | + None => *user.get_id(), |
| 817 | }; | 817 | }; |
| 818 | let Some(target_user) = crate::service::user::read(&st.db, &target).await? else { | 818 | let Some(target_user) = crate::service::user::read(&st.db, &target).await? else { |
| 819 | return Err(AppError::Validation(ValidationError::Invalid { | 819 | return Err(AppError::Validation(ValidationError::Invalid { |
| @@ -835,8 +835,8 @@ async fn register( | |||
| 835 | // the {target, caller} pair may not contain. | 835 | // the {target, caller} pair may not contain. |
| 836 | let people = person_map( | 836 | let people = person_map( |
| 837 | [ | 837 | [ |
| 838 | - registration.get_user().clone(), | 838 | + *registration.get_user(), |
| 839 | - registration.get_registered_by().clone(), | 839 | + *registration.get_registered_by(), |
| 840 | ], | 840 | ], |
| 841 | &st.db, | 841 | &st.db, |
| 842 | ) | 842 | ) |
src/web/exam_ws.rsmodified+1 -2
| @@ -93,7 +93,6 @@ const ROOM: &str = "exam room"; | |||
| 93 | /// stamp can never erase a join's clear of a marker it did not make. The | 93 | /// stamp can never erase a join's clear of a marker it did not make. The |
| 94 | /// join's clear lands milliseconds after the door's read-only rejoin | 94 | /// join's clear lands milliseconds after the door's read-only rejoin |
| 95 | /// check, which no HTTP caller can observe. | 95 | /// check, which no HTTP caller can observe. |
| 96 | - | ||
| 97 | /// What the client asked for, tagged by `type`. | 96 | /// What the client asked for, tagged by `type`. |
| 98 | #[derive(Deserialize)] | 97 | #[derive(Deserialize)] |
| 99 | #[serde(tag = "type", rename_all = "snake_case", deny_unknown_fields)] | 98 | #[serde(tag = "type", rename_all = "snake_case", deny_unknown_fields)] |
| @@ -147,7 +146,7 @@ pub async fn attempt_ws( | |||
| 147 | check_rejoin(&exam, &attempt)?; | 146 | check_rejoin(&exam, &attempt)?; |
| 148 | crate::service::course::require_open(&st.db, &course_of(&exam, &st.db).await?).await?; | 147 | crate::service::course::require_open(&st.db, &course_of(&exam, &st.db).await?).await?; |
| 149 | 148 | ||
| 150 | - let user_id = user.get_id().clone(); | 149 | + let user_id = *user.get_id(); |
| 151 | Ok(ws.on_upgrade(move |socket| room(socket, st, slug, exam, attempt, user_id))) | 150 | Ok(ws.on_upgrade(move |socket| room(socket, st, slug, exam, attempt, user_id))) |
| 152 | } | 151 | } |
| 153 | 152 | ||
src/web/exams/attempts.rsmodified+2 -2
| @@ -376,7 +376,7 @@ pub(crate) async fn live_snapshot( | |||
| 376 | entry.0 += 1; | 376 | entry.0 += 1; |
| 377 | entry.1 = entry.1.max(answer.get_updated_at().as_millis()); | 377 | entry.1 = entry.1.max(answer.get_updated_at().as_millis()); |
| 378 | } | 378 | } |
| 379 | - let people = person_map(roster.iter().map(|e| e.get_user().clone()), db).await?; | 379 | + let people = person_map(roster.iter().map(|e| *e.get_user()), db).await?; |
| 380 | 380 | ||
| 381 | // Once the window closes the door is shut for good (starting answers | 381 | // Once the window closes the door is shut for good (starting answers |
| 382 | // 409), so "hasn't started" hardens into "was absent". Open exams have | 382 | // 409), so "hasn't started" hardens into "was absent". Open exams have |
| @@ -761,7 +761,7 @@ pub(crate) async fn answer_sheet( | |||
| 761 | .map(|question| (question.get_id().key(), question)) | 761 | .map(|question| (question.get_id().key(), question)) |
| 762 | .collect(); | 762 | .collect(); |
| 763 | let (earned, possible) = auto_score(&questions, &answers); | 763 | let (earned, possible) = auto_score(&questions, &answers); |
| 764 | - let people = person_map([target.clone()], db).await?; | 764 | + let people = person_map([*target], db).await?; |
| 765 | Ok(AttemptAnswersResponse { | 765 | Ok(AttemptAnswersResponse { |
| 766 | exam: exam.get_id().key().to_string(), | 766 | exam: exam.get_id().key().to_string(), |
| 767 | user: PersonRef::resolve(&people, target), | 767 | user: PersonRef::resolve(&people, target), |
src/web/exams/mod.rsmodified+2 -2
| @@ -590,7 +590,7 @@ async fn list_results( | |||
| 590 | let rows = paginate(&results, limit, offset); | 590 | let rows = paginate(&results, limit, offset); |
| 591 | let people = person_map( | 591 | let people = person_map( |
| 592 | rows.iter() | 592 | rows.iter() |
| 593 | - .flat_map(|r| [r.get_user().clone(), r.get_graded_by().clone()]), | 593 | + .flat_map(|r| [*r.get_user(), *r.get_graded_by()]), |
| 594 | &st.db, | 594 | &st.db, |
| 595 | ) | 595 | ) |
| 596 | .await?; | 596 | .await?; |
| @@ -624,7 +624,7 @@ async fn my_result( | |||
| 624 | .await? | 624 | .await? |
| 625 | .ok_or(AppError::NotFound)?; | 625 | .ok_or(AppError::NotFound)?; |
| 626 | let people = person_map( | 626 | let people = person_map( |
| 627 | - [result.get_user().clone(), result.get_graded_by().clone()], | 627 | + [*result.get_user(), *result.get_graded_by()], |
| 628 | &st.db, | 628 | &st.db, |
| 629 | ) | 629 | ) |
| 630 | .await?; | 630 | .await?; |
src/web/exams/questions.rsmodified+4 -4
| @@ -325,7 +325,7 @@ pub(crate) async fn update_question( | |||
| 325 | Some(ref subject_id) => { | 325 | Some(ref subject_id) => { |
| 326 | service::subject::in_course(&st.db, subject_id, course.get_id()).await? | 326 | service::subject::in_course(&st.db, subject_id, course.get_id()).await? |
| 327 | } | 327 | } |
| 328 | - None => question.get_subject().clone(), | 328 | + None => *question.get_subject(), |
| 329 | }; | 329 | }; |
| 330 | let text = match req.text { | 330 | let text = match req.text { |
| 331 | Some(ref text) => QuestionText::try_new(text)?, | 331 | Some(ref text) => QuestionText::try_new(text)?, |
| @@ -655,7 +655,7 @@ pub(crate) async fn question_refresh_from_bank( | |||
| 655 | 655 | ||
| 656 | // The question's own subject stays: it is checked against the exam's | 656 | // The question's own subject stays: it is checked against the exam's |
| 657 | // course, and the template's is origin metadata from anywhere in school. | 657 | // course, and the template's is origin metadata from anywhere in school. |
| 658 | - let subject = question.get_subject().clone(); | 658 | + let subject = *question.get_subject(); |
| 659 | // `spec()` hands over the template's stored choices *with their ids* rather | 659 | // `spec()` hands over the template's stored choices *with their ids* rather |
| 660 | // than re-minting any — the same funnel `question_from_bank` uses. | 660 | // than re-minting any — the same funnel `question_from_bank` uses. |
| 661 | let updated = exam_question::update( | 661 | let updated = exam_question::update( |
| @@ -751,8 +751,8 @@ pub(crate) async fn question_to_bank( | |||
| 751 | // question's fields plus the origin exam it was saved off. | 751 | // question's fields plus the origin exam it was saved off. |
| 752 | let template = bank_question::create_from_exam( | 752 | let template = bank_question::create_from_exam( |
| 753 | &st.db, | 753 | &st.db, |
| 754 | - user.get_id().clone(), | 754 | + *user.get_id(), |
| 755 | - question.get_subject().clone(), | 755 | + *question.get_subject(), |
| 756 | question.get_text().clone(), | 756 | question.get_text().clone(), |
| 757 | question.get_points(), | 757 | question.get_points(), |
| 758 | question.spec(), | 758 | question.spec(), |
src/web/exams/review.rsmodified+2 -2
| @@ -161,7 +161,7 @@ pub(crate) async fn student_marks_history( | |||
| 161 | let people = person_map( | 161 | let people = person_map( |
| 162 | results | 162 | results |
| 163 | .iter() | 163 | .iter() |
| 164 | - .flat_map(|r| [r.get_user().clone(), r.get_graded_by().clone()]), | 164 | + .flat_map(|r| [*r.get_user(), *r.get_graded_by()]), |
| 165 | &st.db, | 165 | &st.db, |
| 166 | ) | 166 | ) |
| 167 | .await?; | 167 | .await?; |
| @@ -305,7 +305,7 @@ pub(crate) async fn review_attempts( | |||
| 305 | Path(id): Path<String>, | 305 | Path(id): Path<String>, |
| 306 | ) -> Result<Json<Vec<i64>>, AppError> { | 306 | ) -> Result<Json<Vec<i64>>, AppError> { |
| 307 | let exam = reviewable_exam(&st, &user, &id).await?; | 307 | let exam = reviewable_exam(&st, &user, &id).await?; |
| 308 | - let target = user.get_id().clone(); | 308 | + let target = *user.get_id(); |
| 309 | let mut seqs = | 309 | let mut seqs = |
| 310 | crate::service::exam_answer::list_seqs_for_user(&st.db, exam.get_id(), &target).await?; | 310 | crate::service::exam_answer::list_seqs_for_user(&st.db, exam.get_id(), &target).await?; |
| 311 | for result in | 311 | for result in |
src/web/meals.rsmodified+13 -13
| @@ -205,7 +205,7 @@ async fn menu_responses( | |||
| 205 | ) -> Result<Vec<MenuResponse>, AppError> { | 205 | ) -> Result<Vec<MenuResponse>, AppError> { |
| 206 | let ids: Vec<MenuId> = menus.iter().map(|menu| menu.get_id().clone()).collect(); | 206 | let ids: Vec<MenuId> = menus.iter().map(|menu| menu.get_id().clone()).collect(); |
| 207 | let dishes = service::menu::list_dishes_for_menus(db, &ids).await?; | 207 | let dishes = service::menu::list_dishes_for_menus(db, &ids).await?; |
| 208 | - let people = person_map(menus.iter().map(|menu| menu.get_created_by().clone()), db).await?; | 208 | + let people = person_map(menus.iter().map(|menu| *menu.get_created_by()), db).await?; |
| 209 | let viewer_tags = service::dietary_profile::tags_of(db, viewer).await?; | 209 | let viewer_tags = service::dietary_profile::tags_of(db, viewer).await?; |
| 210 | Ok(menus | 210 | Ok(menus |
| 211 | .iter() | 211 | .iter() |
| @@ -220,7 +220,7 @@ async fn one_menu( | |||
| 220 | db: &Database, | 220 | db: &Database, |
| 221 | ) -> Result<Json<MenuResponse>, AppError> { | 221 | ) -> Result<Json<MenuResponse>, AppError> { |
| 222 | let dishes = service::menu::list_dishes(db, menu.get_id()).await?; | 222 | let dishes = service::menu::list_dishes(db, menu.get_id()).await?; |
| 223 | - let people = person_map([menu.get_created_by().clone()], db).await?; | 223 | + let people = person_map([*menu.get_created_by()], db).await?; |
| 224 | let viewer_tags = service::dietary_profile::tags_of(db, viewer).await?; | 224 | let viewer_tags = service::dietary_profile::tags_of(db, viewer).await?; |
| 225 | Ok(Json(MenuResponse::new( | 225 | Ok(Json(MenuResponse::new( |
| 226 | menu, | 226 | menu, |
| @@ -573,8 +573,8 @@ async fn profile_response( | |||
| 573 | ) -> Result<Json<DietaryProfileResponse>, AppError> { | 573 | ) -> Result<Json<DietaryProfileResponse>, AppError> { |
| 574 | let profile = service::dietary_profile::read(db, student).await?; | 574 | let profile = service::dietary_profile::read(db, student).await?; |
| 575 | let people = person_map( | 575 | let people = person_map( |
| 576 | - std::iter::once(student.clone()) | 576 | + std::iter::once(*student) |
| 577 | - .chain(profile.as_ref().map(|row| row.get_updated_by().clone())), | 577 | + .chain(profile.as_ref().map(|row| *row.get_updated_by())), |
| 578 | db, | 578 | db, |
| 579 | ) | 579 | ) |
| 580 | .await?; | 580 | .await?; |
| @@ -745,8 +745,8 @@ async fn booking_responses( | |||
| 745 | let people = person_map( | 745 | let people = person_map( |
| 746 | bookings.iter().flat_map(|booking| { | 746 | bookings.iter().flat_map(|booking| { |
| 747 | [ | 747 | [ |
| 748 | - booking.get_student().clone(), | 748 | + *booking.get_student(), |
| 749 | - booking.get_booked_by().clone(), | 749 | + *booking.get_booked_by(), |
| 750 | ] | 750 | ] |
| 751 | }), | 751 | }), |
| 752 | db, | 752 | db, |
| @@ -786,7 +786,7 @@ async fn booking_target( | |||
| 786 | Some(id) if id != caller.get_id().key() => Err(AppError::Forbidden( | 786 | Some(id) if id != caller.get_id().key() => Err(AppError::Forbidden( |
| 787 | "a student books meals only for themselves", | 787 | "a student books meals only for themselves", |
| 788 | )), | 788 | )), |
| 789 | - _ => Ok(caller.get_id().clone()), | 789 | + _ => Ok(*caller.get_id()), |
| 790 | }, | 790 | }, |
| 791 | Role::Parent => { | 791 | Role::Parent => { |
| 792 | let target = UserId::from_key(student_id.ok_or(AppError::Validation( | 792 | let target = UserId::from_key(student_id.ok_or(AppError::Validation( |
| @@ -889,13 +889,13 @@ async fn my_bookings( | |||
| 889 | let (limit, offset) = page.resolve()?; | 889 | let (limit, offset) = page.resolve()?; |
| 890 | // Own seats always; a parent's children only while the link is live — the | 890 | // Own seats always; a parent's children only while the link is live — the |
| 891 | // booking row's `booked_by` is history, never a standing read grant. | 891 | // booking row's `booked_by` is history, never a standing read grant. |
| 892 | - let mut students = vec![user.get_id().clone()]; | 892 | + let mut students = vec![*user.get_id()]; |
| 893 | if user.get_role() == Role::Parent { | 893 | if user.get_role() == Role::Parent { |
| 894 | students.extend( | 894 | students.extend( |
| 895 | crate::service::parent_link::list_for_parent(&st.db, user.get_id()) | 895 | crate::service::parent_link::list_for_parent(&st.db, user.get_id()) |
| 896 | .await? | 896 | .await? |
| 897 | .iter() | 897 | .iter() |
| 898 | - .map(|link| link.get_student().clone()), | 898 | + .map(|link| *link.get_student()), |
| 899 | ); | 899 | ); |
| 900 | } | 900 | } |
| 901 | let (rows, total) = | 901 | let (rows, total) = |
| @@ -1065,7 +1065,7 @@ struct MealAttendanceResponse { | |||
| 1065 | impl MealAttendanceResponse { | 1065 | impl MealAttendanceResponse { |
| 1066 | fn new(row: &MealAttendance, people: &std::collections::HashMap<String, PersonRef>) -> Self { | 1066 | fn new(row: &MealAttendance, people: &std::collections::HashMap<String, PersonRef>) -> Self { |
| 1067 | Self { | 1067 | Self { |
| 1068 | - id: MealAttendanceId::composite(row.get_menu(), &row.get_student()).key(), | 1068 | + id: MealAttendanceId::composite(row.get_menu(), row.get_student()).key(), |
| 1069 | menu_id: row.get_menu().key().to_string(), | 1069 | menu_id: row.get_menu().key().to_string(), |
| 1070 | student: PersonRef::resolve(people, row.get_student()), | 1070 | student: PersonRef::resolve(people, row.get_student()), |
| 1071 | status: row.get_status().as_str().to_string(), | 1071 | status: row.get_status().as_str().to_string(), |
| @@ -1082,7 +1082,7 @@ async fn attendance_responses( | |||
| 1082 | ) -> Result<Vec<MealAttendanceResponse>, AppError> { | 1082 | ) -> Result<Vec<MealAttendanceResponse>, AppError> { |
| 1083 | let people = person_map( | 1083 | let people = person_map( |
| 1084 | rows.iter() | 1084 | rows.iter() |
| 1085 | - .flat_map(|row| [row.get_student().clone(), row.get_marked_by().clone()]), | 1085 | + .flat_map(|row| [*row.get_student(), *row.get_marked_by()]), |
| 1086 | db, | 1086 | db, |
| 1087 | ) | 1087 | ) |
| 1088 | .await?; | 1088 | .await?; |
| @@ -1286,7 +1286,7 @@ async fn ledger_responses( | |||
| 1286 | let people = person_map( | 1286 | let people = person_map( |
| 1287 | lines | 1287 | lines |
| 1288 | .iter() | 1288 | .iter() |
| 1289 | - .flat_map(|line| [line.get_student().clone(), line.get_recorded_by().clone()]), | 1289 | + .flat_map(|line| [*line.get_student(), *line.get_recorded_by()]), |
| 1290 | db, | 1290 | db, |
| 1291 | ) | 1291 | ) |
| 1292 | .await?; | 1292 | .await?; |
| @@ -1301,7 +1301,7 @@ async fn balance_response( | |||
| 1301 | student: &UserId, | 1301 | student: &UserId, |
| 1302 | db: &Database, | 1302 | db: &Database, |
| 1303 | ) -> Result<Json<BalanceResponse>, AppError> { | 1303 | ) -> Result<Json<BalanceResponse>, AppError> { |
| 1304 | - let people = person_map(std::iter::once(student.clone()), db).await?; | 1304 | + let people = person_map(std::iter::once(*student), db).await?; |
| 1305 | Ok(Json(BalanceResponse { | 1305 | Ok(Json(BalanceResponse { |
| 1306 | student: PersonRef::resolve(&people, student), | 1306 | student: PersonRef::resolve(&people, student), |
| 1307 | balance_minor: service::meal_ledger::balance_of(db, student).await?, | 1307 | balance_minor: service::meal_ledger::balance_of(db, student).await?, |
src/web/messages.rsmodified+2 -2
| @@ -115,8 +115,8 @@ async fn load_people(messages: &[Message], db: &Database) -> Result<People, AppE | |||
| 115 | .iter() | 115 | .iter() |
| 116 | .flat_map(|message| { | 116 | .flat_map(|message| { |
| 117 | [ | 117 | [ |
| 118 | - message.get_sender().clone(), | 118 | + *message.get_sender(), |
| 119 | - message.get_recipient().clone(), | 119 | + *message.get_recipient(), |
| 120 | ] | 120 | ] |
| 121 | }) | 121 | }) |
| 122 | .filter(|id| seen.insert(id.key().to_string())) | 122 | .filter(|id| seen.insert(id.key().to_string())) |
src/web/mod.rsmodified+3 -3
| @@ -403,7 +403,7 @@ mod tests { | |||
| 403 | ClassName::try_new("9-A").unwrap(), | 403 | ClassName::try_new("9-A").unwrap(), |
| 404 | None, | 404 | None, |
| 405 | None, | 405 | None, |
| 406 | - Some(teacher.get_id().clone()), | 406 | + Some(*teacher.get_id()), |
| 407 | ) | 407 | ) |
| 408 | .await | 408 | .await |
| 409 | .unwrap(); | 409 | .unwrap(); |
| @@ -456,8 +456,8 @@ mod tests { | |||
| 456 | assert_eq!( | 456 | assert_eq!( |
| 457 | stored(class.get_id(), course.get_id(), &db).await, | 457 | stored(class.get_id(), course.get_id(), &db).await, |
| 458 | ( | 458 | ( |
| 459 | - Some(teacher.get_id().clone()), | 459 | + Some(*teacher.get_id()), |
| 460 | - vec![teacher.get_id().clone()] | 460 | + vec![*teacher.get_id()] |
| 461 | ), | 461 | ), |
| 462 | "nothing may be undone while the bar still holds" | 462 | "nothing may be undone while the bar still holds" |
| 463 | ); | 463 | ); |
src/web/payments.rsmodified+5 -5
| @@ -153,7 +153,7 @@ async fn plan_responses( | |||
| 153 | plans: &[FeePlan], | 153 | plans: &[FeePlan], |
| 154 | db: &Database, | 154 | db: &Database, |
| 155 | ) -> Result<Vec<FeePlanResponse>, AppError> { | 155 | ) -> Result<Vec<FeePlanResponse>, AppError> { |
| 156 | - let people = person_map(plans.iter().map(|plan| plan.get_created_by().clone()), db).await?; | 156 | + let people = person_map(plans.iter().map(|plan| *plan.get_created_by()), db).await?; |
| 157 | Ok(plans | 157 | Ok(plans |
| 158 | .iter() | 158 | .iter() |
| 159 | .map(|plan| FeePlanResponse::new(plan, &people)) | 159 | .map(|plan| FeePlanResponse::new(plan, &people)) |
| @@ -457,7 +457,7 @@ async fn list_plan_assignments( | |||
| 457 | service::fee_plan_assignment::list_for_plan(&st.db, plan.get_id(), limit, offset).await?; | 457 | service::fee_plan_assignment::list_for_plan(&st.db, plan.get_id(), limit, offset).await?; |
| 458 | let people = person_map( | 458 | let people = person_map( |
| 459 | rows.iter() | 459 | rows.iter() |
| 460 | - .flat_map(|row| [row.get_student().clone(), row.get_assigned_by().clone()]), | 460 | + .flat_map(|row| [*row.get_student(), *row.get_assigned_by()]), |
| 461 | &st.db, | 461 | &st.db, |
| 462 | ) | 462 | ) |
| 463 | .await?; | 463 | .await?; |
| @@ -523,7 +523,7 @@ async fn line_responses( | |||
| 523 | let people = person_map( | 523 | let people = person_map( |
| 524 | lines | 524 | lines |
| 525 | .iter() | 525 | .iter() |
| 526 | - .flat_map(|line| [line.get_student().clone(), line.get_recorded_by().clone()]), | 526 | + .flat_map(|line| [*line.get_student(), *line.get_recorded_by()]), |
| 527 | db, | 527 | db, |
| 528 | ) | 528 | ) |
| 529 | .await?; | 529 | .await?; |
| @@ -948,7 +948,7 @@ async fn statement_response( | |||
| 948 | }) | 948 | }) |
| 949 | .collect(); | 949 | .collect(); |
| 950 | 950 | ||
| 951 | - let people = person_map(std::iter::once(student.clone()), db).await?; | 951 | + let people = person_map(std::iter::once(*student), db).await?; |
| 952 | Ok(Json(StatementResponse { | 952 | Ok(Json(StatementResponse { |
| 953 | student: PersonRef::resolve(&people, student), | 953 | student: PersonRef::resolve(&people, student), |
| 954 | entries: Page::new(entries, total, limit, offset), | 954 | entries: Page::new(entries, total, limit, offset), |
| @@ -1026,7 +1026,7 @@ async fn balance_response( | |||
| 1026 | student: &UserId, | 1026 | student: &UserId, |
| 1027 | db: &Database, | 1027 | db: &Database, |
| 1028 | ) -> Result<Json<PaymentBalanceResponse>, AppError> { | 1028 | ) -> Result<Json<PaymentBalanceResponse>, AppError> { |
| 1029 | - let people = person_map(std::iter::once(student.clone()), db).await?; | 1029 | + let people = person_map(std::iter::once(*student), db).await?; |
| 1030 | Ok(Json(PaymentBalanceResponse { | 1030 | Ok(Json(PaymentBalanceResponse { |
| 1031 | student: PersonRef::resolve(&people, student), | 1031 | student: PersonRef::resolve(&people, student), |
| 1032 | balance_minor: service::payment_ledger::balance_of(db, student).await?, | 1032 | balance_minor: service::payment_ledger::balance_of(db, student).await?, |
src/web/questions.rsmodified+5 -5
| @@ -221,12 +221,12 @@ async fn question_responses( | |||
| 221 | st: &AppState, | 221 | st: &AppState, |
| 222 | ) -> Result<Vec<PoolQuestionResponse>, AppError> { | 222 | ) -> Result<Vec<PoolQuestionResponse>, AppError> { |
| 223 | let ids = questions.iter().flat_map(|question| { | 223 | let ids = questions.iter().flat_map(|question| { |
| 224 | - std::iter::once(question.get_asker().clone()).chain(question.get_approved_by().cloned()) | 224 | + std::iter::once(*question.get_asker()).chain(question.get_approved_by().cloned()) |
| 225 | }); | 225 | }); |
| 226 | let people = person_map(ids, &st.db).await?; | 226 | let people = person_map(ids, &st.db).await?; |
| 227 | let question_ids: Vec<PoolQuestionId> = questions | 227 | let question_ids: Vec<PoolQuestionId> = questions |
| 228 | .iter() | 228 | .iter() |
| 229 | - .map(|question| question.get_id().clone()) | 229 | + .map(|question| *question.get_id()) |
| 230 | .collect(); | 230 | .collect(); |
| 231 | let counts = solution::counts_for(&st.db, &question_ids).await?; | 231 | let counts = solution::counts_for(&st.db, &question_ids).await?; |
| 232 | Ok(questions | 232 | Ok(questions |
| @@ -644,7 +644,7 @@ async fn offer_solution( | |||
| 644 | Solution::new(question.get_id(), user.get_id(), body), | 644 | Solution::new(question.get_id(), user.get_id(), body), |
| 645 | ) | 645 | ) |
| 646 | .await?; | 646 | .await?; |
| 647 | - let people = person_map([user.get_id().clone()], &st.db).await?; | 647 | + let people = person_map([*user.get_id()], &st.db).await?; |
| 648 | Ok(( | 648 | Ok(( |
| 649 | StatusCode::CREATED, | 649 | StatusCode::CREATED, |
| 650 | Json(SolutionResponse::new(&solution, &people)), | 650 | Json(SolutionResponse::new(&solution, &people)), |
| @@ -679,7 +679,7 @@ async fn list_solutions( | |||
| 679 | let (solutions, total) = solution::list_for(&st.db, question.get_id(), limit, offset).await?; | 679 | let (solutions, total) = solution::list_for(&st.db, question.get_id(), limit, offset).await?; |
| 680 | let slice = solutions.as_slice(); | 680 | let slice = solutions.as_slice(); |
| 681 | let people = person_map( | 681 | let people = person_map( |
| 682 | - slice.iter().map(|solution| solution.get_author().clone()), | 682 | + slice.iter().map(|solution| *solution.get_author()), |
| 683 | &st.db, | 683 | &st.db, |
| 684 | ) | 684 | ) |
| 685 | .await?; | 685 | .await?; |
| @@ -763,7 +763,7 @@ async fn edit_solution( | |||
| 763 | let updated = solution::set_body(&st.db, solution.get_id(), &body) | 763 | let updated = solution::set_body(&st.db, solution.get_id(), &body) |
| 764 | .await? | 764 | .await? |
| 765 | .ok_or(AppError::NotFound)?; | 765 | .ok_or(AppError::NotFound)?; |
| 766 | - let people = person_map([user.get_id().clone()], &st.db).await?; | 766 | + let people = person_map([*user.get_id()], &st.db).await?; |
| 767 | Ok(Json(SolutionResponse::new(&updated, &people))) | 767 | Ok(Json(SolutionResponse::new(&updated, &people))) |
| 768 | } | 768 | } |
| 769 | 769 | ||
src/web/sessions.rsmodified+6 -7
| @@ -77,7 +77,7 @@ struct SessionAttendanceResponse { | |||
| 77 | impl SessionAttendanceResponse { | 77 | impl SessionAttendanceResponse { |
| 78 | fn new(attendance: &SessionAttendance, people: &HashMap<String, PersonRef>) -> Self { | 78 | fn new(attendance: &SessionAttendance, people: &HashMap<String, PersonRef>) -> Self { |
| 79 | Self { | 79 | Self { |
| 80 | - id: SessionAttendanceId::composite(attendance.get_session(), &attendance.get_user()).key(), | 80 | + id: SessionAttendanceId::composite(attendance.get_session(), attendance.get_user()).key(), |
| 81 | session: attendance.get_session().key().to_string(), | 81 | session: attendance.get_session().key().to_string(), |
| 82 | course: attendance.get_course().key().to_string(), | 82 | course: attendance.get_course().key().to_string(), |
| 83 | user: PersonRef::resolve(people, attendance.get_user()), | 83 | user: PersonRef::resolve(people, attendance.get_user()), |
| @@ -145,7 +145,7 @@ async fn get_session( | |||
| 145 | "only enrolled users, the session teacher, the course's teachers, or a manager/admin can view this session", | 145 | "only enrolled users, the session teacher, the course's teachers, or a manager/admin can view this session", |
| 146 | )); | 146 | )); |
| 147 | } | 147 | } |
| 148 | - let people = person_map([session.get_teacher().clone()], &st.db).await?; | 148 | + let people = person_map([*session.get_teacher()], &st.db).await?; |
| 149 | Ok(Json(SessionResponse::new(&session, &people))) | 149 | Ok(Json(SessionResponse::new(&session, &people))) |
| 150 | } | 150 | } |
| 151 | 151 | ||
| @@ -199,10 +199,9 @@ async fn update_session( | |||
| 199 | .transpose()?; | 199 | .transpose()?; |
| 200 | let teacher = match req.teacher_id { | 200 | let teacher = match req.teacher_id { |
| 201 | Some(ref key) => Some( | 201 | Some(ref key) => Some( |
| 202 | - service::course_session::resolve_session_teacher(Some(key), &user, &st.db) | 202 | + *service::course_session::resolve_session_teacher(Some(key), &user, &st.db) |
| 203 | .await? | 203 | .await? |
| 204 | - .get_id() | 204 | + .get_id(), |
| 205 | - .clone(), | ||
| 206 | ), | 205 | ), |
| 207 | None => None, | 206 | None => None, |
| 208 | }; | 207 | }; |
| @@ -217,7 +216,7 @@ async fn update_session( | |||
| 217 | let updated = | 216 | let updated = |
| 218 | service::course_session::update(&st.db, session, teacher, topic, starts_at, ends_at) | 217 | service::course_session::update(&st.db, session, teacher, topic, starts_at, ends_at) |
| 219 | .await?; | 218 | .await?; |
| 220 | - let people = person_map([updated.get_teacher().clone()], &st.db).await?; | 219 | + let people = person_map([*updated.get_teacher()], &st.db).await?; |
| 221 | Ok(Json(SessionResponse::new(&updated, &people))) | 220 | Ok(Json(SessionResponse::new(&updated, &people))) |
| 222 | } | 221 | } |
| 223 | 222 | ||
| @@ -338,7 +337,7 @@ async fn list_roll_call( | |||
| 338 | // Join people onto the page alone — the lookup shrinks with the window. | 337 | // Join people onto the page alone — the lookup shrinks with the window. |
| 339 | let people = person_map( | 338 | let people = person_map( |
| 340 | rows.iter() | 339 | rows.iter() |
| 341 | - .flat_map(|a| [a.get_user().clone(), a.get_marked_by().clone()]), | 340 | + .flat_map(|a| [*a.get_user(), *a.get_marked_by()]), |
| 342 | &st.db, | 341 | &st.db, |
| 343 | ) | 342 | ) |
| 344 | .await?; | 343 | .await?; |
src/web/users.rsmodified+1 -1
| @@ -539,7 +539,7 @@ async fn students_page( | |||
| 539 | let links = crate::service::parent_link::list_for_parent(db, parent).await?; | 539 | let links = crate::service::parent_link::list_for_parent(db, parent).await?; |
| 540 | let ids: Vec<UserId> = links | 540 | let ids: Vec<UserId> = links |
| 541 | .iter() | 541 | .iter() |
| 542 | - .map(|link| link.get_student().clone()) | 542 | + .map(|link| *link.get_student()) |
| 543 | .collect(); | 543 | .collect(); |
| 544 | let mut students = crate::service::user::list_by_ids(db, &ids).await?; | 544 | let mut students = crate::service::user::list_by_ids(db, &ids).await?; |
| 545 | // The link row alone is not the grant, exactly as [`ensure_can_observe`] | 545 | // The link row alone is not the grant, exactly as [`ensure_can_observe`] |
tests/integration.rsmodified+1 -1
| @@ -22213,7 +22213,7 @@ async fn concurrent_ledger_appends_of_one_id_write_one_line_not_a_500() { | |||
| 22213 | .await | 22213 | .await |
| 22214 | .expect("read the booking") | 22214 | .expect("read the booking") |
| 22215 | .expect("the booking exists"); | 22215 | .expect("the booking exists"); |
| 22216 | - let student = booking.get_student().clone(); | 22216 | + let student = *booking.get_student(); |
| 22217 | assert_eq!( | 22217 | assert_eq!( |
| 22218 | meal_ledger::balance_of(&db, &student).await.unwrap(), | 22218 | meal_ledger::balance_of(&db, &student).await.unwrap(), |
| 22219 | -1000, | 22219 | -1000, |
tests/name_refs.rsmodified+0 -2
| @@ -46,7 +46,6 @@ fn listed_kinds(body: &Value) -> Vec<String> { | |||
| 46 | /// A graded student, an exam of `kind`, and the manager's cookie. | 46 | /// A graded student, an exam of `kind`, and the manager's cookie. |
| 47 | struct School { | 47 | struct School { |
| 48 | app: axum::Router, | 48 | app: axum::Router, |
| 49 | - db: hezarfen_backend::database::Database, | ||
| 50 | boss: String, | 49 | boss: String, |
| 51 | course: String, | 50 | course: String, |
| 52 | exam: String, | 51 | exam: String, |
| @@ -72,7 +71,6 @@ async fn school_with_kinds(names: &[&str]) -> School { | |||
| 72 | let exam = create_exam(&app, &boss, &course, "Midterm", names[0]).await; | 71 | let exam = create_exam(&app, &boss, &course, "Midterm", names[0]).await; |
| 73 | School { | 72 | School { |
| 74 | app, | 73 | app, |
| 75 | - db, | ||
| 76 | boss, | 74 | boss, |
| 77 | course, | 75 | course, |
| 78 | exam, | 76 | exam, |
tests/regress_homework_orphans.rsmodified+0 -1
| @@ -28,7 +28,6 @@ use common::{ | |||
| 28 | use hezarfen_backend::database::Database; | 28 | use hezarfen_backend::database::Database; |
| 29 | use hezarfen_backend::domain::user::UserId; | 29 | use hezarfen_backend::domain::user::UserId; |
| 30 | use serde_json::{Value, json}; | 30 | use serde_json::{Value, json}; |
| 31 | -use sqlx::Row as _; | ||
| 32 | 31 | ||
| 33 | /// A due date comfortably clear of the 60s past-scheduling grace. | 32 | /// A due date comfortably clear of the 60s past-scheduling grace. |
| 34 | fn far_future() -> i64 { | 33 | fn far_future() -> i64 { |
tests/regress_role_sweep.rsmodified+1 -1
| @@ -138,7 +138,7 @@ async fn demote_in_the_window( | |||
| 138 | db: &Database, | 138 | db: &Database, |
| 139 | ) -> tokio::task::JoinHandle<()> { | 139 | ) -> tokio::task::JoinHandle<()> { |
| 140 | let handle = { | 140 | let handle = { |
| 141 | - let (student, db) = (student.clone(), db.clone()); | 141 | + let (student, db) = (*student, db.clone()); |
| 142 | tokio::spawn(async move { demote(&student, to, &db).await }) | 142 | tokio::spawn(async move { demote(&student, to, &db).await }) |
| 143 | }; | 143 | }; |
| 144 | // race-window staging — do not convert to poll | 144 | // race-window staging — do not convert to poll |
tests/regress_roles.rsmodified+0 -1
| @@ -13,7 +13,6 @@ use common::{app_and_db, id_of, login, login_as, me_id, send}; | |||
| 13 | use hezarfen_backend::database::Database; | 13 | use hezarfen_backend::database::Database; |
| 14 | use hezarfen_backend::domain::timestamp::Timestamp; | 14 | use hezarfen_backend::domain::timestamp::Timestamp; |
| 15 | use serde_json::json; | 15 | use serde_json::json; |
| 16 | -use sqlx::Row as _; | ||
| 17 | 16 | ||
| 18 | /// One counter, re-read out of the store — never off a response body. `sql` | 17 | /// One counter, re-read out of the store — never off a response body. `sql` |
| 19 | /// is a whole scalar query. | 18 | /// is a whole scalar query. |