diff --git a/flake.nix b/flake.nix index f70093f..c98584e 100644 --- a/flake.nix +++ b/flake.nix @@ -20,6 +20,8 @@ pkgs.rust-analyzer pkgs.clippy pkgs.sqlite + pkgs.superhtml + pkgs.vscode-langservers-extracted ]; }; } diff --git a/tasks.db b/foods.db similarity index 85% rename from tasks.db rename to foods.db index 768836b..5ad494a 100644 Binary files a/tasks.db and b/foods.db differ diff --git a/src/create_tables.sql b/src/create_tables.sql index 1c23668..de99c88 100644 --- a/src/create_tables.sql +++ b/src/create_tables.sql @@ -1,6 +1,8 @@ -CREATE TABLE IF NOT EXISTS task ( +CREATE TABLE IF NOT EXISTS food ( id INTEGER PRIMARY KEY, + portion TEXT NOT NULL, name TEXT NOT NULL, - worth FLOAT NOT NULL DEFAULT 1.0, - times_completed INTEGER NOT NULL DEFAULT 0 + kc_per_serving INTEGER NOT NULL DEFAULT 0, + target_servings INTEGER NOT NULL DEFAULT 1, + actual_servings INTEGER NOT NULL DEFAULT 0 ); diff --git a/src/main.rs b/src/main.rs index 11c5683..3bae5b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,20 +7,22 @@ use askama::Template; #[derive(Template)] #[template(path = "index.html")] struct IndexTemplate { - tasks: Vec, + foods: Vec, } #[derive(Debug, Clone, PartialEq)] -struct Task { +struct Food { id: i32, - name: String, - worth: f32, - times_completed: i32, + portion: String, + name: String, + kc_per_serving: i32, + target_servings: i32, + actual_servings: i32, } #[tokio::main] async fn main() { - let db_connecion_str = "./tasks.db".to_string(); + let db_connecion_str = "./foods.db".to_string(); let conn = Connection::open(db_connecion_str).unwrap(); conn.execute(include_str!("create_tables.sql"), ()).unwrap(); let conn = Arc::new(Mutex::new(conn)); @@ -36,16 +38,18 @@ async fn root( State(conn): State>> ) -> Html { let conn = conn.lock().unwrap(); - let mut stmt = conn.prepare("SELECT id, name, worth, times_completed FROM task").unwrap(); - let tasks = stmt.query_map((), |row| { - Ok(Task { + let mut stmt = conn.prepare("SELECT id, portion, name, kc_per_serving, target_servings, actual_servings FROM food").unwrap(); + let foods = stmt.query_map((), |row| { + Ok(Food { id: row.get(0).unwrap(), - name: row.get(1).unwrap(), - worth: row.get(2).unwrap(), - times_completed: row.get(3).unwrap(), + portion: row.get(1).unwrap(), + name: row.get(2).unwrap(), + kc_per_serving: row.get(3).unwrap(), + target_servings: row.get(4).unwrap(), + actual_servings: row.get(5).unwrap(), }) }).unwrap().collect::>().unwrap(); - let index = IndexTemplate {tasks}; + let index = IndexTemplate {foods}; Html( index.render().unwrap() ) diff --git a/templates/index.html b/templates/index.html index ca97d97..ee967bd 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,21 +1,38 @@ - - - - - Task Counter - - -
-

Task Counter!

-
-
-
    - {% for task in tasks %} -
  • {{ task.name }}
  • + + + + + + Food Tracker + + + +
    + + + + + + + + {% for food in foods %} + + + + + + {% endfor %} - - - - +
    PortionLebensmittelkc.Servings (target)
    {{ food.portion }}{{ food.name }}{{ food.kc_per_serving }} + + food.target_servings %}style="accent-color: red;"{% endif %}> + {{ food.actual_servings }}/{{ food.target_servings }} + + +
    +
    + + + \ No newline at end of file