35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
from logging import Logger
|
|
|
|
from fastapi import HTTPException, status, APIRouter
|
|
from fastapi.responses import JSONResponse
|
|
from starlette.requests import Request
|
|
|
|
from classes.errors import WalletNotFoundError
|
|
from classes.fastapi import FastAPI
|
|
from classes.wallet import Wallet
|
|
from modules.utils import get_logger
|
|
|
|
logger: Logger = get_logger(__name__)
|
|
|
|
router_v1: APIRouter = APIRouter(
|
|
prefix="/v1/admin/guilds/{guild_id}/wallets", tags=["Admin - Wallets"]
|
|
)
|
|
|
|
|
|
@router_v1.get("/{user_id}", response_class=JSONResponse)
|
|
async def get_guild_wallet_v1(request: Request, guild_id: int, user_id: int) -> JSONResponse:
|
|
try:
|
|
wallet: Wallet = await Wallet.from_id(
|
|
user_id, guild_id, allow_creation=False, cache=request.app.bot.cache
|
|
)
|
|
except WalletNotFoundError as exc:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND, detail="Wallet not found"
|
|
) from exc
|
|
|
|
return JSONResponse(wallet.to_dict(json_compatible=True))
|
|
|
|
|
|
def setup(app: FastAPI) -> None:
|
|
app.include_router(router_v1)
|