Add POST endpoint for /rivers
This commit is contained in:
parent
5a061be4e5
commit
0fb10b86a8
26
endpoints/rivers.post.py
Normal file
26
endpoints/rivers.post.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Entity: Lake
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
from app.api.db.database import get_db
|
||||||
|
# You'll need to add correct model and schema imports
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.post("/rivers", response_model=List[LakeSchema])
|
||||||
|
async def get_lakes_in_paris(
|
||||||
|
city: str = "Paris",
|
||||||
|
db: Session = Depends(get_db)
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Get a list of lakes in the specified city.
|
||||||
|
|
||||||
|
By default, it returns lakes in Paris.
|
||||||
|
"""
|
||||||
|
lakes = db.query(Lake).filter(Lake.city == city).all()
|
||||||
|
|
||||||
|
if not lakes:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,
|
||||||
|
detail=f"No lakes found in {city}")
|
||||||
|
|
||||||
|
return lakes
|
Loading…
x
Reference in New Issue
Block a user