Skip to content

Commit

Permalink
\#6 Apply api versioning and enhance folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
YousefAldabbas committed Jul 20, 2024
1 parent 2d95b16 commit 1323452
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 31 deletions.
4 changes: 2 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from fastapi import FastAPI

from app.routers import dummy
from app.v1.routers import router as v1_router


app = FastAPI()

app.include_router(dummy.router)
app.include_router(v1_router)


@app.get("/ping")
Expand Down
3 changes: 0 additions & 3 deletions app/requests/__init__.py

This file was deleted.

5 changes: 0 additions & 5 deletions app/requests/capitalize_request.py

This file was deleted.

3 changes: 0 additions & 3 deletions app/responses/__init__.py

This file was deleted.

5 changes: 0 additions & 5 deletions app/responses/capitalize_response.py

This file was deleted.

12 changes: 0 additions & 12 deletions app/routers/dummy.py

This file was deleted.

4 changes: 4 additions & 0 deletions app/v1/routers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .base import router


__all__ = ("router",)
7 changes: 7 additions & 0 deletions app/v1/routers/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from fastapi import APIRouter

from .dummy import router as dummy_router


router = APIRouter(prefix="/v1")
router.include_router(dummy_router, prefix="/dummy", tags=["Dummy"])
11 changes: 11 additions & 0 deletions app/v1/routers/dummy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from fastapi import APIRouter

from app.v1.serializers import dummy as dummy_serializer


router = APIRouter()


@router.post("/capitalize", response_model=dummy_serializer.CapitalizeOut)
async def capitalize(request: dummy_serializer.CapitalizeIn) -> dict[str, str]:
return {"text": request.text.upper()}
11 changes: 11 additions & 0 deletions app/v1/serializers/dummy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pydantic import BaseModel


class BaseCapitalize(BaseModel):
text: str


class CapitalizeIn(BaseCapitalize): ...


class CapitalizeOut(BaseCapitalize): ...
Empty file removed tests/routers/__init__.py
Empty file.
1 change: 1 addition & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from fastapi.testclient import TestClient


def test_ping_endpoint(client: TestClient) -> None:
response = client.get("/ping")
assert response.status_code == 200
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


def test_capitalize_endpoint(client: TestClient) -> None:
response = client.post("/dummy/capitalize", json={"text": "hello"})
response = client.post("/v1/dummy/capitalize", json={"text": "hello"})
assert response.status_code == 200
assert response.json() == {"text": "HELLO"}

0 comments on commit 1323452

Please sign in to comment.