Add GET endpoint for /football
This commit is contained in:
parent
582b1ff8e8
commit
d516891dbc
@ -0,0 +1,27 @@
|
|||||||
|
# Entity: Pastor
|
||||||
|
|
||||||
|
```python
|
||||||
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
from typing import List
|
||||||
|
import random
|
||||||
|
from core.database import get_db
|
||||||
|
from models.pastor import Pastor
|
||||||
|
from schemas.pastor import PastorSchema
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.get("/random-pastor", status_code=200, response_model=PastorSchema)
|
||||||
|
async def get_random_pastor(
|
||||||
|
db: Session = Depends(get_db)
|
||||||
|
):
|
||||||
|
"""Get a random young Nigerian pastor"""
|
||||||
|
pastors = db.query(Pastor).filter(Pastor.age <= 40, Pastor.nationality == "Nigerian").all()
|
||||||
|
if not pastors:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
|
detail="No young Nigerian pastors found in database"
|
||||||
|
)
|
||||||
|
random_pastor = random.choice(pastors)
|
||||||
|
return random_pastor
|
||||||
|
```
|
Loading…
x
Reference in New Issue
Block a user