Files
Javelina/api/extensions/user.py

24 lines
725 B
Python

from logging import Logger
from fastapi import HTTPException, status
from fastapi.responses import JSONResponse
from api.app import app
from classes import PycordUser
from classes.errors import UserNotFoundError
from modules.utils import get_logger
logger: Logger = get_logger(__name__)
@app.get("/v1/admin/users/{user_id}", response_class=JSONResponse)
async def get_user_v1(user_id: int) -> JSONResponse:
try:
user: PycordUser = await PycordUser.from_id(user_id, allow_creation=False)
except UserNotFoundError as exc:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="User not found"
) from exc
return JSONResponse(user.to_dict(json_compatible=True))