weapon img, stats, url
This commit is contained in:
parent
9e0923c25d
commit
5a2c1d9bc7
@ -1,4 +1,4 @@
|
|||||||
from fastapi import APIRouter, HTTPException
|
from fastapi import APIRouter
|
||||||
|
|
||||||
from src.errors import Response
|
from src.errors import Response
|
||||||
from src.types.characters import Character, Constellations, Talents
|
from src.types.characters import Character, Constellations, Talents
|
||||||
|
@ -2,7 +2,7 @@ from fastapi import APIRouter
|
|||||||
|
|
||||||
from src.errors import Response
|
from src.errors import Response
|
||||||
from src.types.weapons import Weapon
|
from src.types.weapons import Weapon
|
||||||
from src.utils import load_index, parse_query_langs, parse_result_lang, load_category, get_file_name
|
from src.utils import load_file, load_index, parse_query_langs, parse_result_lang, load_category, get_file_name
|
||||||
|
|
||||||
weapons = APIRouter(prefix='/weapons', tags=['Weapons'])
|
weapons = APIRouter(prefix='/weapons', tags=['Weapons'])
|
||||||
|
|
||||||
@ -18,8 +18,26 @@ async def get_weapons(query_field: str = 'names', result_language: str = 'eng')
|
|||||||
|
|
||||||
|
|
||||||
@weapons.get('/{query}', response_model_exclude_none=True)
|
@weapons.get('/{query}', response_model_exclude_none=True)
|
||||||
async def get_weapon(query: str, query_languages: str = 'eng', result_language: str = 'ru') -> Response[Weapon]:
|
async def get_weapon(
|
||||||
|
query: str, query_languages: str = 'eng', result_language: str = 'ru',
|
||||||
|
images: bool = False, stats: bool = False, url: bool = False
|
||||||
|
) -> Response[Weapon]:
|
||||||
query_langs = parse_query_langs(query_languages)
|
query_langs = parse_query_langs(query_languages)
|
||||||
result_lang = parse_result_lang(result_language)
|
result_lang = parse_result_lang(result_language)
|
||||||
filename = get_file_name(query, 'weapons', query_langs)
|
filename = get_file_name(query, 'weapons', query_langs)
|
||||||
return Response[Weapon](response=load_category(result_lang, 'weapons', filename))
|
|
||||||
|
response = load_category(result_lang, 'weapons', filename)
|
||||||
|
if images:
|
||||||
|
images_file = load_file('image', 'weapons')
|
||||||
|
response.update({'images': images_file[filename]})
|
||||||
|
if stats:
|
||||||
|
stats_file = load_file('stats', 'weapons')
|
||||||
|
response.update({'stats': stats_file[filename]})
|
||||||
|
if url:
|
||||||
|
url_file = load_file('url', 'weapons')
|
||||||
|
response.update({'url': url_file[filename]})
|
||||||
|
|
||||||
|
version_file = load_file('version', 'weapons')
|
||||||
|
response.update({'version': version_file[filename]})
|
||||||
|
|
||||||
|
return Response[Weapon](response=response)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from typing import List
|
from typing import List, Optional
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
@ -17,6 +17,40 @@ class Costs(BaseModel):
|
|||||||
ascend6: List[AscendItem]
|
ascend6: List[AscendItem]
|
||||||
|
|
||||||
|
|
||||||
|
class URL(BaseModel):
|
||||||
|
fandom: str
|
||||||
|
|
||||||
|
|
||||||
|
class Images(BaseModel):
|
||||||
|
nameicon: str
|
||||||
|
namegacha: str
|
||||||
|
icon: str
|
||||||
|
nameawakenicon: str
|
||||||
|
awakenicon: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
class Base(BaseModel):
|
||||||
|
attack: float
|
||||||
|
specialized: float
|
||||||
|
|
||||||
|
|
||||||
|
class Curve(BaseModel):
|
||||||
|
attack: str
|
||||||
|
specialized: str
|
||||||
|
|
||||||
|
|
||||||
|
class PromotionItem(BaseModel):
|
||||||
|
maxlevel: int
|
||||||
|
attack: float
|
||||||
|
|
||||||
|
|
||||||
|
class Stats(BaseModel):
|
||||||
|
base: Base
|
||||||
|
curve: Curve
|
||||||
|
specialized: str
|
||||||
|
promotion: List[PromotionItem]
|
||||||
|
|
||||||
|
|
||||||
class Weapon(BaseModel):
|
class Weapon(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
description: str
|
description: str
|
||||||
@ -35,3 +69,7 @@ class Weapon(BaseModel):
|
|||||||
r5: List[str]
|
r5: List[str]
|
||||||
weaponmaterialtype: str
|
weaponmaterialtype: str
|
||||||
costs: Costs
|
costs: Costs
|
||||||
|
url: Optional[URL] = None
|
||||||
|
images: Optional[Images] = None
|
||||||
|
stats: Optional[Stats] = None
|
||||||
|
version: str
|
||||||
|
Loading…
Reference in New Issue
Block a user