From 9c1f6e55a67f864938c65dc863101d62c5ddf48b Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sun, 5 May 2024 22:12:45 +1200 Subject: [PATCH] implement api to fetch announces --- web.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/web.py b/web.py index 303a3b5..db5abd8 100644 --- a/web.py +++ b/web.py @@ -144,6 +144,41 @@ class ReticulumWebChat: return websocket_response + # serve announces + @routes.get("/api/v1/announces") + async def index(request): + + # get query params + aspect = request.query.get("aspect", None) + + # build announces database query + query = database.Announce.select() + + # filter by provided aspect + if aspect is not None: + query = query.where(database.Announce.aspect == aspect) + + # get announces from database + query_results = query.order_by(database.Announce.id.asc()) + + # process announces + announces = [] + for announce in query_results: + announces.append({ + "id": announce.id, + "destination_hash": announce.destination_hash, + "aspect": announce.aspect, + "identity_hash": announce.identity_hash, + "identity_public_key": announce.identity_public_key, + "app_data": announce.app_data, + "created_at": announce.created_at, + "updated_at": announce.updated_at, + }) + + return web.json_response({ + "announces": announces, + }) + # serve lxmf messages @routes.delete("/api/v1/lxmf-messages/{id}") async def index(request):