fix(v1-api): 500 when request with username

This commit is contained in:
MingxuanGame
2025-08-14 13:14:49 +00:00
parent 46a1d049fe
commit 55c25bf96e
2 changed files with 5 additions and 5 deletions

View File

@@ -16,7 +16,7 @@ from .router import router
from fastapi import Depends, HTTPException, Query
from pydantic import BaseModel
from sqlmodel import select
from sqlmodel import col, select
from sqlmodel.ext.asyncio.session import AsyncSession
@@ -61,7 +61,7 @@ async def download_replay(
Score.beatmap_id == beatmap,
Score.user_id == user
if type == "id" or user.isdigit()
else Score.user.username == user,
else col(Score.user).has(username=user),
Score.mods == mods_,
Score.gamemode == GameMode.from_int_extra(ruleset_id)
if ruleset_id is not None

View File

@@ -83,7 +83,7 @@ async def get_user_best(
.where(
Score.user_id == user
if type == "id" or user.isdigit()
else Score.user.username == user,
else col(Score.user).has(username=user),
Score.gamemode == GameMode.from_int_extra(ruleset_id),
exists().where(col(PPBestScore.score_id) == Score.id),
)
@@ -119,7 +119,7 @@ async def get_user_recent(
.where(
Score.user_id == user
if type == "id" or user.isdigit()
else Score.user.username == user,
else col(Score.user).has(username=user),
Score.gamemode == GameMode.from_int_extra(ruleset_id),
Score.ended_at > datetime.now(UTC) - timedelta(hours=24),
)
@@ -160,7 +160,7 @@ async def get_scores(
Score.beatmap_id == beatmap_id,
Score.user_id == user
if type == "id" or user.isdigit()
else Score.user.username == user,
else col(Score.user).has(username=user),
)
.options(joinedload(Score.beatmap))
.order_by(col(Score.classic_total_score).desc())