diff --git a/api/advent22_api/app.py b/api/advent22_api/app.py index a38dac5..c600709 100644 --- a/api/advent22_api/app.py +++ b/api/advent22_api/app.py @@ -1,5 +1,6 @@ from fastapi import FastAPI +from .routers import router from .settings import SETTINGS app = FastAPI( @@ -17,3 +18,5 @@ app = FastAPI( docs_url=SETTINGS.docs_url, redoc_url=SETTINGS.redoc_url, ) + +app.include_router(router) diff --git a/api/advent22_api/routers/__init__.py b/api/advent22_api/routers/__init__.py new file mode 100644 index 0000000..6f03b0a --- /dev/null +++ b/api/advent22_api/routers/__init__.py @@ -0,0 +1,7 @@ +from fastapi import APIRouter + +from . import abspacken + +router = APIRouter(prefix="/api") + +router.include_router(abspacken.router) diff --git a/api/advent22_api/routers/abspacken.py b/api/advent22_api/routers/abspacken.py new file mode 100644 index 0000000..d8211fe --- /dev/null +++ b/api/advent22_api/routers/abspacken.py @@ -0,0 +1,27 @@ +import asyncio + +from fastapi import APIRouter + +router = APIRouter(prefix="/abspacken", tags=["abspacken"]) + + +async def get_kurix(kgs: float) -> float: + await asyncio.sleep(2) + + return kgs / 1.13 + + +@router.post("/uwe") +async def uwe( + kgs: float = 10, + firma: str = "Vodafone" +) -> str: + kurix = await get_kurix(kgs) + + return f"UWE hat bei {firma} einen beachtlichen Haufen von " \ + f"{kgs} Kg ({kurix:.3f} Kurix) auf den Läufer geschissen." + + +@router.get("/torsten/{ding}") +async def torsten(ding: str) -> str: + return "Der Alphakevin Torsten hat ein " f"langes {ding}."