diff --git a/extra/app.py b/extra/app.py index b06451b3..996d941f 100644 --- a/extra/app.py +++ b/extra/app.py @@ -26,42 +26,42 @@ async def index(): return RedirectResponse("/docs") -@app.get("/card/{hoyolab_uid}", response_model=genshin.models.RecordCard) +@app.get("/card/{hoyolab_uid}", response_model=genshin.models.RecordCard, tags=["chronicle"]) async def hoyolab_user(hoyolab_uid: int, lang: Lang = None): return await client.get_record_card(hoyolab_uid, lang=lang) -@app.get("/user/{uid}", response_model=genshin.models.UserStats) +@app.get("/user/{uid}", response_model=genshin.models.UserStats, tags=["chronicle"]) async def user(uid: int, lang: Lang = None): return await client.get_user(uid, lang=lang) -@app.get("/user/{uid}/abyss", response_model=genshin.models.SpiralAbyss) +@app.get("/user/{uid}/abyss", response_model=genshin.models.SpiralAbyss, tags=["chronicle"]) async def abyss(uid: int, previous: bool = False): return await client.get_spiral_abyss(uid, previous=previous) -@app.get("/user/{uid}/notes", response_model=genshin.models.Notes) +@app.get("/user/{uid}/notes", response_model=genshin.models.Notes, tags=["chronicle"]) async def notes(uid: int, lang: Lang = None): return await client.get_notes(uid, lang=lang) -@app.get("/user/{uid}/activities", response_model=genshin.models.Activities) +@app.get("/user/{uid}/activities", response_model=genshin.models.Activities, tags=["chronicle"]) async def activities(uid: int, lang: Lang = None): return await client.get_activities(uid, lang=lang) -@app.get("/user/{uid}/partial", response_model=genshin.models.PartialUserStats) +@app.get("/user/{uid}/partial", response_model=genshin.models.PartialUserStats, tags=["chronicle"]) async def partial_user(uid: int, lang: Lang = None): return await client.get_partial_user(uid, lang=lang) -@app.get("/user/{uid}/full", response_model=genshin.models.FullUserStats) +@app.get("/user/{uid}/full", response_model=genshin.models.FullUserStats, tags=["chronicle"]) async def full_user(uid: int, lang: Lang = None): return await client.get_full_user(uid, lang=lang) -@app.get("/wish", response_model=List[genshin.models.Wish]) +@app.get("/wish", response_model=List[genshin.models.Wish], tags=["remote"]) async def wish( authkey: str, banner: Literal["100", "200", "301", "302"] = None, @@ -82,6 +82,7 @@ async def wish( @app.get( "/transaction", response_model=List[Union[genshin.models.Transaction, genshin.models.ItemTransaction]], + tags=["remote"], ) async def transaction( authkey: str, @@ -94,6 +95,49 @@ async def transaction( return await paginator.flatten() +@app.get( + "/calculator/characters", + response_model=List[genshin.models.CalculatorCharacter], + tags=["calculator"], +) +async def calculator_characters(query: str = None, lang: Lang = None): + return await client.get_calculator_characters(query=query, lang=lang) + + +@app.get( + "/calculator/weapons", response_model=List[genshin.models.CalculatorWeapon], tags=["calculator"] +) +async def calculator_weapons(query: str = None, lang: Lang = None): + return await client.get_calculator_weapons(query=query, lang=lang) + + +@app.get( + "/calculator/artifacts", + response_model=List[genshin.models.CalculatorArtifact], + tags=["calculator"], +) +async def calculator_artifacts(query: str = None, pos: int = 1, lang: Lang = None): + return await client.get_calculator_artifacts(query=query, pos=pos, lang=lang) + + +@app.get( + "/calculator/characters/{character_id}/talents", + response_model=List[genshin.models.CalculatorTalent], + tags=["calculator"], +) +async def calculator_character_talents(character_id: int, lang: Lang = None): + return await client.get_character_talents(character_id) + + +@app.get( + "/calculator/artifacts/{artifact_id}/set", + response_model=List[genshin.models.CalculatorArtifact], + tags=["calculator"], +) +async def calculator_artifact_set(artifact_id: int, lang: Lang = None): + return await client.get_complete_artifact_set(artifact_id, lang=lang) + + @app.exception_handler(genshin.GenshinException) async def handle_genshin_exception(request: Request, exc: genshin.GenshinException): if isinstance(exc, genshin.AccountNotFound): diff --git a/genshin/models/calculator.py b/genshin/models/calculator.py index 02eba40a..4e5a9f8a 100644 --- a/genshin/models/calculator.py +++ b/genshin/models/calculator.py @@ -54,12 +54,18 @@ class CalculatorCharacter(BaseCharacter): level: int = Field(0, galias="level_current") max_level: int - @validator("element") + @validator("element", pre=True) def __parse_element(cls, v: Any) -> str: + if isinstance(v, str): + return v + return CALCULATOR_ELEMENTS[int(v)] - @validator("weapon_type") + @validator("weapon_type", pre=True) def __parse_weapon_type(cls, v: Any) -> str: + if isinstance(v, str): + return v + return CALCULATOR_WEAPON_TYPES[int(v)] @@ -74,8 +80,11 @@ class CalculatorWeapon(GenshinModel, Unique): level: int = Field(0, galias="level_current") max_level: int - @validator("type") + @validator("type", pre=True) def __parse_weapon_type(cls, v: Any) -> str: + if isinstance(v, str): + return v + return CALCULATOR_WEAPON_TYPES[int(v)] @@ -85,8 +94,8 @@ class CalculatorArtifact(GenshinModel, Unique): id: int name: str icon: str - rarity: int = Field(alias="reliquary_level") - pos: int = Field(alias="reliquary_cat_id") + rarity: int = Field(galias="reliquary_level") + pos: int = Field(galias="reliquary_cat_id") level: int = Field(0, galias="level_current") max_level: int @@ -171,8 +180,8 @@ def __correct_talent_current_level(cls, v: List[CalculatorTalent]) -> List[Calcu class CalculatorArtifactResult(GenshinModel): """A calulation result for a specific artifact""" - artifact_id: int = Field(alias="reliquary_id") - list: List[CalculatorConsumable] = Field(alias="id_consume_list") + artifact_id: int = Field(galias="reliquary_id") + list: List[CalculatorConsumable] = Field(galias="id_consume_list") class CalculatorResult(GenshinModel):