Update code in endpoints/signup.post.py
This commit is contained in:
parent
5f18e055b5
commit
9b3ab7eb54
@ -1,50 +1,32 @@
|
||||
from fastapi import APIRouter, HTTPException, Depends
|
||||
from sqlalchemy.orm import Session
|
||||
from pydantic import BaseModel
|
||||
from core.database import get_db
|
||||
from core.auth import get_password_hash, create_access_token
|
||||
from fastapi import APIRouter, HTTPException
|
||||
import uuid
|
||||
from models.user import User
|
||||
|
||||
meals = [] # In-memory storage
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class UserCreate(BaseModel):
|
||||
username: str
|
||||
email: str
|
||||
password: str
|
||||
|
||||
@router.post("/signup")
|
||||
async def signup(
|
||||
user_data: UserCreate,
|
||||
db: Session = Depends(get_db)
|
||||
async def meal_recommendations(
|
||||
preferences: str = "vegetarian",
|
||||
dietary_restrictions: str = "none",
|
||||
meal_type: str = "dinner"
|
||||
):
|
||||
"""User registration endpoint"""
|
||||
# Check existing user
|
||||
db_user = db.query(User).filter(
|
||||
(User.username == user_data.username) |
|
||||
(User.email == user_data.email)
|
||||
).first()
|
||||
"""Demo meal recommendation endpoint"""
|
||||
recommendation_id = str(uuid.uuid4())
|
||||
meals.append({
|
||||
"id": recommendation_id,
|
||||
"preferences": preferences,
|
||||
"restrictions": dietary_restrictions,
|
||||
"type": meal_type,
|
||||
"disabled": False
|
||||
})
|
||||
|
||||
if db_user:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Username or email already exists"
|
||||
)
|
||||
|
||||
# Create new user
|
||||
new_user = User(
|
||||
id=str(uuid.uuid4()),
|
||||
username=user_data.username,
|
||||
email=user_data.email,
|
||||
hashed_password=get_password_hash(user_data.password)
|
||||
)
|
||||
|
||||
db.add(new_user)
|
||||
db.commit()
|
||||
|
||||
# Return token directly after registration
|
||||
return {
|
||||
"message": "User created successfully",
|
||||
"access_token": create_access_token({"sub": new_user.id}),
|
||||
"token_type": "bearer"
|
||||
"message": "Meal recommendations generated",
|
||||
"recommendation_id": recommendation_id,
|
||||
"preferences": preferences,
|
||||
"next_steps": [
|
||||
"Review recommendations (demo)",
|
||||
"Save favorite meals"
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user