Skip to content

Commit 7b4044b

Browse files
authored
Merge pull request #228 from ibhuiyan17/v1-to-FastAPI
V1 to fast api
2 parents b12ba72 + 6638e6e commit 7b4044b

File tree

18 files changed

+75
-93
lines changed

18 files changed

+75
-93
lines changed

app/main.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
import uvicorn
1111
from fastapi import FastAPI, Request, Response
1212
from fastapi.middleware.cors import CORSMiddleware
13-
from fastapi.middleware.wsgi import WSGIMiddleware
1413
from fastapi.responses import JSONResponse
1514

1615
from .core import create_app
1716
from .data import data_source
1817
from .models.latest import LatestResponse as Latest
1918
from .models.location import LocationResponse as Location
2019
from .models.location import LocationsResponse as Locations
21-
from .router import router
20+
from .router.v1 import router as v1router
21+
from .router.v2 import router as v2router
2222

2323
# ############
2424
# FastAPI App
@@ -83,11 +83,9 @@ async def handle_validation_error(request: Request, exc: pydantic.error_wrappers
8383

8484

8585
# Include routers.
86-
APP.include_router(router, prefix="/v2", tags=["v2"])
86+
APP.include_router(v1router, prefix="", tags=["v1"])
87+
APP.include_router(v2router, prefix="/v2", tags=["v2"])
8788

88-
# mount the existing Flask app
89-
# v1 @ /
90-
APP.mount("/", WSGIMiddleware(create_app()))
9189

9290
# Running of app.
9391
if __name__ == "__main__":

app/router/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from fastapi import APIRouter
22

3-
# Create the router.
4-
router = APIRouter()
3+
from .v1 import all, confirmed, deaths, recovered
54

65
# The routes.
7-
from . import latest, sources, locations # isort:skip
6+
from .v2 import latest, sources, locations # isort:skip

app/router/v1/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from fastapi import APIRouter
2+
3+
router = APIRouter()

app/router/v1/all.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from ...services.location.jhu import get_category
2+
from . import router
3+
4+
5+
@router.get("/all")
6+
def all():
7+
# Get all the categories.
8+
confirmed = get_category("confirmed")
9+
deaths = get_category("deaths")
10+
recovered = get_category("recovered")
11+
12+
return {
13+
# Data.
14+
"confirmed": confirmed,
15+
"deaths": deaths,
16+
"recovered": recovered,
17+
# Latest.
18+
"latest": {"confirmed": confirmed["latest"], "deaths": deaths["latest"], "recovered": recovered["latest"],},
19+
}

app/router/v1/confirmed.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ...services.location.jhu import get_category
2+
from . import router
3+
4+
5+
@router.get("/confirmed")
6+
def confirmed():
7+
confirmed = get_category("confirmed")
8+
9+
return confirmed

app/router/v1/deaths.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ...services.location.jhu import get_category
2+
from . import router
3+
4+
5+
@router.get("/deaths")
6+
def deaths():
7+
deaths = get_category("deaths")
8+
9+
return deaths

app/router/v1/recovered.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ...services.location.jhu import get_category
2+
from . import router
3+
4+
5+
@router.get("/recovered")
6+
def recovered():
7+
recovered = get_category("recovered")
8+
9+
return recovered

app/router/v2/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from fastapi import APIRouter
2+
3+
router = APIRouter()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from fastapi import Request
22

3-
from ..enums.sources import Sources
4-
from ..models.latest import LatestResponse as Latest
3+
from ...enums.sources import Sources
4+
from ...models.latest import LatestResponse as Latest
55
from . import router
66

77

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from fastapi import HTTPException, Request
22

3-
from ..enums.sources import Sources
4-
from ..models.location import LocationResponse as Location
5-
from ..models.location import LocationsResponse as Locations
3+
from ...enums.sources import Sources
4+
from ...models.location import LocationResponse as Location
5+
from ...models.location import LocationsResponse as Locations
66
from . import router
77

88

0 commit comments

Comments
 (0)