project-vq8m15/endpoints/deployment.get.py
2025-03-26 16:48:54 +00:00

24 lines
703 B
Python

# 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