11from fastapi import status
22from fastapi_utils .cbv import cbv
3- from fastapi_utils .inferring_router import InferringRouter
4-
3+ from fastapi import APIRouter
54from apps .constant import constant
5+ from fastapi_versioning import version
6+ from fastapi_utils .inferring_router import InferringRouter
67from 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 )
1314class 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 )
0 commit comments