diff --git a/src/main.rs b/src/main.rs index 67900ba..bab6a79 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,6 +51,11 @@ async fn main() { pool.close().await; } +//-************************************************************************ +// the two route hanlders +//-************************************************************************ + +/// This is the main handler. It counts the hit and returns the latest count. #[debug_handler] async fn register_hit( Path(slug): Path, @@ -91,6 +96,7 @@ async fn register_hit( format!("{hits}") } +/// fer fancy people what want to be a little finer #[axum::debug_handler] async fn get_hits( State(db): State, @@ -120,17 +126,6 @@ async fn get_hits( format!("{count}") } -async fn get_period_hits(db: &SqlitePool, page: &str, when: &str) -> i32 { - sqlx::query_scalar!( - "select count(*) from hits where page = ? and accessed > ?", - page, - when - ) - .fetch_one(db) - .await - .unwrap_or(0) -} - //-************************************************************************ // li'l helpers //-************************************************************************ @@ -226,3 +221,14 @@ fn shasum(input: &[u8]) -> Vec { context.update(input); context.finish().as_ref().to_vec() } + +async fn get_period_hits(db: &SqlitePool, page: &str, when: &str) -> i32 { + sqlx::query_scalar!( + "select count(*) from hits where page = ? and accessed > ?", + page, + when + ) + .fetch_one(db) + .await + .unwrap_or(0) +}