41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import logging
|
|
from logging import Logger
|
|
|
|
from fastapi import HTTPException, status
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from api.app import app
|
|
from classes import PycordGuild
|
|
from classes.errors import WalletNotFoundError, GuildNotFoundError
|
|
from classes.wallet import Wallet
|
|
|
|
logger: Logger = logging.getLogger(__name__)
|
|
|
|
|
|
@app.get("/v1/guilds/{guild_id}", response_class=JSONResponse)
|
|
async def get_guild_wallet(guild_id: int):
|
|
try:
|
|
guild: PycordGuild = await PycordGuild.from_id(guild_id, allow_creation=False)
|
|
except GuildNotFoundError as exc:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND, detail="Guild not found"
|
|
) from exc
|
|
except NotImplementedError as exc:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_501_NOT_IMPLEMENTED, detail="Not implemented"
|
|
) from exc
|
|
|
|
return guild.to_dict(json_compatible=True)
|
|
|
|
|
|
@app.get("/v1/guilds/{guild_id}/wallets/{user_id}", response_class=JSONResponse)
|
|
async def get_guild_wallet(guild_id: int, user_id: int):
|
|
try:
|
|
wallet: Wallet = await Wallet.from_id(user_id, guild_id, allow_creation=False)
|
|
except WalletNotFoundError as exc:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND, detail="Wallet not found"
|
|
) from exc
|
|
|
|
return wallet.to_dict(json_compatible=True)
|