feat: Updated endpoint endpoints/fruits.get.py via AI
This commit is contained in:
parent
46ff51a4f9
commit
af1c3bb37a
19
alembic/versions/20250412_020818_237fe07a_update_fruit.py
Normal file
19
alembic/versions/20250412_020818_237fe07a_update_fruit.py
Normal file
@ -0,0 +1,19 @@
|
||||
"""remove country field from fruit model
|
||||
Revision ID: a1b2c3d4e5f6
|
||||
Revises: f7d3e8a9c2b6
|
||||
Create Date: 2024-01-23 10:20:30.123456
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '237fe07a'
|
||||
down_revision = 'f7d3e8a9c2b6'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
def upgrade():
|
||||
op.drop_column('fruits', 'country')
|
||||
|
||||
def downgrade():
|
||||
op.add_column('fruits', sa.Column('country', sa.String(), nullable=True))
|
@ -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 optional country
|
||||
fruit_data (FruitCreate): The data for the fruit to create
|
||||
|
||||
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 optional country
|
||||
fruit_data (FruitUpdate): The update data for the fruit
|
||||
|
||||
Returns:
|
||||
Optional[Fruit]: The updated fruit object if found, otherwise None
|
||||
|
@ -10,7 +10,6 @@ class Fruit(Base):
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column(String, unique=True, nullable=False, index=True)
|
||||
description = Column(String, nullable=True)
|
||||
country = Column(String, nullable=True)
|
||||
is_active = Column(Boolean, default=True)
|
||||
created_at = Column(DateTime, default=func.now())
|
||||
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
|
@ -9,7 +9,6 @@ class FruitName(BaseModel):
|
||||
class FruitBase(BaseModel):
|
||||
name: str = Field(..., min_length=1, description="Fruit name")
|
||||
description: Optional[str] = Field(None, description="Fruit description")
|
||||
country: Optional[str] = Field(None, description="Country of origin")
|
||||
is_active: bool = Field(True, description="Whether the fruit is active")
|
||||
|
||||
class FruitCreate(FruitBase):
|
||||
@ -18,7 +17,6 @@ class FruitCreate(FruitBase):
|
||||
class FruitUpdate(BaseModel):
|
||||
name: Optional[str] = Field(None, min_length=1, description="Fruit name")
|
||||
description: Optional[str] = Field(None, description="Fruit description")
|
||||
country: Optional[str] = Field(None, description="Country of origin")
|
||||
is_active: Optional[bool] = Field(None, description="Whether the fruit is active")
|
||||
|
||||
class FruitSchema(FruitBase):
|
||||
@ -33,7 +31,6 @@ class FruitSchema(FruitBase):
|
||||
"id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
|
||||
"name": "Apple",
|
||||
"description": "A sweet, edible fruit produced by an apple tree",
|
||||
"country": "United States",
|
||||
"is_active": True,
|
||||
"created_at": "2023-01-01T12:00:00",
|
||||
"updated_at": "2023-01-01T12:00:00"
|
||||
|
Loading…
x
Reference in New Issue
Block a user