feat(order): Add finalize order functionality
This commit is contained in:
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user