43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
from logging import Logger
|
|
|
|
from fastapi import HTTPException, status, APIRouter
|
|
from fastapi.responses import JSONResponse
|
|
from starlette.requests import Request
|
|
|
|
from classes import PycordGuild
|
|
from classes.errors import GuildNotFoundError
|
|
from classes.fastapi import FastAPI
|
|
from modules.utils import get_logger
|
|
|
|
logger: Logger = get_logger(__name__)
|
|
|
|
router_v1: APIRouter = APIRouter(prefix="/v1/admin/guilds", tags=["Admin - Guilds"])
|
|
|
|
|
|
# TODO Implement this method
|
|
@router_v1.get("/", response_class=JSONResponse)
|
|
async def get_guilds_v1() -> JSONResponse:
|
|
raise HTTPException(status_code=status.HTTP_501_NOT_IMPLEMENTED, detail="Not implemented")
|
|
|
|
|
|
@router_v1.get("/{guild_id}", response_class=JSONResponse)
|
|
async def get_guild_v1(request: Request, guild_id: int) -> JSONResponse:
|
|
try:
|
|
guild: PycordGuild = await PycordGuild.from_id(
|
|
guild_id, allow_creation=False, cache=request.app.bot.cache
|
|
)
|
|
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 JSONResponse(guild.to_dict(json_compatible=True))
|
|
|
|
|
|
def setup(app: FastAPI) -> None:
|
|
app.include_router(router_v1)
|