refactor(api): use Annotated-style dependency injection
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Literal
|
||||
from typing import Annotated, Literal
|
||||
|
||||
from app.database.best_scores import PPBestScore
|
||||
from app.database.score import Score, get_leaderboard
|
||||
@@ -69,10 +69,10 @@ class V1Score(AllStrModel):
|
||||
)
|
||||
async def get_user_best(
|
||||
session: Database,
|
||||
user: str = Query(..., alias="u", description="用户"),
|
||||
ruleset_id: int = Query(0, alias="m", description="Ruleset ID", ge=0),
|
||||
type: Literal["string", "id"] | None = Query(None, description="用户类型:string 用户名称 / id 用户 ID"),
|
||||
limit: int = Query(10, ge=1, le=100, description="返回的成绩数量"),
|
||||
user: Annotated[str, Query(..., alias="u", description="用户")],
|
||||
ruleset_id: Annotated[int, Query(alias="m", description="Ruleset ID", ge=0)] = 0,
|
||||
type: Annotated[Literal["string", "id"] | None, Query(description="用户类型:string 用户名称 / id 用户 ID")] = None,
|
||||
limit: Annotated[int, Query(ge=1, le=100, description="返回的成绩数量")] = 10,
|
||||
):
|
||||
try:
|
||||
scores = (
|
||||
@@ -101,10 +101,10 @@ async def get_user_best(
|
||||
)
|
||||
async def get_user_recent(
|
||||
session: Database,
|
||||
user: str = Query(..., alias="u", description="用户"),
|
||||
ruleset_id: int = Query(0, alias="m", description="Ruleset ID", ge=0),
|
||||
type: Literal["string", "id"] | None = Query(None, description="用户类型:string 用户名称 / id 用户 ID"),
|
||||
limit: int = Query(10, ge=1, le=100, description="返回的成绩数量"),
|
||||
user: Annotated[str, Query(..., alias="u", description="用户")],
|
||||
ruleset_id: Annotated[int, Query(alias="m", description="Ruleset ID", ge=0)] = 0,
|
||||
type: Annotated[Literal["string", "id"] | None, Query(description="用户类型:string 用户名称 / id 用户 ID")] = None,
|
||||
limit: Annotated[int, Query(ge=1, le=100, description="返回的成绩数量")] = 10,
|
||||
):
|
||||
try:
|
||||
scores = (
|
||||
@@ -133,12 +133,12 @@ async def get_user_recent(
|
||||
)
|
||||
async def get_scores(
|
||||
session: Database,
|
||||
user: str | None = Query(None, alias="u", description="用户"),
|
||||
beatmap_id: int = Query(alias="b", description="谱面 ID"),
|
||||
ruleset_id: int = Query(0, alias="m", description="Ruleset ID", ge=0),
|
||||
type: Literal["string", "id"] | None = Query(None, description="用户类型:string 用户名称 / id 用户 ID"),
|
||||
limit: int = Query(10, ge=1, le=100, description="返回的成绩数量"),
|
||||
mods: int = Query(0, description="成绩的 MOD"),
|
||||
beatmap_id: Annotated[int, Query(alias="b", description="谱面 ID")],
|
||||
user: Annotated[str | None, Query(alias="u", description="用户")] = None,
|
||||
ruleset_id: Annotated[int, Query(alias="m", description="Ruleset ID", ge=0)] = 0,
|
||||
type: Annotated[Literal["string", "id"] | None, Query(description="用户类型:string 用户名称 / id 用户 ID")] = None,
|
||||
limit: Annotated[int, Query(ge=1, le=100, description="返回的成绩数量")] = 10,
|
||||
mods: Annotated[int, Query(description="成绩的 MOD")] = 0,
|
||||
):
|
||||
try:
|
||||
if user is not None:
|
||||
|
||||
Reference in New Issue
Block a user