diff --git a/endpoints/deployment.get.py b/endpoints/deployment.get.py index e69de29..cfe4097 100644 --- a/endpoints/deployment.get.py +++ b/endpoints/deployment.get.py @@ -0,0 +1,24 @@ +# Entity: Country + +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.country import Country +from schemas.country import CountrySchema + +router = APIRouter() + +@router.get("/deployment", status_code=200, response_model=CountrySchema) +async def get_random_country( + db: Session = Depends(get_db) +): + countries = db.query(Country).all() + if not countries: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, + detail="No countries found in database" + ) + random_country = random.choice(countries) + return random_country \ No newline at end of file