diff --git a/alembic/versions/20250412_120121_c67eec9f_update_fruit.py b/alembic/versions/20250412_120121_c67eec9f_update_fruit.py new file mode 100644 index 0000000..806c09f --- /dev/null +++ b/alembic/versions/20250412_120121_c67eec9f_update_fruit.py @@ -0,0 +1,19 @@ +"""add is_ripe field to fruits table +Revision ID: b9c6d3e2f5a7 +Revises: a8b5c2d1e9f4 +Create Date: 2024-01-30 10:00:00.000000 +""" +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision = 'b9c6d3e2f5a7' +down_revision = 'a8b5c2d1e9f4' +branch_labels = None +depends_on = None + +def upgrade(): + op.add_column('fruits', sa.Column('is_ripe', sa.Boolean(), server_default='false', nullable=False)) + +def downgrade(): + op.drop_column('fruits', 'is_ripe') \ No newline at end of file diff --git a/endpoints/fruits.get.py b/endpoints/fruits.get.py index 0c55426..723a551 100644 --- a/endpoints/fruits.get.py +++ b/endpoints/fruits.get.py @@ -10,5 +10,4 @@ router = APIRouter() @router.get("/fruits", response_model=List[FruitSchema]) async def get_fruits(db: Session = Depends(get_db)): fruits = get_all_fruits(db) - # The color property should already be part of the Fruit model and FruitSchema return fruits \ No newline at end of file diff --git a/helpers/fruit_helpers.py b/helpers/fruit_helpers.py index e485ea3..7ed552a 100644 --- a/helpers/fruit_helpers.py +++ b/helpers/fruit_helpers.py @@ -8,7 +8,7 @@ from schemas.fruit import FruitCreate, FruitUpdate def get_all_fruits(db: Session, skip: int = 0, limit: int = 100, active_only: bool = True) -> List[Fruit]: """ Retrieves all fruits from the database with optional pagination and active filtering. - Returns full fruit objects including color. + Returns full fruit objects including color and ripeness status. Args: db (Session): The database session @@ -56,7 +56,7 @@ def create_fruit(db: Session, fruit_data: FruitCreate) -> Fruit: Args: db (Session): The database session - fruit_data (FruitCreate): The data for the fruit to create, including color + fruit_data (FruitCreate): The data for the fruit to create, including color and ripeness Returns: Fruit: The newly created fruit object @@ -74,7 +74,7 @@ def update_fruit(db: Session, fruit_id: UUID, fruit_data: FruitUpdate) -> Option Args: db (Session): The database session fruit_id (UUID): The ID of the fruit to update - fruit_data (FruitUpdate): The update data for the fruit, including color + fruit_data (FruitUpdate): The update data for the fruit, including color and ripeness Returns: Optional[Fruit]: The updated fruit object if found, otherwise None diff --git a/models/fruit.py b/models/fruit.py index e415844..0aea218 100644 --- a/models/fruit.py +++ b/models/fruit.py @@ -12,5 +12,6 @@ class Fruit(Base): description = Column(Text, nullable=True) color = Column(String(50), nullable=True) is_active = Column(Boolean, server_default='true', nullable=False) + is_ripe = Column(Boolean, server_default='false', nullable=False) created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False) updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) \ No newline at end of file diff --git a/schemas/fruit.py b/schemas/fruit.py index ec5d62e..9d61c93 100644 --- a/schemas/fruit.py +++ b/schemas/fruit.py @@ -11,6 +11,7 @@ class FruitBase(BaseModel): description: Optional[str] = Field(None, description="Fruit description") color: Optional[str] = Field(None, max_length=50, description="Fruit color") is_active: bool = Field(True, description="Whether the fruit is active") + is_ripe: bool = Field(False, description="Whether the fruit is ripe") class FruitCreate(FruitBase): pass @@ -20,6 +21,7 @@ class FruitUpdate(BaseModel): description: Optional[str] = Field(None, description="Fruit description") color: Optional[str] = Field(None, max_length=50, description="Fruit color") is_active: Optional[bool] = Field(None, description="Whether the fruit is active") + is_ripe: Optional[bool] = Field(None, description="Whether the fruit is ripe") class FruitSchema(FruitBase): id: UUID @@ -35,6 +37,7 @@ class FruitSchema(FruitBase): "description": "A sweet, edible fruit produced by an apple tree", "color": "Red", "is_active": True, + "is_ripe": False, "created_at": "2023-01-01T12:00:00", "updated_at": "2023-01-01T12:00:00" }