fix mutliday support issues

This commit is contained in:
Khaïs COLIN 2025-10-29 12:43:58 +01:00
parent d7fc530201
commit 093962e1db
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
4 changed files with 16 additions and 15 deletions

BIN
foods.db

Binary file not shown.

View file

@ -12,7 +12,7 @@ LEFT JOIN
day_serving
ON
day_serving.food_id = food.id
WHERE
coalesce(day_serving.day, CURRENT_DATE) = CURRENT_DATE
AND coalesce(day_serving.day, CURRENT_DATE) = CURRENT_DATE
ORDER BY
sort_order, name;

View file

@ -1,11 +1,12 @@
SELECT
SUM(kc_per_serving * servings_eaten) AS kc,
SUM(protein_per_portion * servings_eaten) AS protein,
SUM(fiber_per_portion * servings_eaten) AS bs
SUM(kc_per_serving * coalesce(servings_eaten, 0)) AS kc,
SUM(protein_per_portion * coalesce(servings_eaten, 0)) AS protein,
SUM(fiber_per_portion * coalesce(servings_eaten, 0)) AS bs
FROM
food
LEFT JOIN
day_serving
ON
day_serving.food_id = food.id
AND day_serving.day = CURRENT_DATE;
AND coalesce(day_serving.day, CURRENT_DATE) = CURRENT_DATE;

View file

@ -1,9 +1,9 @@
UPDATE
day_serving
SET
servings_eaten = MAX(?2, 0)
WHERE
food_id = ?1
AND day = CURRENT_DATE
RETURNING
servings_eaten
INSERT OR REPLACE INTO
day_serving (day, food_id, servings_eaten)
VALUES (
CURRENT_DATE,
?1,
MAX(?2, 0)
)
RETURNING servings_eaten;