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 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()
|
||||||
|
|
||||||
@router.post("/signup", status_code=status.HTTP_201_CREATED, response_model=UserResponse)
|
@router.post("/signup", response_model=UserResponse, status_code=status.HTTP_201_CREATED)
|
||||||
async def signup(
|
async def signup_user(
|
||||||
user_data: UserCreate,
|
user_data: UserCreate,
|
||||||
db: Session = Depends(get_db)
|
db: Session = Depends(get_db)
|
||||||
):
|
):
|
||||||
"""Create a new user account"""
|
existing_user = get_user_by_email(db, user_data.email)
|
||||||
user = create_user(db=db, user_data=user_data)
|
if existing_user:
|
||||||
if not user:
|
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
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