Skip to content

Commit

Permalink
fix: apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
7mochi committed Sep 13, 2023
1 parent 946b3ff commit f446450
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/api/domains/cho.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ async def login(
""" login credentials verified """

await logins_repo.create(
userid=user_info["id"],
user_id=user_info["id"],
ip=str(ip),
osu_ver=osu_version.date,
osu_stream=osu_version.stream,
Expand Down
34 changes: 16 additions & 18 deletions app/repositories/ingame_logins.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@
)


async def create(userid: int, ip: str, osu_ver: str, osu_stream: str) -> dict[str, Any]:
async def create(
user_id: int,
ip: str,
osu_ver: str,
osu_stream: str,
) -> dict[str, Any]:
"""Create a new login entry in the database."""
query = f"""\
INSERT INTO ingame_logins (userid, ip, osu_ver, osu_stream, datetime)
VALUES (:userid, :ip, :osu_ver, :osu_stream, NOW())
"""
params = {
"userid": userid,
"userid": user_id,
"ip": ip,
"osu_ver": osu_ver,
"osu_stream": osu_stream,
Expand All @@ -53,15 +58,15 @@ async def create(userid: int, ip: str, osu_ver: str, osu_stream: str) -> dict[st

async def fetch_one(
id: Optional[int] = None,
userid: Optional[int] = None,
user_id: Optional[int] = None,
ip: Optional[str] = None,
osu_ver: Optional[str] = None,
osu_stream: Optional[str] = None,
) -> Optional[dict[str, Any]]:
"""Fetch a login entry from the database."""
if (
id is None
and userid is None
and user_id is None
and ip is None
and osu_ver is None
and osu_stream is None
Expand All @@ -79,7 +84,7 @@ async def fetch_one(
"""
params = {
"id": id,
"userid": userid,
"userid": user_id,
"ip": ip,
"osu_ver": osu_ver,
"osu_stream": osu_stream,
Expand All @@ -89,34 +94,27 @@ async def fetch_one(


async def fetch_count(
userid: Optional[int] = None,
user_id: Optional[int] = None,
ip: Optional[str] = None,
osu_ver: Optional[str] = None,
osu_stream: Optional[str] = None,
) -> int:
"""Fetch the number of logins in the database."""
query = """\
SELECT COUNT(*) AS count
FROM ingame_logins
WHERE userid = COALESCE(:userid, userid)
AND ip = COALESCE(:ip, ip)
AND osu_ver = COALESCE(:osu_ver, osu_ver)
AND osu_stream = COALESCE(:osu_stream, osu_stream)
"""
params = {
"userid": userid,
"userid": user_id,
"ip": ip,
"osu_ver": osu_ver,
"osu_stream": osu_stream,
}
rec = await app.state.services.database.fetch_one(query, params)
assert rec is not None
return rec["count"]


async def fetch_many(
userid: Optional[int] = None,
user_id: Optional[int] = None,
ip: Optional[str] = None,
osu_ver: Optional[str] = None,
osu_stream: Optional[str] = None,
Expand All @@ -133,7 +131,7 @@ async def fetch_many(
AND osu_stream = COALESCE(:osu_stream, osu_stream)
"""
params = {
"userid": userid,
"userid": user_id,
"ip": ip,
"osu_ver": osu_ver,
"osu_stream": osu_stream,
Expand All @@ -153,7 +151,7 @@ async def fetch_many(

async def update(
id: int,
userid: Optional[int] = None,
user_id: Optional[int] = None,
ip: Optional[str] = None,
osu_ver: Optional[str] = None,
osu_stream: Optional[str] = None,
Expand All @@ -169,7 +167,7 @@ async def update(
"""
params = {
"id": id,
"userid": userid,
"userid": user_id,
"ip": ip,
"osu_ver": osu_ver,
"osu_stream": osu_stream,
Expand Down

0 comments on commit f446450

Please sign in to comment.