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