From de1d79ff9fc82a050cb86a9169c3ebc6a43fbf5e Mon Sep 17 00:00:00 2001 From: coolneng Date: Thu, 3 Sep 2020 18:31:52 +0200 Subject: [PATCH] Define routes using APIRouter --- app/__init__.py | 4 ++-- app/routes.py | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index a358d25..d747fcf 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,5 +1,5 @@ from fastapi import FastAPI +from app.routes import router app = FastAPI() - -from app import routes, schemas +app.include_router(router) diff --git a/app/routes.py b/app/routes.py index 79ae2e5..b78139a 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,12 +1,13 @@ -from fastapi import HTTPException, Response, status +from fastapi import APIRouter, HTTPException, Response -from app import app from app.schemas import * from app.twilio import send_otp from database.crud import insert_data, verify_otp +router = APIRouter() -@app.post("/register") + +@router.post("/register") async def create_user(request: RegisterSchema): insert_data(schema="Users", data=request) send_otp(receiver=request.mobile) @@ -14,14 +15,14 @@ async def create_user(request: RegisterSchema): # FIXME Use OAuth2 for verification -@app.post("/login") +@router.post("/login") async def log_in(request: LoginSchema, response: Response): return {"message": "Logged in successfully"} # response.status_code = status.HTTP_400_BAD_REQUEST # return {"message": "The email/password combination is not correct"} -@app.post("/otpVerification") +@router.post("/otpVerification") async def validate_otp(request: OTPSchema, response: Response): if verify_otp(data=request): return {"message": "The OTP has been verified successfully"}