tidy
This commit is contained in:
parent
aad60a5752
commit
e96a993f9a
1 changed files with 17 additions and 11 deletions
28
src/main.rs
28
src/main.rs
|
@ -51,6 +51,11 @@ async fn main() {
|
||||||
pool.close().await;
|
pool.close().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-************************************************************************
|
||||||
|
// the two route hanlders
|
||||||
|
//-************************************************************************
|
||||||
|
|
||||||
|
/// This is the main handler. It counts the hit and returns the latest count.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
async fn register_hit(
|
async fn register_hit(
|
||||||
Path(slug): Path<String>,
|
Path(slug): Path<String>,
|
||||||
|
@ -91,6 +96,7 @@ async fn register_hit(
|
||||||
format!("{hits}")
|
format!("{hits}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// fer fancy people what want to be a little finer
|
||||||
#[axum::debug_handler]
|
#[axum::debug_handler]
|
||||||
async fn get_hits(
|
async fn get_hits(
|
||||||
State(db): State<SqlitePool>,
|
State(db): State<SqlitePool>,
|
||||||
|
@ -120,17 +126,6 @@ async fn get_hits(
|
||||||
format!("{count}")
|
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
|
// li'l helpers
|
||||||
//-************************************************************************
|
//-************************************************************************
|
||||||
|
@ -226,3 +221,14 @@ fn shasum(input: &[u8]) -> Vec<u8> {
|
||||||
context.update(input);
|
context.update(input);
|
||||||
context.finish().as_ref().to_vec()
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue