feat: Updated endpoint endpoints/fruits.get.py via AI
This commit is contained in:
parent
4c16acea7d
commit
4150ad4513
19
alembic/versions/20250412_115942_4b8b5452_update_fruit.py
Normal file
19
alembic/versions/20250412_115942_4b8b5452_update_fruit.py
Normal file
@ -0,0 +1,19 @@
|
||||
"""add color field to fruits table
|
||||
Revision ID: a8b5c2d1e9f4
|
||||
Revises: f9d4e2c7b3a1
|
||||
Create Date: 2024-01-22 10:00:00.000000
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'a8b5c2d1e9f4'
|
||||
down_revision = 'f9d4e2c7b3a1'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
def upgrade():
|
||||
op.add_column('fruits', sa.Column('color', sa.String(50), nullable=True))
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('fruits', 'color')
|
@ -1,4 +1,4 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List
|
||||
from core.database import get_db
|
||||
@ -7,9 +7,8 @@ from helpers.fruit_helpers import get_all_fruits
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/fruits", response_model=List[FruitSchema], status_code=200)
|
||||
async def get_fruits_with_color(db: Session = Depends(get_db)):
|
||||
@router.get("/fruits", response_model=List[FruitSchema])
|
||||
async def get_fruits(db: Session = Depends(get_db)):
|
||||
fruits = get_all_fruits(db)
|
||||
if not fruits:
|
||||
raise HTTPException(status_code=404, detail="No fruits found")
|
||||
# The color property should already be part of the Fruit model and FruitSchema
|
||||
return fruits
|
Loading…
x
Reference in New Issue
Block a user