feat: Update endpoint signup
This commit is contained in:
parent
1dbe371015
commit
8a5f5aadf8
@ -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
|
||||
|
||||
new_user = create_user(db, user_data)
|
||||
return new_user
|
||||
return user
|
Loading…
x
Reference in New Issue
Block a user