Add GET endpoint for /lions

This commit is contained in:
Backend IM Bot 2025-03-25 12:30:49 -05:00
parent 6d8da3fae5
commit bfce3ad07e

20
endpoints/lions.get.py Normal file
View File

@ -0,0 +1,20 @@
# 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.