Skip to content

Commit

Permalink
corrected data source and updated db
Browse files Browse the repository at this point in the history
  • Loading branch information
emoltz committed May 29, 2024
1 parent 5a25239 commit f569cc9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
20 changes: 6 additions & 14 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions api/migrations/0009_food_initial_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.3 on 2024-05-29 20:24

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0008_meal_most_recent_follow_up'),
]

operations = [
migrations.AddField(
model_name='food',
name='initial_description',
field=models.TextField(blank=True, null=True),
),
]
1 change: 1 addition & 0 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Food(models.Model):
"""
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=255, default="")
initial_description = models.TextField(blank=True, null=True)
# the system with nutritional info is on a *range* of values, so we need to store the min and max values
# all values are in grams
calories_min = models.FloatField(default=0)
Expand Down
3 changes: 3 additions & 0 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,12 @@ def post(self, request):
food_serializer = FoodSerializer(data=response)
if food_serializer.is_valid():
food = food_serializer.save()
food.initial_description = description
food.save()
else:
raise ErrorMessage("Error saving food data to database")


self.add_food_to_meal(user, food, meal_type, date_str, name)

# before returning, add the db id to the response json
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
services:
db:
image: postgres
image: postgres:latest
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data/

Expand Down

0 comments on commit f569cc9

Please sign in to comment.