Simplify error handling in routes
This commit is contained in:
		
							parent
							
								
									6787237c7e
								
							
						
					
					
						commit
						cfb1321e1e
					
				@ -2,4 +2,4 @@ from fastapi import FastAPI
 | 
			
		||||
 | 
			
		||||
app = FastAPI()
 | 
			
		||||
 | 
			
		||||
from app import routes, schema
 | 
			
		||||
from app import routes, schemas
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
from fastapi import Response, status
 | 
			
		||||
from fastapi import HTTPException, Response, status
 | 
			
		||||
 | 
			
		||||
from app import app
 | 
			
		||||
from app.schemas import *
 | 
			
		||||
@ -6,7 +6,7 @@ from app.twilio import send_otp
 | 
			
		||||
from database.crud import insert_data, verify_otp
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.post("/register", status_code=status.HTTP_200_OK)
 | 
			
		||||
@app.post("/register")
 | 
			
		||||
async def create_user(request: RegisterSchema):
 | 
			
		||||
    insert_data(schema="Users", data=request)
 | 
			
		||||
    send_otp(receiver=request.mobile)
 | 
			
		||||
@ -14,16 +14,15 @@ async def create_user(request: RegisterSchema):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# FIXME Use OAuth2 for verification
 | 
			
		||||
@app.post("/login", status_code=status.HTTP_200_OK)
 | 
			
		||||
@app.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", status_code=status.HTTP_200_OK)
 | 
			
		||||
@app.post("/otpVerification")
 | 
			
		||||
async def validate_otp(request: OTPSchema, response: Response):
 | 
			
		||||
    if verify_otp(data=request):
 | 
			
		||||
        return {"message": "The OTP has been verified successfully"}
 | 
			
		||||
    response.status_code = status.HTTP_400_BAD_REQUEST
 | 
			
		||||
    return {"message": "The OTP is not correct"}
 | 
			
		||||
    raise HTTPException(status_code=400, detail="The OTP is not correct")
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,7 @@ from datetime import datetime
 | 
			
		||||
from database import SessionLocal
 | 
			
		||||
from database.models import *
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
db = SessionLocal()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user