Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions dj_gui_api_server/DJConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 28 additions & 6 deletions dj_gui_api_server/DJGUIAPIServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def hello_world():
Returns:
dict(jwt=<JWT_TOKEN>): If sucessfully authenticated against the database
or
dict(error=<error_message>): 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():
Expand All @@ -68,7 +68,7 @@ def login():
Returns:
dict(schemaNames=<schemas>): If sucessfuly send back a list of schemas names
or
dict(error=<error_message>): 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
Expand All @@ -95,7 +95,7 @@ def list_schemas(jwt_payload):
partTables=[<parent_table.part_table_name>]
): If successful then send back a list of tables names
or
dict(error=<error_message>): 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
Expand All @@ -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=<error_message>): 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
Expand All @@ -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 <JWT-Token>
body: (html:POST:JSON): {"schemaName": <schema_name>, "tableName": <table_name>, "tuple", "tuple": <tuple_to_insert>} (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

Expand All @@ -137,8 +160,7 @@ def fetch_tuples(jwt_payload):
Returns:
string: The table definition
or
dict(error=<error_message>): 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
Expand Down