add bare '/hits' route
This commit is contained in:
parent
369915854c
commit
3d96092799
1 changed files with 3 additions and 2 deletions
|
@ -23,6 +23,7 @@ async fn main() {
|
|||
let pool = db().await;
|
||||
let app = Router::new()
|
||||
.route("/hit", get(register_hit))
|
||||
.route("/hits", get(get_hits))
|
||||
.route("/hits/:period", get(get_hits))
|
||||
.with_state(pool.clone())
|
||||
.into_make_service();
|
||||
|
@ -64,7 +65,7 @@ async fn register_hit(State(db): State<SqlitePool>, headers: HeaderMap) -> Strin
|
|||
#[axum::debug_handler]
|
||||
async fn get_hits(
|
||||
State(db): State<SqlitePool>,
|
||||
period: Path<String>,
|
||||
period: Option<Path<String>>,
|
||||
headers: HeaderMap,
|
||||
) -> String {
|
||||
let now = chrono::Utc::now();
|
||||
|
@ -81,7 +82,7 @@ async fn get_hits(
|
|||
};
|
||||
let page = &page;
|
||||
|
||||
let count = match period.as_str() {
|
||||
let count = match period.unwrap_or(Path("all".to_string())).as_str() {
|
||||
"day" => {
|
||||
let then = now - chrono::Duration::try_hours(24).unwrap();
|
||||
let then = then.to_rfc3339();
|
||||
|
|
Loading…
Reference in a new issue