diff --git a/application/templates/base.html b/application/templates/base.html
index 36a4757..3cf8b6b 100644
--- a/application/templates/base.html
+++ b/application/templates/base.html
@@ -7,7 +7,7 @@
{% block title %}My Flask App{% endblock %}
-
+
diff --git a/application/user/routes.py b/application/user/routes.py
index 7e11c82..78e989d 100644
--- a/application/user/routes.py
+++ b/application/user/routes.py
@@ -1,8 +1,8 @@
from flask import Blueprint, redirect, url_for, render_template, flash
from flask_login import current_user
from application import db
-from forms import FoodItemForm
-from models import FoodItem
+from forms import FoodItemForm, FoodLogForm
+from models import FoodItem, FoodLog
user_bp = Blueprint(
"user",
@@ -113,7 +113,7 @@ def edit_food_item(id: int):
def food_item(barcode):
food = FoodItem.query.filter_by(barcode=barcode).first()
if food:
- return render_template("food_item.html", item=food)
+ return redirect(url_for("user.log_food", item_id=food.id))
else:
return render_template(
"add_food_item.html",
@@ -149,3 +149,22 @@ def add_food_item_manual():
db.session.commit()
return redirect(url_for("user.dashboard"))
return render_template("add_food_item_manual.html", form=form)
+
+
+@user_bp.route("/log_food/", methods=["GET", "POST"])
+def log_food(item_id):
+ form = FoodLogForm()
+ if item_id is not None:
+ if db.session.get(FoodItem, item_id):
+ if form.validate_on_submit():
+ assert form.amount.data is not None
+ db.session.add(
+ FoodLog(
+ item_id,
+ current_user.id,
+ form.amount.data,
+ )
+ )
+ db.session.commit()
+ return redirect(url_for("user.dashboard"))
+ return render_template("log_food.html", item_id=item_id, form=form)
diff --git a/application/user/templates/log_food.html b/application/user/templates/log_food.html
new file mode 100644
index 0000000..5ec13f2
--- /dev/null
+++ b/application/user/templates/log_food.html
@@ -0,0 +1,20 @@
+{% extends "base.html" %}
+
+{% block content %}
+
+{% endblock%}
\ No newline at end of file
diff --git a/forms.py b/forms.py
index ba71960..7c2c657 100644
--- a/forms.py
+++ b/forms.py
@@ -25,3 +25,8 @@ class FoodItemForm(FlaskForm):
fat = FloatField("fat per 100g", validators=[InputRequired()])
saturated_fat = FloatField("saturated_fat per 100g")
submit = SubmitField("Add Item")
+
+
+class FoodLogForm(FlaskForm):
+ amount = IntegerField("amount of food (g/ml)")
+ submit = SubmitField("Log Item")