diff --git a/src/model/stat.rs b/src/model/stat.rs index 4f6ced9..77922f9 100644 --- a/src/model/stat.rs +++ b/src/model/stat.rs @@ -1,3 +1,4 @@ +use crate::model::user::User; use serde::Serialize; use sqlx::{FromRow, Row, SqlitePool}; @@ -41,3 +42,26 @@ ORDER BY rowed_km DESC; .collect() } } + +#[derive(Debug, Serialize)] +pub struct PersonalStat { + date: String, + km: i32, +} + +pub async fn get_personal(db: &SqlitePool, user: &User) -> Vec { + vec![ + PersonalStat { + date: String::from("2023-01-01"), + km: 5, + }, + PersonalStat { + date: String::from("2023-02-01"), + km: 24, + }, + PersonalStat { + date: String::from("2023-08-30"), + km: 1340, + }, + ] +} diff --git a/src/tera/stat.rs b/src/tera/stat.rs index dc611ef..1e39aa9 100644 --- a/src/tera/stat.rs +++ b/src/tera/stat.rs @@ -2,13 +2,17 @@ use rocket::{get, routes, Route, State}; use rocket_dyn_templates::{context, Template}; use sqlx::SqlitePool; -use crate::model::{stat::Stat, user::User}; +use crate::model::{ + stat::{self, Stat}, + user::User, +}; #[get("/")] async fn index(db: &State, user: User) -> Template { let stat = Stat::get_rowed_km(db).await; + let personal = stat::get_personal(db, &user).await; - Template::render("stat", context!(loggedin_user: &user, stat)) + Template::render("stat", context!(loggedin_user: &user, stat, personal)) } pub fn routes() -> Vec { diff --git a/templates/stat.html.tera b/templates/stat.html.tera index 820eeae..5d274fd 100644 --- a/templates/stat.html.tera +++ b/templates/stat.html.tera @@ -43,10 +43,11 @@ import * as d3 from "https://cdn.jsdelivr.net/npm/d3@7/+esm"; const data = [ - { date: '2023-01-01', km: 5 }, - { date: '2023-02-01', km: 24 }, - { date: '2023-08-30', km: 1340 }, + {%- for p in personal %} + { date: '{{p.date}}', km: {{p.km}} }, + {%- endfor %} ]; +console.log(data); const margin = { top: 20, right: 20, bottom: 50, left: 50 }, width = 960 - margin.left - margin.right,