diff options
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/app/controllers/graph_controller.py | 6 | ||||
| -rw-r--r-- | cli/app/controllers/page_controller.py | 30 |
2 files changed, 33 insertions, 3 deletions
diff --git a/cli/app/controllers/graph_controller.py b/cli/app/controllers/graph_controller.py index 3fa4cce..7efda73 100644 --- a/cli/app/controllers/graph_controller.py +++ b/cli/app/controllers/graph_controller.py @@ -17,13 +17,13 @@ class GraphView(CrudView): session.query(Tile).filter(Tile.page_id == item.id).delete(synchronize_session=False) session.query(Page).filter(Page.graph_id == item.id).delete(synchronize_session=False) - @route('/name/<path>', methods=['GET']) - def get_name(self, path: str): + @route('/name/<graph_path>', methods=['GET']) + def get_name(self, graph_path: str): """ Fetch a single {model}. """ session = Session() - item = session.query(self.model).filter(self.model.path == path).first() + item = session.query(self.model).filter(self.model.path == graph_path).first() if not item: session.close() return jsonify({ diff --git a/cli/app/controllers/page_controller.py b/cli/app/controllers/page_controller.py index 41d30f3..b6bfaa8 100644 --- a/cli/app/controllers/page_controller.py +++ b/cli/app/controllers/page_controller.py @@ -3,6 +3,7 @@ from flask_classful import route from werkzeug.datastructures import MultiDict from app.sql.common import db, Session +from app.sql.models.graph import Graph from app.sql.models.page import Page, PageForm from app.sql.models.tile import Tile from app.controllers.crud_controller import CrudView @@ -26,3 +27,32 @@ class PageView(CrudView): def on_destroy(self, session, item): session.query(Tile).filter(Tile.page_id == item.id).delete(synchronize_session=False) + + @route('/name/<graph_path>/<page_path>', methods=['GET']) + def get_name(self, graph_path: str, page_path: str): + """ + Fetch a single {model}. + """ + session = Session() + graph = session.query(Graph).filter(Graph.path == graph_path).first() + if not graph: + session.close() + return jsonify({ + 'status': 'error', + 'error': 'graph not found' + }) + + page = session.query(Page).filter(Page.graph_id == graph.id, Page.path == page_path).first() + if not page: + session.close() + return jsonify({ + 'status': 'error', + 'error': 'page not found' + }) + + result = { + 'status': 'ok', + 'res': page.toFullJSON() if hasattr(page, 'toFullJSON') else page.toJSON(), + } + session.close() + return jsonify(result) |
