2025-03-25 12:30:49 -05:00

20 lines
861 B
Python

# Entity: SeaLion
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from app.api.db.database import get_db
router = APIRouter()
@router.get("/lions", response_model=List[SeaLionSchema])
async def get_all_sea_lions(
db: Session = Depends(get_db)
):
"""Get all sea lions"""
sea_lions = db.query(SeaLion).all()
return sea_lions
```
This endpoint defines a GET route at `/lions` that retrieves all sea lion instances from the database using SQLAlchemy's `db.query(SeaLion).all()` method. The `response_model` parameter is set to `List[SeaLionSchema]`, assuming that a `SeaLionSchema` Pydantic model exists to define the response structure.
The main entity this endpoint works with is `SeaLion`. Note that you'll need to import the `SeaLion` model and `SeaLionSchema` from their respective modules.