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 fastapi import APIRouter, HTTPException
|
||||||
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
|
|
||||||
import uuid
|
import uuid
|
||||||
from models.user import User
|
|
||||||
|
meals = [] # In-memory storage
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
class UserCreate(BaseModel):
|
|
||||||
username: str
|
|
||||||
email: str
|
|
||||||
password: str
|
|
||||||
|
|
||||||
@router.post("/signup")
|
@router.post("/signup")
|
||||||
async def signup(
|
async def meal_recommendations(
|
||||||
user_data: UserCreate,
|
preferences: str = "vegetarian",
|
||||||
db: Session = Depends(get_db)
|
dietary_restrictions: str = "none",
|
||||||
|
meal_type: str = "dinner"
|
||||||
):
|
):
|
||||||
"""User registration endpoint"""
|
"""Demo meal recommendation endpoint"""
|
||||||
# Check existing user
|
recommendation_id = str(uuid.uuid4())
|
||||||
db_user = db.query(User).filter(
|
meals.append({
|
||||||
(User.username == user_data.username) |
|
"id": recommendation_id,
|
||||||
(User.email == user_data.email)
|
"preferences": preferences,
|
||||||
).first()
|
"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 {
|
return {
|
||||||
"message": "User created successfully",
|
"message": "Meal recommendations generated",
|
||||||
"access_token": create_access_token({"sub": new_user.id}),
|
"recommendation_id": recommendation_id,
|
||||||
"token_type": "bearer"
|
"preferences": preferences,
|
||||||
|
"next_steps": [
|
||||||
|
"Review recommendations (demo)",
|
||||||
|
"Save favorite meals"
|
||||||
|
]
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user