Skip to content

Commit

Permalink
rename mode to akatsuki_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tsunyoku committed Jul 7, 2024
1 parent 7a5ae6f commit 55b6743
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions app/api/public/user_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from app.errors import ErrorCode
from app.common_types import GameMode
from app.common_types import RelaxMode
from app.common_types import Mode
from app.common_types import AkatsukiMode
from app.usecases import user_stats

router = APIRouter(tags=["(Public) User Stats API"])
Expand All @@ -30,9 +30,9 @@ async def get_user_stats(
game_mode: GameMode = Query(...),
relax_mode: RelaxMode = Query(...),
) -> Response:
mode = Mode.from_game_mode_and_relax_mode(game_mode, relax_mode)
akatsuki_mode = AkatsukiMode.from_game_mode_and_relax_mode(game_mode, relax_mode)

response = await user_stats.fetch_one_by_user_id_and_mode(user_id, mode)
response = await user_stats.fetch_one_by_user_id_and_akatsuki_mode(user_id, akatsuki_mode)
if isinstance(response, Error):
return JSONResponse(
content=response.model_dump(),
Expand Down
10 changes: 5 additions & 5 deletions app/common_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class RelaxMode(IntEnum):
AUTOPILOT = 2


class Mode(IntEnum):
class AkatsukiMode(IntEnum):
OSU = 0
TAIKO = 1
CATCH = 2
Expand All @@ -69,12 +69,12 @@ class Mode(IntEnum):
def from_game_mode_and_relax_mode(
game_mode: GameMode,
relax_mode: RelaxMode,
) -> "Mode":
) -> "AkatsukiMode":
if relax_mode is RelaxMode.VANILLA:
return Mode(game_mode.value)
return AkatsukiMode(game_mode.value)
elif relax_mode is RelaxMode.RELAX and game_mode is not GameMode.MANIA:
return Mode(game_mode.value + 4)
return AkatsukiMode(game_mode.value + 4)
elif relax_mode is RelaxMode.AUTOPILOT and game_mode is GameMode.OSU:
return Mode.AUTOPILOT_OSU
return AkatsukiMode.AUTOPILOT_OSU
else:
raise ValueError("Unknown game_mode and relax_mode combo")
10 changes: 5 additions & 5 deletions app/repositories/user_stats.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic import BaseModel

from app.common_types import Mode
from app.common_types import AkatsukiMode

import app.state

Expand Down Expand Up @@ -30,17 +30,17 @@ class UserStats(BaseModel):
xh_count, x_count, sh_count, s_count, a_count, b_count, c_count, d_count, max_combo
"""

async def fetch_one_by_user_id_and_mode(
async def fetch_one_by_user_id_and_akatsuki_mode(
user_id: int,
mode: Mode,
akatsuki_mode: AkatsukiMode,
) -> UserStats | None:
query = f"""
SELECT {READ_PARAMS}
FROM user_stats
WHERE user_id = :user_id
AND mode = :mode
AND mode = :akatsuki_mode
"""
params = {"user_id": user_id, "mode": mode.value}
params = {"user_id": user_id, "akatsuki_mode": akatsuki_mode.value}

user_stats = await app.state.database.fetch_one(query, params)
if user_stats is None:
Expand Down
6 changes: 3 additions & 3 deletions app/usecases/user_stats.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from app.common_types import Mode
from app.common_types import AkatsukiMode
from app.models.user_stats import UserStats
from app.errors import Error
from app.errors import ErrorCode
from app.repositories import user_stats

async def fetch_one_by_user_id_and_mode(user_id: int, mode: Mode) -> UserStats | Error:
stats = await user_stats.fetch_one_by_user_id_and_mode(user_id, mode)
async def fetch_one_by_user_id_and_akatsuki_mode(user_id: int, mode: AkatsukiMode) -> UserStats | Error:
stats = await user_stats.fetch_one_by_user_id_and_akatsuki_mode(user_id, mode)
if stats is None:
return Error(
error_code=ErrorCode.NOT_FOUND,
Expand Down

0 comments on commit 55b6743

Please sign in to comment.