24 lines
671 B
Python
24 lines
671 B
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 PycordUser
|
|
from classes.errors import UserNotFoundError
|
|
|
|
logger: Logger = logging.getLogger(__name__)
|
|
|
|
|
|
@app.get("/v1/users/{user_id}", response_class=JSONResponse)
|
|
async def get_user(user_id: int):
|
|
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 user.to_dict(json_compatible=True)
|