diff --git a/dj_gui_api_server/DJConnector.py b/dj_gui_api_server/DJConnector.py index c179681..34f1529 100644 --- a/dj_gui_api_server/DJConnector.py +++ b/dj_gui_api_server/DJConnector.py @@ -121,6 +121,25 @@ def get_table_definition(jwt_payload, schema_name, table_name): schema_virtual_module = dj.create_virtual_module(schema_name, schema_name) return getattr(schema_virtual_module, table_name).describe() + """ + Insert tuple table + + Parameters: + jwt_payload (dict): Dictionary containing databaseAddress, username and password strings + schema_name (string): Schema name where to find the table under + table_name (string): Table name under the given schema, must be in camel case + tuple (dict): tuple to be inserted + + Return: + bool: true if input is sucessful + """ + @staticmethod + def insert_tuple(jwt_payload, schema_name, table_name, tuple_to_insert): + DJConnector.set_datajoint_config(jwt_payload) + + schema_virtual_module = dj.create_virtual_module(schema_name, schema_name) + return getattr(schema_virtual_module, table_name).insert1(tuple_to_insert) + """ Method to set credentials for database diff --git a/dj_gui_api_server/DJGUIAPIServer.py b/dj_gui_api_server/DJGUIAPIServer.py index 7360552..f16b29a 100644 --- a/dj_gui_api_server/DJGUIAPIServer.py +++ b/dj_gui_api_server/DJGUIAPIServer.py @@ -42,7 +42,7 @@ def hello_world(): Returns: dict(jwt=): If sucessfully authenticated against the database or - dict(error=): With error message of why it failed + string: With error message of why it failed, 500 error """ @app.route('/api/login', methods=['POST']) def login(): @@ -68,7 +68,7 @@ def login(): Returns: dict(schemaNames=): If sucessfuly send back a list of schemas names or - dict(error=): With error message of why it failed + string: With error message of why it failed, 500 error """ @app.route('/api/list_schemas', methods=['GET']) @protected_route @@ -95,7 +95,7 @@ def list_schemas(jwt_payload): partTables=[] ): If successful then send back a list of tables names or - dict(error=): With error message of why it failed + string: With error message of why it failed, 500 error """ @app.route('/api/list_tables', methods=['POST']) @protected_route @@ -116,7 +116,7 @@ def list_tables(jwt_payload): Returns: dict(table_definition=table_definition): table_definition will be in string format or - dict(error=): With error message of why it failed + string: With error message of why it failed, 500 error """ @app.route('/api/fetch_tuples', methods=['POST']) @protected_route @@ -127,6 +127,29 @@ def fetch_tuples(jwt_payload): except Exception as e: return str(e), 500 +""" +Route to insert tuple + +Parameter: + Parameters: + header: (html:GET:Authorization): Must include in format of: bearer + body: (html:POST:JSON): {"schemaName": , "tableName": , "tuple", "tuple": } (NOTE: Table name must be in CamalCase) + +Returns: + string: "Insert Successful" if the tuple was insert sucessfully + or + string: With error message of why it failed, 500 error +""" +@app.route('/api/insert_tuple', methods=['POST']) +@protected_route +def insert_tuple(jwt_payload): + try: + # Attempt to insert + DJConnector.insert_tuple(jwt_payload, request.json["schemaName"], request.json["tableName"], request.json["tuple"]) + return "Insert Successful" + except Exception as e: + return str(e), 500 + """ Route to get table definition @@ -137,8 +160,7 @@ def fetch_tuples(jwt_payload): Returns: string: The table definition or - dict(error=): With error message of why it failed - + string: With error message of why it failed, 500 error """ @app.route('/api/get_table_definition', methods=['POST']) @protected_route