Add GET endpoint for /lions
This commit is contained in:
parent
6d8da3fae5
commit
bfce3ad07e
20
endpoints/lions.get.py
Normal file
20
endpoints/lions.get.py
Normal 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.
|
Loading…
x
Reference in New Issue
Block a user