Skip to content

Update user.py #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/data/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def row_to_model(row: tuple) -> User:
return User(name=name, hash=hash)

def model_to_dict(user: User) -> dict:
return user.dict()
return user.model_dump()

def get_one(name: str) -> User:
qry = "select * from user where name=:name"
Expand All @@ -35,6 +35,7 @@ def get_all() -> list[User]:

def create(user: User, table:str = "user") -> User:
"""Add <user> to user or xuser table"""
if not user: return None
if table not in ("user", "xuser"):
raise Exception(f"Invalid table name {table}")
qry = f"""insert into {table}
Expand All @@ -47,7 +48,7 @@ def create(user: User, table:str = "user") -> User:
except IntegrityError:
raise Duplicate(msg=
f"{table}: user {user.name} already exists")
return user
return get_one(user.name)

def modify(name: str, user: User) -> User:
qry = """update user set
Expand All @@ -63,8 +64,9 @@ def modify(name: str, user: User) -> User:
else:
raise Missing(msg=f"User {name} not found")

def delete(name: str) -> None:
def delete(name: str) -> User:
"""Drop user with <name> from user table, add to xuser table"""
if not name: return False
user = get_one(name)
qry = "delete from user where name = :name"
params = {"name": name}
Expand Down