From 0c89256c782f0d1e98e93047fa90ad90b4e003e3 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 14 Jan 2026 22:36:54 +0100 Subject: Touch the 'updated_at' column on exercise success MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the user runs into an exercise and is satisfied with the results, then touch the 'updated_at' column for that exercise. This is relevant because in practice exercises are selected by the lastly updated exercise. Signed-off-by: Miquel Sabaté Solà --- lib/mihi/src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib') diff --git a/lib/mihi/src/lib.rs b/lib/mihi/src/lib.rs index 2915368..4d337b9 100644 --- a/lib/mihi/src/lib.rs +++ b/lib/mihi/src/lib.rs @@ -856,6 +856,25 @@ pub fn update_exercise(exercise: Exercise) -> Result<(), String> { } } +/// Updates the 'updated_at' column for an exercise. +pub fn touch_exercise(exercise: Exercise) -> Result<(), String> { + if exercise.id == 0 { + return Err("invalid exercise to update; seems it has not been created before".to_string()); + } + + let conn = get_connection()?; + + match conn.execute( + "UPDATE exercises \ + SET updated_at = datetime('now') \ + WHERE id = ?1", + params![exercise.id], + ) { + Ok(_) => Ok(()), + Err(e) => Err(format!("could not update '{}': {}", exercise.title, e)), + } +} + /// Delete an exercise from the database. pub fn delete_exercise(title: &str) -> Result<(), String> { let conn = get_connection()?; -- cgit v1.2.3