From ad6643421def5f7d4e0031dbe6835b41d91553bb Mon Sep 17 00:00:00 2001 From: Luna Date: Wed, 29 Jul 2020 17:37:03 -0300 Subject: [PATCH] add route to fetch notes from singular users --- litecord/blueprints/user/settings.py | 21 +++++++++++++++++++++ litecord/errors.py | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/litecord/blueprints/user/settings.py b/litecord/blueprints/user/settings.py index 0d81f9d..ae05b59 100644 --- a/litecord/blueprints/user/settings.py +++ b/litecord/blueprints/user/settings.py @@ -23,6 +23,7 @@ from litecord.auth import token_check from litecord.schemas import validate, USER_SETTINGS, GUILD_SETTINGS from litecord.blueprints.checks import guild_check from litecord.pubsub.user import dispatch_user +from litecord.errors import UserNotFound bp = Blueprint("users_settings", __name__) @@ -129,6 +130,26 @@ async def patch_guild_settings(guild_id: int): return jsonify(settings) +@bp.route("/@me/notes/", methods=["GET"]) +async def get_note(target_id: int): + """Get a single note from a user.""" + user_id = await token_check() + note = await app.db.fetchval( + """ + SELECT note + FROM notes + WHERE user_id = $1 AND target_id = $2 + """, + user_id, + target_id, + ) + + if note is None: + raise UserNotFound() + + return jsonify({"user_id": user_id, "note_user_id": target_id, "note": note}) + + @bp.route("/@me/notes/", methods=["PUT"]) async def put_note(target_id: int): """Put a note to a user. diff --git a/litecord/errors.py b/litecord/errors.py index 0820f51..bef8c04 100644 --- a/litecord/errors.py +++ b/litecord/errors.py @@ -142,6 +142,10 @@ class WebhookNotFound(NotFound): error_code = 10015 +class UserNotFound(NotFound): + error_code = 10013 + + class Ratelimited(LitecordError): status_code = 429