Add GET endpoint for /deployment
This commit is contained in:
parent
9f3022815b
commit
c531963fce
@ -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
|
Loading…
x
Reference in New Issue
Block a user