Define routes using APIRouter

This commit is contained in:
coolneng 2020-09-03 18:31:52 +02:00
parent abd0f45c91
commit de1d79ff9f
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
2 changed files with 8 additions and 7 deletions

View File

@ -1,5 +1,5 @@
from fastapi import FastAPI
from app.routes import router
app = FastAPI()
from app import routes, schemas
app.include_router(router)

View File

@ -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"}