Skip to content

Commit

Permalink
feat(api-gateway): support query links
Browse files Browse the repository at this point in the history
  • Loading branch information
renjie-run committed Apr 10, 2024
1 parent 2243006 commit 6e84d8b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 29 deletions.
75 changes: 47 additions & 28 deletions seatable_api/api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def _filtered_rows_server_url(self):
def _row_link_server_url(self):
return self.api_gateway_url + '/api/v2/dtables/' + self.dtable_uuid + '/links/'

def _query_links_server_url(self):
return self.api_gateway_url + '/api/v2/dtables/' + self.dtable_uuid + '/query-links/'

def _batch_update_row_link_server_url(self):
return self._row_link_server_url()

Expand Down Expand Up @@ -148,7 +151,7 @@ def get_view_by_name(self, table_name, view_name):
response = requests.get(view_url, headers=self.headers, timeout=self.timeout)
return parse_response(response)


def add_view(self, table_name, view_name):
url = self._view_server_url()
view_url = '%(url)s/?table_name=%(table_name)s' % ({
Expand All @@ -161,7 +164,7 @@ def add_view(self, table_name, view_name):
response = requests.post(view_url, json=json_data, headers=self.headers, timeout=self.timeout)
return parse_response(response)


def rename_view(self, table_name, view_name, new_view_name):
url = self._view_server_url()
view_url = '%(url)s/%(view_name)s/?table_name=%(table_name)s' % ({
Expand All @@ -175,7 +178,7 @@ def rename_view(self, table_name, view_name, new_view_name):
response = requests.put(view_url, json=json_data, headers=self.headers, timeout=self.timeout)
return parse_response(response)


def delete_view(self, table_name, view_name):
url = self._view_server_url()
view_url = '%(url)s/%(view_name)s/?table_name=%(table_name)s' % ({
Expand All @@ -186,7 +189,7 @@ def delete_view(self, table_name, view_name):
response = requests.delete(view_url, headers=self.headers, timeout=self.timeout)
return parse_response(response)


def list_rows(self, table_name, view_name=None, order_by=None, desc=False, start=None, limit=None):
"""
:param table_name: str
Expand Down Expand Up @@ -217,7 +220,7 @@ def list_rows(self, table_name, view_name=None, order_by=None, desc=False, start
data = parse_response(response)
return data.get('rows')


def get_row(self, table_name, row_id):
"""
:param table_name: str
Expand All @@ -235,7 +238,7 @@ def get_row(self, table_name, row_id):
data = parse_response(response)
return data


def append_row(self, table_name, row_data, apply_default=None):
"""
:param table_name: str
Expand All @@ -253,7 +256,7 @@ def append_row(self, table_name, row_data, apply_default=None):
response = requests.post(url, json=json_data, headers=self.headers, timeout=self.timeout)
return parse_response(response)


def batch_append_rows(self, table_name, rows_data, apply_default=None):
"""
:param table_name: str
Expand All @@ -271,7 +274,7 @@ def batch_append_rows(self, table_name, rows_data, apply_default=None):
response = requests.post(url, json=json_data, headers=self.headers, timeout=self.timeout)
return parse_response(response)


def insert_row(self, table_name, row_data, anchor_row_id, apply_default=None):
"""
:param table_name: str
Expand All @@ -291,7 +294,7 @@ def insert_row(self, table_name, row_data, anchor_row_id, apply_default=None):
response = requests.post(url, json=json_data, headers=self.headers, timeout=self.timeout)
return parse_response(response)


def update_row(self, table_name, row_id, row_data):
"""
:param table_name: str
Expand All @@ -309,7 +312,7 @@ def update_row(self, table_name, row_id, row_data):
response = requests.put(url, json=json_data, headers=self.headers, timeout=self.timeout)
return parse_response(response)


def batch_update_rows(self, table_name, rows_data):
"""
:param table_name: str
Expand All @@ -326,7 +329,7 @@ def batch_update_rows(self, table_name, rows_data):
response = requests.put(url, json=json_data, headers=self.headers, timeout=self.timeout)
return parse_response(response)


def delete_row(self, table_name, row_id):
"""
:param table_name: str
Expand All @@ -342,7 +345,7 @@ def delete_row(self, table_name, row_id):
response = requests.delete(url, json=json_data, headers=self.headers, timeout=self.timeout)
return parse_response(response)


def batch_delete_rows(self, table_name, row_ids):
"""
:param table_name: str
Expand All @@ -358,7 +361,7 @@ def batch_delete_rows(self, table_name, row_ids):
response = requests.delete(url, json=json_data, headers=self.headers, timeout=self.timeout)
return parse_response(response)


def filter_rows(self, table_name, filters, view_name=None, filter_conjunction='And'):
"""
:param table_name: str
Expand Down Expand Up @@ -425,7 +428,7 @@ def add_link(self, link_id, table_name, other_table_name, row_id, other_row_id):
response = requests.post(url, json=json_data, headers=self.headers, timeout=self.timeout)
return parse_response(response)


def remove_link(self, link_id, table_name, other_table_name, row_id, other_row_id):
"""
:param link_id: str
Expand All @@ -448,7 +451,7 @@ def remove_link(self, link_id, table_name, other_table_name, row_id, other_row_i
response = requests.delete(url, json=json_data, headers=self.headers, timeout=self.timeout)
return parse_response(response)


def update_link(self, link_id, table_name, other_table_name, row_id, other_rows_ids):
"""
:param link_id: str
Expand All @@ -475,7 +478,7 @@ def update_link(self, link_id, table_name, other_table_name, row_id, other_rows_
response = requests.put(url, json=json_data, headers=self.headers, timeout=self.timeout)
return parse_response(response)


def batch_update_links(self, link_id, table_name, other_table_name, row_id_list, other_rows_ids_map):
"""
:param link_id: str
Expand All @@ -500,6 +503,22 @@ def batch_update_links(self, link_id, table_name, other_table_name, row_id_list,
return parse_response(response)


def get_linked_records(self, table_id, link_column_key, rows):
"""
:param table_id: str
:param link_column_key: str
:param rows: list
"""
url = self._query_links_server_url()
json_data = {
'table_id': table_id,
'link_column_key': link_column_key,
'rows': rows,
}
response = requests.post(url, json=json_data, headers=self.headers, timeout=self.timeout)
return parse_response(response)


def list_columns(self, table_name, view_name=None):
"""
:param table_name: str
Expand All @@ -518,30 +537,30 @@ def list_columns(self, table_name, view_name=None):
data = parse_response(response)
return data.get('columns')


def get_column_link_id(self, table_name, column_name):
columns = self.list_columns(table_name)
for column in columns:
if column.get('name') == column_name and column.get('type') == 'link':
return column.get('data', {}).get('link_id')
raise ValueError('link type column "%s" does not exist in current table' % column_name)


def get_column_by_name(self, table_name, column_name):
columns = self.list_columns(table_name)
for col in columns:
if col.get('name') == column_name:
return col


def get_columns_by_type(self, table_name, column_type: ColumnTypes):
if column_type not in ColumnTypes:
raise ValueError("type %s invalid!" % (column_type,))
columns = self.list_columns(table_name)
cols_results = [col for col in columns if col.get('type') == column_type.value]
return cols_results


def insert_column(self, table_name, column_name, column_type, column_key=None, column_data=None):
"""
:param table_name: str
Expand Down Expand Up @@ -569,7 +588,7 @@ def insert_column(self, table_name, column_name, column_type, column_key=None, c
data = parse_response(response)
return data


def rename_column(self, table_name, column_key, new_column_name):
"""
:param table_name: str
Expand All @@ -590,7 +609,7 @@ def rename_column(self, table_name, column_key, new_column_name):
data = parse_response(response)
return data


def resize_column(self, table_name, column_key, new_column_width):
"""
:param table_name: str
Expand All @@ -612,7 +631,7 @@ def resize_column(self, table_name, column_key, new_column_width):
data = parse_response(response)
return data


def freeze_column(self, table_name, column_key, frozen):
"""
:param table_name: str
Expand All @@ -633,7 +652,7 @@ def freeze_column(self, table_name, column_key, frozen):
data = parse_response(response)
return data


def move_column(self, table_name, column_key, target_column_key):
"""
:param table_name: str
Expand All @@ -654,7 +673,7 @@ def move_column(self, table_name, column_key, target_column_key):
data = parse_response(response)
return data


def modify_column_type(self, table_name, column_key, new_column_type):
"""
:param table_name: str
Expand All @@ -677,7 +696,7 @@ def modify_column_type(self, table_name, column_key, new_column_type):
data = parse_response(response)
return data


def add_column_options(self, table_name, column, options):
"""
:param table_name: str
Expand All @@ -696,7 +715,7 @@ def add_column_options(self, table_name, column, options):
data = parse_response(response)
return data


def add_column_cascade_settings(self, table_name, child_column, parent_column, cascade_settings):
"""
Expand All @@ -719,7 +738,7 @@ def add_column_cascade_settings(self, table_name, child_column, parent_column, c
data = parse_response(response)
return data


def delete_column(self, table_name, column_key):
"""
:param table_name: str
Expand Down
3 changes: 2 additions & 1 deletion seatable_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _batch_update_row_link_server_url(self):

def _app_download_link_url(self):
return self.server_url + '/api/v2.1/dtable/app-download-link/'

def _app_custom_download_link_url(self):
return self.server_url + '/api/v2.1/dtable/custom/app-download-link/'

Expand Down Expand Up @@ -722,6 +722,7 @@ def batch_update_links(self, link_id, table_name, other_table_name, row_id_list,
return parse_response(response)

@check_auth
@api_gateway_wrapper
def get_linked_records(self, table_id, link_column_key, rows):
"""
:param table_id: str
Expand Down

0 comments on commit 6e84d8b

Please sign in to comment.