21 lines
778 B
Python
21 lines
778 B
Python
from fastapi import APIRouter, HTTPException, status
|
|
from typing import List
|
|
|
|
from schemas.country import CountryCreate, CountrySchema
|
|
from helpers.country_helpers import get_all_countries, create_country
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/countries", status_code=status.HTTP_201_CREATED, response_model=CountrySchema)
|
|
async def create_new_country(country: CountryCreate = None):
|
|
"""Create a new country"""
|
|
new_country = create_country(country)
|
|
if not new_country:
|
|
raise HTTPException(status_code=400, detail="Country could not be created")
|
|
return new_country
|
|
|
|
@router.get("/countries", status_code=200, response_model=List[CountrySchema])
|
|
async def get_countries():
|
|
"""Get all countries"""
|
|
countries = get_all_countries()
|
|
return countries |