import json import logging from fasthtml.fastapp import fast_app from components.workflows.constants import Routes from core.instance_manager import InstanceManager, debug_session logger = logging.getLogger("WorkflowsApp") repositories_app, rt = fast_app() @rt(Routes.AddWorkflow) def get(session, _id: str): logger.debug(f"Entering {Routes.AddWorkflow} with args {debug_session(session)}, {_id=}") instance = InstanceManager.get(session, _id) return instance.request_new_workflow() @rt(Routes.AddWorkflow) def post(session, _id: str, tab_id: str, form_id: str, name: str, tab_boundaries: str): logger.debug( f"Entering {Routes.AddWorkflow} with args {debug_session(session)}, {_id=}, {tab_id=}, {form_id=}, {name=}, {tab_boundaries=}") instance = InstanceManager.get(session, _id) return instance.add_new_workflow(tab_id, form_id, name, json.loads(tab_boundaries)) @rt(Routes.ShowWorkflow) def post(session, _id: str, name: str, tab_boundaries: str): logger.debug( f"Entering {Routes.AddWorkflow} with args {debug_session(session)}, {_id=}, {name=}, {tab_boundaries=}") instance = InstanceManager.get(session, _id) return instance.show_workflow(name, json.loads(tab_boundaries)) @rt(Routes.AddComponent) def post(session, _id: str, component_type: str, x: int, y: int): logger.debug( f"Entering {Routes.AddComponent} with args {debug_session(session)}, {_id=}, {component_type=}, {x=}, {y=}") instance = InstanceManager.get(session, _id) return instance.add_component(component_type, x, y) @rt(Routes.MoveComponent) def post(session, _id: str, component_id: str, x: int, y: int): logger.debug( f"Entering {Routes.MoveComponent} with args {debug_session(session)}, {_id=}, {component_id=}, {x=}, {y=}") instance = InstanceManager.get(session, _id) return instance.move_component(component_id, x, y) @rt(Routes.DeleteComponent) def post(session, _id: str, component_id: str): logger.debug( f"Entering {Routes.DeleteComponent} with args {debug_session(session)}, {_id=}, {component_id=}") instance = InstanceManager.get(session, _id) return instance.delete_component(component_id) @rt(Routes.AddConnection) def post(session, _id: str, from_id: str, to_id: str): logger.debug( f"Entering {Routes.AddConnection} with args {debug_session(session)}, {_id=}, {from_id=}, {to_id=}") instance = InstanceManager.get(session, _id) return instance.add_connection(from_id, to_id)