Add GET endpoint for services_2
This commit is contained in:
parent
9da1b7967f
commit
77d98be227
27
endpoints/services_2.get.py
Normal file
27
endpoints/services_2.get.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Entity: User
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
from core.database import get_db
|
||||||
|
from models.user import User
|
||||||
|
from schemas.user import UserSchema, UserCreate
|
||||||
|
from helpers.user_helpers import get_user_by_email, create_user
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.post("/api/users", status_code=201, response_model=UserSchema)
|
||||||
|
async def register_user(
|
||||||
|
user_data: UserCreate,
|
||||||
|
db: Session = Depends(get_db)
|
||||||
|
):
|
||||||
|
# Check if user already exists
|
||||||
|
existing_user = get_user_by_email(db, user_data.email)
|
||||||
|
if existing_user:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
detail="User with this email already exists"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create new user
|
||||||
|
new_user = create_user(db, user_data)
|
||||||
|
return new_user
|
Loading…
x
Reference in New Issue
Block a user