Skip to content

Commit

Permalink
feat(api): ✨ New endpoint to set variables in a menuflow room
Browse files Browse the repository at this point in the history
  • Loading branch information
egalvis39 committed Nov 27, 2023
1 parent 8f69405 commit 1ab8744
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions menuflow/api/client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from __future__ import annotations

from json import JSONDecodeError
from typing import Dict

from aiohttp import web
from mautrix.client import Client as MatrixClient
from mautrix.errors import MatrixConnectionError, MatrixInvalidToken, MatrixRequestError
from mautrix.types import UserID

from ..menu import MenuClient
from ..room import Room
from .base import routes
from .responses import resp

Expand Down Expand Up @@ -55,3 +57,18 @@ async def create_client(request: web.Request) -> web.Response:
except JSONDecodeError:
return resp.body_not_json
return await _create_client(None, data)


@routes.post("/room/{room_id}/set_variables")
async def set_variables(request: web.Request) -> web.Response:
try:
data: Dict = await request.json()
except JSONDecodeError:
return resp.body_not_json
room_id = request.match_info["room_id"]
room = await Room.get_by_room_id(room_id)
variables = data.get("variables", {})

await room.set_variables(variables=variables)

return resp.ok
4 changes: 4 additions & 0 deletions menuflow/api/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def user_exists(self) -> web.Response:
status=HTTPStatus.CONFLICT,
)

@property
def ok(self) -> web.Response:
return web.json_response({}, status=HTTPStatus.OK)

@staticmethod
def created(data: dict) -> web.Response:
return web.json_response(data, status=HTTPStatus.CREATED)
Expand Down

0 comments on commit 1ab8744

Please sign in to comment.