Skip to content

Commit

Permalink
Rename Player to User to match repo terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyui committed Feb 17, 2024
1 parent 6ca6951 commit 336db49
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/api/domains/cho.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ def parse_adapters_string(adapters_string: str) -> tuple[list[str], bool]:
async def authenticate(
username: str,
untrusted_password: bytes,
) -> users_repo.Player | None:
) -> users_repo.User | None:
user_info = await users_repo.fetch_one(
name=username,
fetch_all_fields=True,
Expand Down
2 changes: 1 addition & 1 deletion app/api/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ async def api_get_pool(
)

pool_creator_clan = await clans_repo.fetch_one(id=pool_creator.clan_id)
pool_creator_clan_members: list[users_repo.Player] = []
pool_creator_clan_members: list[users_repo.User] = []
if pool_creator_clan is not None:
pool_creator_clan_members = await users_repo.fetch_many(
clan_id=pool_creator.clan_id,
Expand Down
38 changes: 19 additions & 19 deletions app/repositories/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
)


class Player(TypedDict):
class User(TypedDict):
id: int
name: str
safe_name: str
Expand Down Expand Up @@ -89,8 +89,8 @@ async def create(
email: str,
pw_bcrypt: bytes,
country: str,
) -> Player:
"""Create a new player in the database."""
) -> User:
"""Create a new user in the database."""
query = f"""\
INSERT INTO users (name, safe_name, email, pw_bcrypt, country, creation_time, latest_activity)
VALUES (:name, :safe_name, :email, :pw_bcrypt, :country, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())
Expand All @@ -112,19 +112,19 @@ async def create(
params = {
"id": rec_id,
}
player = await app.state.services.database.fetch_one(query, params)
user = await app.state.services.database.fetch_one(query, params)

assert player is not None
return cast(Player, dict(player._mapping))
assert user is not None
return cast(User, dict(user._mapping))


async def fetch_one(
id: int | None = None,
name: str | None = None,
email: str | None = None,
fetch_all_fields: bool = False, # TODO: probably remove this if possible
) -> Player | None:
"""Fetch a single player from the database."""
) -> User | None:
"""Fetch a single user from the database."""
if id is None and name is None and email is None:
raise ValueError("Must provide at least one parameter.")

Expand All @@ -140,8 +140,8 @@ async def fetch_one(
"safe_name": make_safe_name(name) if name is not None else None,
"email": email,
}
player = await app.state.services.database.fetch_one(query, params)
return cast(Player, dict(player._mapping)) if player is not None else None
user = await app.state.services.database.fetch_one(query, params)
return cast(User, dict(user._mapping)) if user is not None else None


async def fetch_count(
Expand All @@ -152,7 +152,7 @@ async def fetch_count(
preferred_mode: int | None = None,
play_style: int | None = None,
) -> int:
"""Fetch the number of players in the database."""
"""Fetch the number of users in the database."""
query = """\
SELECT COUNT(*) AS count
FROM users
Expand Down Expand Up @@ -185,8 +185,8 @@ async def fetch_many(
play_style: int | None = None,
page: int | None = None,
page_size: int | None = None,
) -> list[Player]:
"""Fetch multiple players from the database."""
) -> list[User]:
"""Fetch multiple users from the database."""
query = f"""\
SELECT {READ_PARAMS}
FROM users
Expand Down Expand Up @@ -214,8 +214,8 @@ async def fetch_many(
params["limit"] = page_size
params["offset"] = (page - 1) * page_size

players = await app.state.services.database.fetch_all(query, params)
return cast(list[Player], [dict(p._mapping) for p in players])
users = await app.state.services.database.fetch_all(query, params)
return cast(list[User], [dict(p._mapping) for p in users])


async def update(
Expand All @@ -236,8 +236,8 @@ async def update(
custom_badge_icon: str | None | _UnsetSentinel = UNSET,
userpage_content: str | None | _UnsetSentinel = UNSET,
api_key: str | None | _UnsetSentinel = UNSET,
) -> Player | None:
"""Update a player in the database."""
) -> User | None:
"""Update a user in the database."""
update_fields: PlayerUpdateFields = {}
if not isinstance(name, _UnsetSentinel):
update_fields["name"] = name
Expand Down Expand Up @@ -291,8 +291,8 @@ async def update(
params = {
"id": id,
}
player = await app.state.services.database.fetch_one(query, params)
return cast(Player, dict(player._mapping)) if player is not None else None
user = await app.state.services.database.fetch_one(query, params)
return cast(User, dict(user._mapping)) if user is not None else None


# TODO: delete?
4 changes: 2 additions & 2 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from app.logging import log

if TYPE_CHECKING:
from app.repositories.users import Player
from app.repositories.users import User

T = TypeVar("T")

Expand All @@ -35,7 +35,7 @@ def make_safe_name(name: str) -> str:
return name.lower().replace(" ", "_")


def determine_highest_ranking_clan_member(members: list[Player]) -> Player:
def determine_highest_ranking_clan_member(members: list[User]) -> User:
return next(iter(sorted(members, key=lambda m: m["clan_priv"], reverse=True)))


Expand Down

0 comments on commit 336db49

Please sign in to comment.