Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nutrition Tracker Feature #36

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f183bf4
Added I Ate This switch
Nov 11, 2020
607f7ac
Created consumed calories table def. and nutrition tracking frontend
Nov 11, 2020
1a54ddd
fixing merge conflicts
Nov 11, 2020
1e68b09
Fixing merge conflicts
Nov 11, 2020
20b0d3f
Fixing merge conflicts
Nov 11, 2020
00d0bec
Work in progress on migrating consumed recipes table to DB
Nov 12, 2020
150786c
Created consumed recipes table
Nov 12, 2020
10f0e14
Merge branch 'master' of https://github.com/ECE444-2020Fall/project1-…
Nov 14, 2020
a4c5f66
Created methods to add, delete, and retrieve recipes from consumed re…
Nov 14, 2020
c51b318
Merge branch 'master' of https://github.com/ECE444-2020Fall/project1-…
Nov 14, 2020
a9394e4
Changed switch component name to RecipeConsumedToggle and added it to…
Nov 14, 2020
3edaf84
Added nutrition info aggregation function and corrected variable name…
Nov 14, 2020
8746f64
Combined the retrieve consumed recipes and calculate nutrition facts …
Nov 15, 2020
06a0440
Fixing merge conflicts with master
Nov 15, 2020
04c16b6
Removed nutrition facts total endpoint in server.py
Nov 15, 2020
9c391ad
Implemented the frontend/Javascript component for the nutrition track…
Nov 15, 2020
14fe272
Merge branch 'master' of https://github.com/ECE444-2020Fall/project1-…
Nov 15, 2020
3dbb61a
Fixed syntax errors in backend
Nov 16, 2020
2bf3a2c
Merge branch 'master' of https://github.com/ECE444-2020Fall/project1-…
Nov 16, 2020
f58bb5e
Merge branch 'master' of https://github.com/ECE444-2020Fall/project1-…
Nov 16, 2020
9f14ddb
Fixed bugs with the nutrition tracker feature
Nov 17, 2020
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
1 change: 1 addition & 0 deletions migrations/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generic single-database configuration.
45 changes: 45 additions & 0 deletions migrations/alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# A generic, single database configuration.

[alembic]
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false


# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
96 changes: 96 additions & 0 deletions migrations/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
from __future__ import with_statement

import logging
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool

from alembic import context

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
logger = logging.getLogger('alembic.env')

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from flask import current_app
config.set_main_option(
'sqlalchemy.url',
str(current_app.extensions['migrate'].db.engine.url).replace('%', '%%'))
target_metadata = current_app.extensions['migrate'].db.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline():
"""Run migrations in 'offline' mode.

This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.

Calls to context.execute() here emit the given string to the
script output.

"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True
)

with context.begin_transaction():
context.run_migrations()


def run_migrations_online():
"""Run migrations in 'online' mode.

In this scenario we need to create an Engine
and associate a connection with the context.

"""

# this callback is used to prevent an auto-migration from being generated
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False):
script = directives[0]
if script.upgrade_ops.is_empty():
directives[:] = []
logger.info('No changes in schema detected.')

connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool,
)

with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args
)

with context.begin_transaction():
context.run_migrations()


if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
26 changes: 26 additions & 0 deletions migrations/script.py.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""${message}

Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}

"""
from alembic import op
import sqlalchemy as sa
import app
import sqlalchemy_utils
${imports if imports else ""}

# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}


def upgrade():
${upgrades if upgrades else "pass"}


def downgrade():
${downgrades if downgrades else "pass"}
26 changes: 26 additions & 0 deletions migrations/versions/05006b3b0796_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""empty message

Revision ID: 05006b3b0796
Revises: 0f31a634899d
Create Date: 2020-11-08 23:04:11.320857

"""
from alembic import op
import sqlalchemy as sa
import app
import sqlalchemy_utils


# revision identifiers, used by Alembic.
revision = '05006b3b0796'
down_revision = '0f31a634899d'
branch_labels = None
depends_on = None


def upgrade():
pass


def downgrade():
pass
49 changes: 49 additions & 0 deletions migrations/versions/0d57cdde0bc8_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""empty message

Revision ID: 0d57cdde0bc8
Revises: 806bba569271
Create Date: 2020-10-23 00:51:53.656538

"""
from alembic import op
import sqlalchemy as sa
import app
import sqlalchemy_utils


# revision identifiers, used by Alembic.
revision = '0d57cdde0bc8'
down_revision = '806bba569271'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('recipe',
sa.Column('recipe_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False),
sa.Column('recipe_name', sa.String(length=100), nullable=False),
sa.Column('cuisine', sa.String(length=100), nullable=False),
sa.Column('instructions', sa.String(length=100), nullable=False),
sa.Column('time_to_cook_in_minutes', sa.Integer(), nullable=False),
sa.Column('servings', sa.Integer(), nullable=False),
sa.Column('calories', sa.Float(), nullable=False),
sa.Column('protein', sa.Float(), nullable=False),
sa.Column('carbs', sa.Float(), nullable=False),
sa.Column('fat', sa.Float(), nullable=False),
sa.PrimaryKeyConstraint('recipe_id'),
sa.UniqueConstraint('recipe_id')
)
op.create_table('favourites_list',
sa.Column('user_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['recipe.recipe_id'], ),
sa.PrimaryKeyConstraint('user_id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('favourites_list')
op.drop_table('recipe')
# ### end Alembic commands ###
36 changes: 36 additions & 0 deletions migrations/versions/0f31a634899d_move_table_schemas_to_folder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""move table schemas to folder

Revision ID: 0f31a634899d
Revises: ce09ed6c70ee
Create Date: 2020-10-23 01:28:44.823984

"""
from alembic import op
import sqlalchemy as sa
import app
import sqlalchemy_utils
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = '0f31a634899d'
down_revision = 'ce09ed6c70ee'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('user_notes', sa.Column('user_notes', sa.String(length=500), nullable=False))
op.drop_column('user_notes', 'user_nodes')
op.add_column('user_rating', sa.Column('user_rating', sa.Float(), nullable=False))
op.drop_column('user_rating', 'user_nodes')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('user_rating', sa.Column('user_nodes', mysql.FLOAT(), nullable=False))
op.drop_column('user_rating', 'user_rating')
op.add_column('user_notes', sa.Column('user_nodes', mysql.VARCHAR(length=500), nullable=False))
op.drop_column('user_notes', 'user_notes')
# ### end Alembic commands ###
30 changes: 30 additions & 0 deletions migrations/versions/33d490ad9a9a_update_fav_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""update fav list

Revision ID: 33d490ad9a9a
Revises: 5d9adc826605
Create Date: 2020-11-10 23:58:16.545883

"""
from alembic import op
import sqlalchemy as sa
import app
import sqlalchemy_utils


# revision identifiers, used by Alembic.
revision = '33d490ad9a9a'
down_revision = '5d9adc826605'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('recipe_cart_ibfk_1', 'recipe_cart', type_='foreignkey')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_foreign_key('recipe_cart_ibfk_1', 'recipe_cart', 'recipe', ['recipe_id'], ['recipe_id'])
# ### end Alembic commands ###
32 changes: 32 additions & 0 deletions migrations/versions/3461c9ab2ed8_update_fav_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""update fav list

Revision ID: 3461c9ab2ed8
Revises: e15c9f833955
Create Date: 2020-11-10 19:42:36.068792

"""
from alembic import op
import sqlalchemy as sa
import app
import sqlalchemy_utils


# revision identifiers, used by Alembic.
revision = '3461c9ab2ed8'
down_revision = 'e15c9f833955'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_foreign_key(None, 'favourites_list', 'user', ['user_id'], ['user_id'])
op.create_foreign_key(None, 'favourites_list', 'recipe', ['recipe_id'], ['recipe_id'])
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'favourites_list', type_='foreignkey')
op.drop_constraint(None, 'favourites_list', type_='foreignkey')
# ### end Alembic commands ###
47 changes: 47 additions & 0 deletions migrations/versions/5d9adc826605_update_fav_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""update fav list

Revision ID: 5d9adc826605
Revises: e9e8638813b7
Create Date: 2020-11-10 20:45:18.626007

"""
from alembic import op
import sqlalchemy as sa
import app
import sqlalchemy_utils
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = '5d9adc826605'
down_revision = 'e9e8638813b7'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('user_favourites',
sa.Column('user_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False),
sa.Column('recipe_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['user.user_id'], ),
sa.PrimaryKeyConstraint('user_id', 'recipe_id')
)
op.drop_table('favourites_list')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('favourites_list',
sa.Column('user_id', sa.BINARY(length=16), nullable=False),
sa.Column('recipe_id', sa.BINARY(length=16), nullable=False),
sa.Column('temp', mysql.VARCHAR(length=50), nullable=True),
sa.ForeignKeyConstraint(['recipe_id'], ['recipe.recipe_id'], name='favourites_list_ibfk_2'),
sa.ForeignKeyConstraint(['user_id'], ['user.user_id'], name='favourites_list_ibfk_1'),
sa.PrimaryKeyConstraint('user_id'),
mysql_collate='utf8mb4_0900_ai_ci',
mysql_default_charset='utf8mb4',
mysql_engine='InnoDB'
)
op.drop_table('user_favourites')
# ### end Alembic commands ###
Loading