Skip to content

Commit a90b8d6

Browse files
committed
feat: calorie hiding
1 parent 8dda8bf commit a90b8d6

14 files changed

+200
-62
lines changed

.sqlx/query-17ce76bf70bf814026fa08d8cf43125eb2e2159c85bc4a7ee72accbd4d2635ce.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-5fabdcc10a1646502cedd111b91bec3cc4720637c3d95bc11f40c98b24bba64b.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

.sqlx/query-6e3f6e228c1f08bc7dfa5bb69d1184e209c4bb108ce71361b7b38bb359cdfa01.json renamed to .sqlx/query-97a33a00711c9588be5a21a2665261bb218414f7150cae028849322963057a1a.json

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
alter table user_preference
2+
add column hide_calories boolean default false not null;

src/balancing/checkpoint_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub async fn create_checkpoint(
185185
pub async fn delete_checkpoint(
186186
State(AppState { db }): State<AppState>,
187187
headers: HeaderMap,
188-
Form(checkpoint): Form<Checkpoint>,
188+
Query(checkpoint): Query<Checkpoint>,
189189
) -> Result<impl IntoResponse, ServerError> {
190190
let session = Session::from_headers_err(&headers, "delete checkpoint")?;
191191
query!(

src/balancing/compute_balancing.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ mod test {
211211
let history = [FoodItem {
212212
id: 1,
213213
eaten_event_id: 1,
214+
hide_calories: false,
214215
details: FoodItemDetails {
215216
calories: 2100,
216217
fat_grams: 0,
@@ -233,6 +234,7 @@ mod test {
233234
FoodItem {
234235
id: 1,
235236
eaten_event_id: 1,
237+
hide_calories: false,
236238
details: FoodItemDetails {
237239
calories: 2100,
238240
fat_grams: 0,
@@ -248,6 +250,7 @@ mod test {
248250
FoodItem {
249251
id: 2,
250252
eaten_event_id: 1,
253+
hide_calories: false,
251254
details: FoodItemDetails {
252255
calories: 2100,
253256
fat_grams: 0,
@@ -272,6 +275,7 @@ mod test {
272275
FoodItem {
273276
id: 1,
274277
eaten_event_id: 1,
278+
hide_calories: false,
275279
details: FoodItemDetails {
276280
calories: 2100,
277281
fat_grams: 0,
@@ -287,6 +291,7 @@ mod test {
287291
FoodItem {
288292
id: 2,
289293
eaten_event_id: 1,
294+
hide_calories: false,
290295
details: FoodItemDetails {
291296
calories: 2100,
292297
fat_grams: 0,
@@ -309,6 +314,7 @@ mod test {
309314
let history = [FoodItem {
310315
id: 1,
311316
eaten_event_id: 1,
317+
hide_calories: false,
312318
details: FoodItemDetails {
313319
calories: 1900,
314320
fat_grams: 0,
@@ -332,6 +338,7 @@ mod test {
332338
FoodItem {
333339
id: 1,
334340
eaten_event_id: 1,
341+
hide_calories: false,
335342
details: FoodItemDetails {
336343
calories: 2100,
337344
fat_grams: 0,
@@ -347,6 +354,7 @@ mod test {
347354
FoodItem {
348355
id: 2,
349356
eaten_event_id: 1,
357+
hide_calories: false,
350358
details: FoodItemDetails {
351359
calories: 2100,
352360
fat_grams: 0,
@@ -384,6 +392,7 @@ mod test {
384392
let history = [FoodItem {
385393
id: 1,
386394
eaten_event_id: 1,
395+
hide_calories: false,
387396
details: FoodItemDetails {
388397
calories: 1000,
389398
fat_grams: 0,
@@ -414,6 +423,7 @@ mod test {
414423
let history = [FoodItem {
415424
id: 1,
416425
eaten_event_id: 1,
426+
hide_calories: false,
417427
details: FoodItemDetails {
418428
calories: 3000,
419429
fat_grams: 0,
@@ -445,6 +455,7 @@ mod test {
445455
FoodItem {
446456
id: 1,
447457
eaten_event_id: 1,
458+
hide_calories: false,
448459
details: FoodItemDetails {
449460
calories: 4000,
450461
fat_grams: 0,
@@ -460,6 +471,7 @@ mod test {
460471
FoodItem {
461472
id: 1,
462473
eaten_event_id: 1,
474+
hide_calories: false,
463475
details: FoodItemDetails {
464476
calories: 2000,
465477
fat_grams: 0,
@@ -475,6 +487,7 @@ mod test {
475487
FoodItem {
476488
id: 1,
477489
eaten_event_id: 1,
490+
hide_calories: false,
478491
details: FoodItemDetails {
479492
calories: 2400,
480493
fat_grams: 0,
@@ -490,6 +503,7 @@ mod test {
490503
FoodItem {
491504
id: 1,
492505
eaten_event_id: 1,
506+
hide_calories: false,
493507
details: FoodItemDetails {
494508
calories: 1800,
495509
fat_grams: 0,
@@ -505,6 +519,7 @@ mod test {
505519
FoodItem {
506520
id: 1,
507521
eaten_event_id: 1,
522+
hide_calories: false,
508523
details: FoodItemDetails {
509524
calories: 1000,
510525
fat_grams: 0,

src/balancing/history_page.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ pub async fn get_relevant_food(
9898
.map(|row| FoodItem {
9999
id: row.id,
100100
eaten_event_id: row.eaten_event_id,
101+
hide_calories: preferences.hide_calories,
101102
details: FoodItemDetails {
102103
calories: row.calories,
103104
carbohydrates_grams: row.carbohydrates_grams,
@@ -115,7 +116,10 @@ pub async fn get_current_goal(
115116
db: impl PgExecutor<'_>,
116117
user_id: i32,
117118
preferences: &UserPreference,
118-
) -> Aresult<i32> {
119+
) -> Aresult<Option<i32>> {
120+
if !preferences.calorie_balancing_enabled {
121+
return Ok(preferences.caloric_intake_goal);
122+
};
119123
let relevant_food = get_relevant_food(db, user_id, preferences).await?;
120124
let balancing_history = compute_balancing(
121125
utc_now(),
@@ -127,7 +131,7 @@ pub async fn get_current_goal(
127131
preferences.calorie_balancing_min_calories,
128132
&relevant_food,
129133
);
130-
Ok(balancing_history.current_calorie_goal)
134+
Ok(Some(balancing_history.current_calorie_goal))
131135
}
132136

133137
pub async fn history(

src/components.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ impl Component for UserHome<'_> {
386386
.render();
387387
let chat = count_chat::ChatContainer {
388388
food_items: self.food_items,
389-
user_timezone: self.preferences.timezone,
389+
preferences: &self.preferences,
390390
prompt: None,
391391
next_page: 1,
392392
post_request_handler: Route::HandleChat,

src/controllers.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,14 @@ pub async fn user_home(
157157
let preferences = preferences?;
158158
let (macros, meals, sub_type, caloric_intake_goal) = join![
159159
metrics::get_macros(&db, session.user_id, &preferences),
160-
count_chat::list_meals_op(&db, user.id, 0),
160+
count_chat::list_meals_op(&db, user.id, &preferences, 0),
161161
stripe::get_subscription_type(&db, user.id),
162162
balancing::get_current_goal(&db, user.id, &preferences)
163163
];
164164
let macros = macros?;
165165
let meals = meals?;
166166
let sub_type = sub_type?;
167-
let caloric_intake_goal = if preferences.calorie_balancing_enabled {
168-
Some(caloric_intake_goal?)
169-
} else {
170-
preferences.caloric_intake_goal
171-
};
167+
let caloric_intake_goal = caloric_intake_goal?;
172168
let html = components::Page {
173169
title: "Home Page",
174170
children: &components::PageContainer {

0 commit comments

Comments
 (0)