From 25f265fa10b075d5b9083f4ec7a9448e9d31eeca Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Wed, 26 Mar 2025 13:01:22 +0000 Subject: [PATCH] Add GET endpoint for /countries --- endpoints/countries.get.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/endpoints/countries.get.py b/endpoints/countries.get.py index eb4fd13..1f8d5e5 100644 --- a/endpoints/countries.get.py +++ b/endpoints/countries.get.py @@ -1,18 +1,21 @@ # Entity: Country -from fastapi import APIRouter, Depends, HTTPException, status -from sqlalchemy.orm import Session +from fastapi import APIRouter, HTTPException, status from typing import List -from core.database import get_db +import httpx from core.models.country import Country from core.schemas.country import CountrySchema router = APIRouter() -@router.get("/countries", status_code=200, response_model=List[CountrySchema]) -async def get_countries( - db: Session = Depends(get_db) -): - """Get all countries""" - countries = db.query(Country).all() - return countries \ No newline at end of file +@router.get("/countries", response_model=List[CountrySchema], status_code=status.HTTP_200_OK) +async def get_countries(): + """Get list of countries from external API""" + async with httpx.AsyncClient() as client: + response = await client.get("https://restcountries.com/v3.1/all") + if response.status_code != 200: + raise HTTPException( + status_code=status.HTTP_503_SERVICE_UNAVAILABLE, + detail="External API service unavailable" + ) + return response.json() \ No newline at end of file