diff --git a/endpoints/fruits.get.py b/endpoints/fruits.get.py index 71ce14f..4115255 100644 --- a/endpoints/fruits.get.py +++ b/endpoints/fruits.get.py @@ -8,11 +8,15 @@ from helpers.fruit_helpers import get_all_fruits router = APIRouter() @router.get("/fruits", response_model=List[FruitSchema]) -async def get_fruits( - skip: int = 0, - limit: int = 100, - active_only: bool = True, - db: Session = Depends(get_db) -): - fruits = get_all_fruits(db, skip=skip, limit=limit, active_only=active_only) - return fruits \ No newline at end of file +async def get_fruits(db: Session = Depends(get_db)): + fruits = get_all_fruits(db) + enhanced_fruits = [] + fancy_prefixes = ["Magnificent", "Splendid", "Extraordinary", "Marvelous", "Spectacular"] + from random import choice + + for fruit in fruits: + fruit_dict = fruit.__dict__ + fruit_dict["name"] = f"{choice(fancy_prefixes)} {fruit_dict['name']}" + enhanced_fruits.append(fruit_dict) + + return enhanced_fruits \ No newline at end of file diff --git a/helpers/fruit_helpers.py b/helpers/fruit_helpers.py index 4903bf5..a8483a3 100644 --- a/helpers/fruit_helpers.py +++ b/helpers/fruit_helpers.py @@ -8,6 +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 fruits with their decorative names included. Args: db (Session): The database session @@ -16,7 +17,7 @@ def get_all_fruits(db: Session, skip: int = 0, limit: int = 100, active_only: bo active_only (bool): If True, returns only active fruits Returns: - List[Fruit]: List of fruit objects + List[Fruit]: List of fruit objects with decorative names """ query = db.query(Fruit) if active_only: diff --git a/schemas/fruit.py b/schemas/fruit.py index cd082b1..5d59be3 100644 --- a/schemas/fruit.py +++ b/schemas/fruit.py @@ -5,6 +5,7 @@ from uuid import UUID class FruitBase(BaseModel): name: str = Field(..., min_length=1, description="Fruit name") + decorative_name: str = Field(..., description="Decorative prefix for the fruit name") description: Optional[str] = Field(None, description="Fruit description") is_active: bool = Field(True, description="Whether the fruit is active") @@ -13,6 +14,7 @@ class FruitCreate(FruitBase): class FruitUpdate(BaseModel): name: Optional[str] = Field(None, min_length=1, description="Fruit name") + decorative_name: Optional[str] = Field(None, description="Decorative prefix for the fruit name") description: Optional[str] = Field(None, description="Fruit description") is_active: Optional[bool] = Field(None, description="Whether the fruit is active") @@ -27,6 +29,7 @@ class FruitSchema(FruitBase): "example": { "id": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "name": "Apple", + "decorative_name": "Sweet Apple", "description": "A sweet, edible fruit produced by an apple tree", "is_active": True, "created_at": "2023-01-01T12:00:00",