diff --git a/src/domain/pool_question.rs b/src/domain/pool_question.rs index e7e7be6..720a6ad 100644 --- a/src/domain/pool_question.rs +++ b/src/domain/pool_question.rs @@ -162,7 +162,10 @@ impl PoolQuestion { created.ok_or_else(|| AppError::Internal("failed to create pool question".into())) } - pub async fn read(id: &PoolQuestionId, db: &Database) -> Result, AppError> { + pub async fn read( + id: &PoolQuestionId, + db: &Database, + ) -> Result, AppError> { Ok(db.select(id.record()).await?) } @@ -355,7 +358,13 @@ mod tests { // The asker sees their own pending question plus the pool; a stranger // sees only the pool; the teacher view (list_all) sees everything. - assert_eq!(PoolQuestion::list_visible_to(&asker, &db).await.unwrap().len(), 2); + assert_eq!( + PoolQuestion::list_visible_to(&asker, &db) + .await + .unwrap() + .len(), + 2 + ); let stranger_view = PoolQuestion::list_visible_to(&other, &db).await.unwrap(); assert_eq!(stranger_view.len(), 1); assert_eq!(stranger_view[0].get_id(), published.get_id()); @@ -444,14 +453,27 @@ mod tests { // The swept solutions ride back with the question so the caller can // take their image blobs off disk. - let (removed, swept) = PoolQuestion::delete(q.get_id(), &db).await.unwrap().unwrap(); + let (removed, swept) = PoolQuestion::delete(q.get_id(), &db) + .await + .unwrap() + .unwrap(); assert_eq!(removed.get_id(), q.get_id()); assert_eq!(swept.len(), 1); assert_eq!(swept[0].get_id(), offered.get_id()); assert!(PoolQuestion::read(q.get_id(), &db).await.unwrap().is_none()); - assert!(Solution::list_for(q.get_id(), &db).await.unwrap().is_empty()); + assert!( + Solution::list_for(q.get_id(), &db) + .await + .unwrap() + .is_empty() + ); // Deleting the already-deleted is None, not an error. - assert!(PoolQuestion::delete(q.get_id(), &db).await.unwrap().is_none()); + assert!( + PoolQuestion::delete(q.get_id(), &db) + .await + .unwrap() + .is_none() + ); } } diff --git a/src/domain/solution.rs b/src/domain/solution.rs index 89b8501..3d3d319 100644 --- a/src/domain/solution.rs +++ b/src/domain/solution.rs @@ -223,10 +223,7 @@ impl Solution { /// Detach the solution's image. Returns the *before* row — its /// `image_file` is the blob the caller must remove. - pub async fn clear_image( - id: &SolutionId, - db: &Database, - ) -> Result, AppError> { + pub async fn clear_image(id: &SolutionId, db: &Database) -> Result, AppError> { let mut result = db .query( "UPDATE $s SET image_file = NONE, image_content_type = NONE, image_size = NONE \ @@ -276,7 +273,12 @@ mod tests { assert_eq!(listed.len(), 2); assert_eq!(listed[0].get_id(), first.get_id()); assert_eq!(listed[1].get_id(), second.get_id()); - assert!(Solution::list_for(&question_b, &db).await.unwrap().is_empty()); + assert!( + Solution::list_for(&question_b, &db) + .await + .unwrap() + .is_empty() + ); // Readable under its own question, invisible under another. assert!( @@ -418,10 +420,9 @@ mod tests { } } - let counts = - Solution::counts_for(&[two.clone(), one.clone(), none.clone()], &db) - .await - .unwrap(); + let counts = Solution::counts_for(&[two.clone(), one.clone(), none.clone()], &db) + .await + .unwrap(); assert_eq!(counts.get(two.key()), Some(&2)); assert_eq!(counts.get(one.key()), Some(&1)); // No solutions = no entry; the caller reads the miss as zero. @@ -435,7 +436,9 @@ mod tests { assert!(SolutionBody::try_new(" ").is_err()); assert!(SolutionBody::try_new(&"x".repeat(10_001)).is_err()); assert_eq!( - SolutionBody::try_new("Kısmi integrasyon.").unwrap().as_str(), + SolutionBody::try_new("Kısmi integrasyon.") + .unwrap() + .as_str(), "Kısmi integrasyon." ); } diff --git a/src/main.rs b/src/main.rs index fdbbe8f..f6a49cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,9 +61,8 @@ fn keepalive(db: Database, health: DbHealth) { hezarfen_backend::constant::DB_KEEPALIVE_INTERVAL_SECS, )); interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Delay); - let ping_timeout = std::time::Duration::from_secs( - hezarfen_backend::constant::DB_PING_TIMEOUT_SECS, - ); + let ping_timeout = + std::time::Duration::from_secs(hezarfen_backend::constant::DB_PING_TIMEOUT_SECS); loop { interval.tick().await; // ponytail: an abandoned ping stays queued in the SDK and replays diff --git a/src/web/questions.rs b/src/web/questions.rs index ce46028..c4a8c34 100644 --- a/src/web/questions.rs +++ b/src/web/questions.rs @@ -167,12 +167,12 @@ impl PoolQuestionResponse { approved_by: question .get_approved_by() .map(|approver| PersonRef::resolve(people, approver)), - image: question.get_image_content_type().map(|content_type| { - PoolImageMeta { + image: question + .get_image_content_type() + .map(|content_type| PoolImageMeta { content_type: content_type.as_str().to_string(), size: question.get_image_size().unwrap_or(0), - } - }), + }), solution_count, } } @@ -202,12 +202,12 @@ impl SolutionResponse { author: PersonRef::resolve(people, solution.get_author()), body: solution.get_body().as_str().to_string(), offered_at: solution.get_offered_at().as_millis(), - image: solution.get_image_content_type().map(|content_type| { - PoolImageMeta { + image: solution + .get_image_content_type() + .map(|content_type| PoolImageMeta { content_type: content_type.as_str().to_string(), size: solution.get_image_size().unwrap_or(0), - } - }), + }), } } } @@ -220,8 +220,7 @@ async fn question_responses( st: &AppState, ) -> Result, AppError> { let ids = questions.iter().flat_map(|question| { - std::iter::once(question.get_asker().clone()) - .chain(question.get_approved_by().cloned()) + std::iter::once(question.get_asker().clone()).chain(question.get_approved_by().cloned()) }); let people = person_map(ids, &st.db).await?; let question_ids: Vec = questions @@ -376,8 +375,8 @@ async fn approve_question( RequireTeacher(user): RequireTeacher, Path(id): Path, ) -> Result, AppError> { - let approved = PoolQuestion::approve(&PoolQuestionId::from_key(&id), user.get_id(), &st.db) - .await?; + let approved = + PoolQuestion::approve(&PoolQuestionId::from_key(&id), user.get_id(), &st.db).await?; let question = match approved { Some(question) => question, // Nothing was pending under that id: either it's already approved diff --git a/tests/persistence.rs b/tests/persistence.rs index 690e242..246c944 100644 --- a/tests/persistence.rs +++ b/tests/persistence.rs @@ -6,8 +6,8 @@ mod common; -use axum::http::StatusCode; use axum::Router; +use axum::http::StatusCode; use common::{create_course, create_exam, enroll, me_id, send, set_role}; use hezarfen_backend::database::Database; use hezarfen_backend::rate_limit::RateLimitConfig;