fake personal history

This commit is contained in:
philipp 2023-10-01 14:35:04 +02:00
parent 22642e3867
commit b797b8011d
3 changed files with 34 additions and 5 deletions

View File

@ -1,3 +1,4 @@
use crate::model::user::User;
use serde::Serialize; use serde::Serialize;
use sqlx::{FromRow, Row, SqlitePool}; use sqlx::{FromRow, Row, SqlitePool};
@ -41,3 +42,26 @@ ORDER BY rowed_km DESC;
.collect() .collect()
} }
} }
#[derive(Debug, Serialize)]
pub struct PersonalStat {
date: String,
km: i32,
}
pub async fn get_personal(db: &SqlitePool, user: &User) -> Vec<PersonalStat> {
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,
},
]
}

View File

@ -2,13 +2,17 @@ use rocket::{get, routes, Route, State};
use rocket_dyn_templates::{context, Template}; use rocket_dyn_templates::{context, Template};
use sqlx::SqlitePool; use sqlx::SqlitePool;
use crate::model::{stat::Stat, user::User}; use crate::model::{
stat::{self, Stat},
user::User,
};
#[get("/")] #[get("/")]
async fn index(db: &State<SqlitePool>, user: User) -> Template { async fn index(db: &State<SqlitePool>, user: User) -> Template {
let stat = Stat::get_rowed_km(db).await; 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<Route> { pub fn routes() -> Vec<Route> {

View File

@ -43,10 +43,11 @@ import * as d3 from "https://cdn.jsdelivr.net/npm/d3@7/+esm";
const data = [ const data = [
{ date: '2023-01-01', km: 5 }, {%- for p in personal %}
{ date: '2023-02-01', km: 24 }, { date: '{{p.date}}', km: {{p.km}} },
{ date: '2023-08-30', km: 1340 }, {%- endfor %}
]; ];
console.log(data);
const margin = { top: 20, right: 20, bottom: 50, left: 50 }, const margin = { top: 20, right: 20, bottom: 50, left: 50 },
width = 960 - margin.left - margin.right, width = 960 - margin.left - margin.right,