feat(user): add ISO 3166-1 code
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
from datetime import UTC, datetime, timedelta
|
||||
import json
|
||||
from typing import TYPE_CHECKING, NotRequired, TypedDict
|
||||
|
||||
from app.models.model import UTCBaseModel
|
||||
from app.models.score import GameMode
|
||||
from app.models.user import Country, Page
|
||||
from app.path import STATIC_DIR
|
||||
|
||||
from .achievement import UserAchievement, UserAchievementResp
|
||||
from .beatmap_playcounts import BeatmapPlaycounts
|
||||
@@ -62,6 +64,8 @@ Badge = TypedDict(
|
||||
},
|
||||
)
|
||||
|
||||
COUNTRIES = json.loads((STATIC_DIR / "iso3166.json").read_text())
|
||||
|
||||
|
||||
class UserBase(UTCBaseModel, SQLModel):
|
||||
avatar_url: str = ""
|
||||
@@ -267,6 +271,9 @@ class UserResp(UserBase):
|
||||
|
||||
u = cls.model_validate(obj.model_dump())
|
||||
u.id = obj.id
|
||||
u.country = Country(
|
||||
code=obj.country_code, name=COUNTRIES.get(obj.country_code, "Unknown")
|
||||
)
|
||||
u.follower_count = (
|
||||
await session.exec(
|
||||
select(func.count())
|
||||
|
||||
@@ -3,3 +3,4 @@
|
||||
- `mods.json`: 包含了游戏中的所有可用mod的详细信息。
|
||||
- Origin: https://github.com/ppy/osu-web/blob/master/database/mods.json
|
||||
- Version: 2025/7/30 `ff49b66b27a2850aea4b6b3ba563cfe936cb6082`
|
||||
- `iso3166.json`: 包含了所有国家和地区的ISO 3166-1代码。
|
||||
|
||||
Reference in New Issue
Block a user