feat(order): Add finalize order functionality

This commit is contained in:
2025-12-13 11:53:41 +01:00
parent 00246819cc
commit fd544fcebc
9 changed files with 161 additions and 35 deletions

View File

@@ -15,6 +15,18 @@ def create_tables():
def ensure_user(user_info: dict, session: Session) -> User:
"""
Retrieve an existing user or create a new one if it doesn't exist.
This function queries the database for a user with the given username.
If found, it returns the existing user. If not found, it creates a new user
with the provided information, adds it to the session, and returns it.
:param user_info: Dictionary containing user information with keys:
- "username" (str): The unique username to search for or create
- "display_name" (str, optional): The display name for the new user
:param session: SQLAlchemy session for database operations
:return: The existing or newly created user object
"""
statement = select(User).where(User.username == user_info["username"])
if user := session.scalars(statement).one_or_none():