Update code in endpoints/signup.post.py
This commit is contained in:
parent
46c0b20c33
commit
aa5c843a57
@ -3,7 +3,7 @@ from sqlalchemy.orm import Session
|
|||||||
from core.database import get_db
|
from core.database import get_db
|
||||||
from models.user import User
|
from models.user import User
|
||||||
from schemas.user import UserCreate, UserResponse
|
from schemas.user import UserCreate, UserResponse
|
||||||
from helpers.user_helpers import create_user
|
from helpers.user_helpers import create_user, get_user_by_email
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@ -12,5 +12,12 @@ async def signup(
|
|||||||
user_data: UserCreate,
|
user_data: UserCreate,
|
||||||
db: Session = Depends(get_db)
|
db: Session = Depends(get_db)
|
||||||
):
|
):
|
||||||
|
existing_user = get_user_by_email(db, user_data.email)
|
||||||
|
if existing_user:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
detail="Email already registered"
|
||||||
|
)
|
||||||
|
|
||||||
new_user = create_user(db, user_data)
|
new_user = create_user(db, user_data)
|
||||||
return new_user
|
return new_user
|
Loading…
x
Reference in New Issue
Block a user