diff --git a/src/lib/components/AggregatedFood/AggregatedFoodTable.svelte b/src/lib/components/AggregatedFood/AggregatedFoodTable.svelte
new file mode 100644
index 0000000..8afce5e
--- /dev/null
+++ b/src/lib/components/AggregatedFood/AggregatedFoodTable.svelte
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+ Period
+ |
+
+ Amount
+ |
+
+ AvgPer100
+ |
+
+ Energy
+ |
+
+
+
+ {#each items as f}
+
+ {/each}
+
+
+
+
+
+
+
diff --git a/src/lib/components/FoodComp.svelte b/src/lib/components/Food/FoodComp.svelte
similarity index 100%
rename from src/lib/components/FoodComp.svelte
rename to src/lib/components/Food/FoodComp.svelte
diff --git a/src/lib/components/Food/FoodTable.svelte b/src/lib/components/Food/FoodTable.svelte
new file mode 100644
index 0000000..b4aee71
--- /dev/null
+++ b/src/lib/components/Food/FoodTable.svelte
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+ Date
+ |
+
+ Food
+ |
+
+ Description
+ |
+
+ Amount
+ |
+
+ Cal Per 100
+ |
+
+ Energy
+ |
+
+
+
+ {#if create}
+
+ {/if}
+ {#each items as f}
+
+ {/each}
+
+
+
+
+
+
+
diff --git a/src/lib/database/food.ts b/src/lib/database/food.ts
index 9872699..322c7a9 100644
--- a/src/lib/database/food.ts
+++ b/src/lib/database/food.ts
@@ -12,6 +12,7 @@ export type Food = {
}
const columns = ['rowid', 'date', 'food', 'description', 'amount', 'per100', 'energy']
+const aggColumns = ['date', 'amount', 'avgPer100', 'energy']
const FoodService = {
async GetAll() {
@@ -30,7 +31,6 @@ or strftime('%Y-%m-%d', date) = strftime('%Y-%m-%d', date('2024-06-12', '-1 day'
order by date DESC;
`, [date])
},
- // TODO: Rework this to use Err in Go style
async Create(food: Food): Promise<[Food[], Err]> {
if (!food.food) return [[food], 'food.food is required']
if (!food.amount) throw [[food], 'food.amount is required']
@@ -39,7 +39,23 @@ order by date DESC;
const row = await db.select(`select ${columns.join(', ')} from food where rowid = $1`, [res.lastInsertId])
return [row, null]
- }
+ },
+ async GetDaily(): Promise<[Food[], Err]> {
+ const rows = await db.select(`select ${aggColumns.join(', ')} from daily limit 100`)
+ return [rows, null]
+ },
+ async GetWeekly(): Promise<[Food[], Err]> {
+ const rows = await db.select(`select ${aggColumns.join(', ')} from weekly limit 100`)
+ return [rows, null]
+ },
+ async GetMonthly(): Promise<[Food[], Err]> {
+ const rows = await db.select(`select ${aggColumns.join(', ')} from monthly limit 100`)
+ return [rows, null]
+ },
+ async GetYearly(): Promise<[Food[], Err]> {
+ const rows = await db.select(`select ${aggColumns.join(', ')} from yearly limit 100`)
+ return [rows, null]
+ },
}
export { FoodService }
diff --git a/src/lib/router/Router.svelte b/src/lib/router/Router.svelte
index e3f4446..6609799 100644
--- a/src/lib/router/Router.svelte
+++ b/src/lib/router/Router.svelte
@@ -2,13 +2,11 @@
import Router from 'svelte-spa-router'
import Home from '$lib/router/routes/Home.svelte'
- import IPC from '$lib/router/routes/IPC.svelte'
- import Versions from '$router/routes/Versions.svelte'
+ import Daily from '$router/routes/Daily.svelte'
const routes = {
'/': Home,
- '/#ipc': IPC,
- '/#versions': Versions
+ '/daily': Daily
}
diff --git a/src/lib/router/routes/Daily.svelte b/src/lib/router/routes/Daily.svelte
new file mode 100644
index 0000000..cd0dc45
--- /dev/null
+++ b/src/lib/router/routes/Daily.svelte
@@ -0,0 +1,19 @@
+
+
+
+
+
diff --git a/src/lib/router/routes/Home.svelte b/src/lib/router/routes/Home.svelte
index 7fd235b..d0c7e7d 100644
--- a/src/lib/router/routes/Home.svelte
+++ b/src/lib/router/routes/Home.svelte
@@ -1,54 +1,8 @@
-
-
-
-
-
-
- Date
- |
-
- Food
- |
-
- Description
- |
-
- Amount
- |
-
- Cal Per 100
- |
-
- Energy
- |
-
-
-
-
- {#each $foodStore as f}
-
- {/each}
-
-
-
-
-
-
+