Skip to content

Commit

Permalink
feat: add image_url field to Product model and update seed data
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerman70000 committed Jan 6, 2025
1 parent 63dbbc2 commit ccca78e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions backend/app/database/seeders.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,39 @@ def seed_products():
description="Pain relief and fever reduction tablets",
price=9.99,
expiry_date=datetime.now() + timedelta(days=365),
image_url="",
),
Product(
name="Vitamin C 1000mg",
manufacturer="Nature's Best",
description="Immune system support supplements",
price=14.99,
expiry_date=datetime.now() + timedelta(days=730),
image_url="",
),
Product(
name="Ibuprofen 200mg",
manufacturer="Advil",
description="Anti-inflammatory pain relief",
price=11.99,
expiry_date=datetime.now() + timedelta(days=365),
image_url="",
),
Product(
name="Allergy Relief",
manufacturer="Claritin",
description="24-hour allergy relief tablets",
price=19.99,
expiry_date=datetime.now() + timedelta(days=545),
image_url="",
),
Product(
name="First Aid Kit",
manufacturer="Johnson & Johnson",
description="Basic first aid supplies",
price=24.99,
expiry_date=datetime.now() + timedelta(days=1095),
image_url="",
),
]

Expand Down
1 change: 1 addition & 0 deletions backend/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Product(db.Model):
description = db.Column(db.Text, nullable=True)
price = db.Column(db.Float, nullable=False)
expiry_date = db.Column(db.Date, nullable=False)
image_url = db.Column(db.String(255), nullable=True)


class Cart(db.Model):
Expand Down
2 changes: 2 additions & 0 deletions backend/app/routes/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def get_products():
"description": product.description,
"price": product.price,
"expiry_date": product.expiry_date.isoformat(),
"image_url": product.image_url,
}
for product in products
]
Expand Down Expand Up @@ -67,6 +68,7 @@ def get_product(product_id):
"description": product.description,
"price": product.price,
"expiry_date": product.expiry_date.isoformat(),
"image_url": product.image_url,
}
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Add image_url to products
Revision ID: 3a9b96cc0b45
Revises: 7b4e1cc7679a
Create Date: 2025-01-06 18:31:09.663955
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '3a9b96cc0b45'
down_revision = '7b4e1cc7679a'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('products', schema=None) as batch_op:
batch_op.add_column(sa.Column('image_url', sa.String(length=255), nullable=True))

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('products', schema=None) as batch_op:
batch_op.drop_column('image_url')

# ### end Alembic commands ###

0 comments on commit ccca78e

Please sign in to comment.