Skip to content

Commit 17cfa55

Browse files
committed
fix: changes in versioning for API's and in structure.
1 parent efb13e4 commit 17cfa55

8 files changed

Lines changed: 56 additions & 254 deletions

File tree

apps/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1+
from config import cors
12
from fastapi import FastAPI
23
from fastapi_versioning import VersionedFastAPI
3-
4-
from apps.api.auth.v1.view import router
5-
from apps.api.auth.v2.view import authrouter
6-
from config import cors
4+
from apps.api.auth.view import defaultrouter
75

86
# Create app object and add routes
97
app = FastAPI(title="Python FastAPI boilerplate", middleware=cors.middleware)
108

119
# define router for different version
12-
app.include_router(router, prefix="/v1", tags=["v1"]) # router for version 1
13-
app.include_router(authrouter, prefix="/v2", tags=["v2"]) # router for version 2
10+
app.include_router(defaultrouter) # router for version 1
1411

15-
# # # Define version to specify version related API's.
12+
# Define version to specify version related API's.
1613
app = VersionedFastAPI(app, version_format="{major}", prefix_format="/v{major}", enable_latest=True)

apps/api/auth/v1/view.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +0,0 @@
1-
import time
2-
from fastapi import status
3-
from fastapi_utils.cbv import cbv
4-
from fastapi_utils.inferring_router import InferringRouter
5-
from fastapi_versioning import version
6-
from apps.constant import constant
7-
from apps.utils.standard_response import StandardResponse
8-
9-
## Load API's
10-
router = InferringRouter()
11-
12-
## Define API's here
13-
@cbv(router)
14-
class UserCrudApi():
15-
"""This class is for user's CRUD operation with version 1 API's"""
16-
17-
@router.get('/list/user')
18-
@version(1)
19-
async def list_user(self):
20-
"""This API is for list user.
21-
"""
22-
try:
23-
data = "Hello there, welcome to fastapi bolierplate"
24-
return data
25-
except Exception as e:
26-
return StandardResponse(False, status.HTTP_400_BAD_REQUEST, None, constant.ERROR_MSG)

apps/api/auth/v2/view.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +0,0 @@
1-
from fastapi_utils.inferring_router import InferringRouter
2-
from fastapi_versioning import version
3-
from fastapi_utils.cbv import cbv
4-
from apps.utils.standard_response import StandardResponse
5-
from fastapi import status
6-
from apps.constant import constant
7-
8-
authrouter = InferringRouter()
9-
10-
11-
@cbv(authrouter)
12-
class APIView():
13-
@authrouter.get("/list")
14-
@version(2)
15-
def get_list(self):
16-
try:
17-
response = { "data": "User's list data" }
18-
return StandardResponse(True, status.HTTP_200_OK, response, constant.STATUS_SUCCESS)
19-
except Exception as e:
20-
return StandardResponse(False, status.HTTP_400_BAD_REQUEST, None, constant.ERROR_MSG)

apps/api/auth/view.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,46 @@
11
from fastapi import status
22
from fastapi_utils.cbv import cbv
3-
from fastapi_utils.inferring_router import InferringRouter
4-
3+
from fastapi import APIRouter
54
from apps.constant import constant
5+
from fastapi_versioning import version
6+
from fastapi_utils.inferring_router import InferringRouter
67
from apps.utils.standard_response import StandardResponse
78

89
## Load API's
9-
router = InferringRouter()
10+
defaultrouter = APIRouter()
1011

1112
## Define API's here
12-
@cbv(router)
13+
@cbv(defaultrouter)
1314
class UserCrudApi():
1415
"""This class is for user's CRUD operation with version 1 API's"""
1516

16-
@router.get('/list/user')
17+
@defaultrouter.get('/v1/list/user')
18+
@version(1)
1719
async def list_user(self):
1820
"""This API is for list user.
1921
"""
2022
try:
21-
response = "Hello there, welcome to fastapi bolierplate"
22-
return response
23+
data = "Hello there, welcome to fastapi bolierplate"
24+
return data
25+
except Exception as e:
26+
return StandardResponse(False, status.HTTP_400_BAD_REQUEST, None, constant.ERROR_MSG)
27+
28+
@defaultrouter.post('/v1/create/user')
29+
@version(1)
30+
async def list_user(self):
31+
"""This API is for list user.
32+
"""
33+
try:
34+
data = "Hello there, welcome to fastapi bolierplate"
35+
return data
36+
except Exception as e:
37+
return StandardResponse(False, status.HTTP_400_BAD_REQUEST, None, constant.ERROR_MSG)
38+
39+
@defaultrouter.get("/v2/list")
40+
@version(2)
41+
async def get_list(self):
42+
try:
43+
response = { "data": "User's list data" }
44+
return StandardResponse(True, status.HTTP_200_OK, response, constant.STATUS_SUCCESS)
2345
except Exception as e:
2446
return StandardResponse(False, status.HTTP_400_BAD_REQUEST, None, constant.ERROR_MSG)

config/database.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""This config file will define Database Url and configurations"""
2+
import os
3+
from config import env_config
4+
from sqlalchemy import create_engine
5+
from sqlalchemy.orm import sessionmaker
6+
from sqlalchemy.ext.declarative import declarative_base
7+
8+
9+
# ##### DATABASE CONFIGURATION ############################
10+
SQLALCHEMY_DATABASE_URL = f'mysql+pymysql://{env_config.DATABASE_USER}:{env_config.DATABASE_PASSWORD}@{env_config.DATABASE_HOST}:{env_config.DATABASE_PORT}/{env_config.DATABASE_NAME}'
11+
12+
# Create engine by sqlalchemy db url
13+
engine = create_engine(SQLALCHEMY_DATABASE_URL, pool_recycle=3600, pool_pre_ping=True)
14+
SessionLocal = sessionmaker(bind=engine, autocommit=False, autoflush=False)
15+
16+
Base = declarative_base()
17+
18+
def get_db():
19+
db = SessionLocal()
20+
try:
21+
yield db
22+
finally:
23+
db.close()

config/shoper-app-198b2b6cbc3e.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

google_wallet.py

Lines changed: 0 additions & 168 deletions
This file was deleted.

shoper-app-198b2b6cbc3e.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)