From 8a5f5aadf8f57d20c650c33058855c5318f25659 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Sat, 29 Mar 2025 12:27:50 +0000 Subject: [PATCH] feat: Update endpoint signup --- endpoints/signup.post.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/endpoints/signup.post.py b/endpoints/signup.post.py index 39eb0cc..81fde64 100644 --- a/endpoints/signup.post.py +++ b/endpoints/signup.post.py @@ -3,20 +3,22 @@ from sqlalchemy.orm import Session from core.database import get_db from models.user import User 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.post("/signup", status_code=status.HTTP_201_CREATED, response_model=UserResponse) -async def signup( +@router.post("/signup", response_model=UserResponse, status_code=status.HTTP_201_CREATED) +async def signup_user( user_data: UserCreate, db: Session = Depends(get_db) ): - """Create a new user account""" - user = create_user(db=db, user_data=user_data) - if not user: + existing_user = get_user_by_email(db, user_data.email) + if existing_user: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail="Unable to create user" + detail="Email already registered" ) - return user \ No newline at end of file + + new_user = create_user(db, user_data) + return new_user + return user \ No newline at end of file