Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Django ###
*.log
*.pot
.env
*.pyc
__pycache__/
local_settings.py
Expand Down
1 change: 1 addition & 0 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ name = "pypi"

[packages]
django = "*"
psycopg2-binary = "*"

[dev-packages]

Expand Down
81 changes: 80 additions & 1 deletion backend/Pipfile.lock

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

56 changes: 56 additions & 0 deletions backend/backend/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# * Make sure each ForeignKey and OneToOneField has `on_delete` set to the desired behavior
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from django.db import models

class Food(models.Model):
fdc_id = models.IntegerField(primary_key=True)
data_type = models.CharField(max_length=50, blank=True, null=True)
description = models.CharField(max_length=300, blank=True, null=True)
food_category_id = models.IntegerField()
publication_date = models.DateField(blank=True, null=True)

class Meta:
managed = False
db_table = 'food'


class FoodNutrient(models.Model):
fdc_id = models.IntegerField(blank=True, null=True)
nutrient_id = models.IntegerField(blank=True, null=True)
amount = models.FloatField(blank=True, null=True)
data_points = models.IntegerField(blank=True, null=True)
derivation_id = models.IntegerField(blank=True, null=True)
min = models.FloatField(blank=True, null=True)
max = models.FloatField(blank=True, null=True)
median = models.FloatField(blank=True, null=True)
footnote = models.CharField(max_length=300, blank=True, null=True)
min_year_acquired = models.CharField(max_length=50, blank=True, null=True)

class Meta:
managed = False
db_table = 'food_nutrient'


class Nutrient(models.Model):
name = models.TextField(blank=True, null=True)
unit_name = models.CharField(max_length=100, blank=True, null=True)
rank = models.FloatField(blank=True, null=True)
nutrient_nbr = models.FloatField(blank=True, null=True)

class Meta:
managed = False
db_table = 'nutrient'


class Test(models.Model):
first_name = models.CharField(max_length=50, blank=True, null=True)
last_name = models.CharField(max_length=50, blank=True, null=True)

class Meta:
managed = False
db_table = 'test'
11 changes: 8 additions & 3 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
https://docs.djangoproject.com/en/5.0/ref/settings/
"""

import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
Expand Down Expand Up @@ -37,6 +38,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'backend',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -75,12 +77,15 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD':os.environ.get('DB_PW'),
'HOST': 'localhost',
'PORT': 5432,
}
}


# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators

Expand Down
4 changes: 4 additions & 0 deletions backend/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
from django.contrib import admin
from django.urls import path

from . import views

urlpatterns = [
path('admin/', admin.site.urls),
path('api/nutrients', views.get_nutrients, name="status"),
path('api/randomItem', views.get_random_item, name="randomItem"),
]
34 changes: 34 additions & 0 deletions backend/backend/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import random

from django.http import HttpResponse

from .models import Food

random.seed()

# Views

def get_nutrients(request):
# Return HTTP response
if request.method == "GET":
result = []
for item in Food.objects.all():
result.append({"description": item.description, "fdc_id": item.fdc_id})
return HttpResponse(result,status=200)
else:
return HttpResponse(status=502)

# Retrieve list of foods and categories

# Submit request information

# Builds response

# Builds recommendations


# Retrieve random food item.
def get_random_item(request):
rand = str(random.randint(167512,175304))
query = Food.objects.get(fdc_id=rand)
return HttpResponse(query.description,status=200)
Empty file modified backend/manage.py
100644 → 100755
Empty file.
Loading