Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api-gateway): support query links #95

Merged
merged 1 commit into from
Jul 9, 2024
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
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 @@ -218,7 +221,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 @@ -237,7 +240,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 @@ -256,7 +259,7 @@ def append_row(self, table_name, row_data, apply_default=None):
data = parse_response(response)
return data.get('first_row')


def batch_append_rows(self, table_name, rows_data, apply_default=None):
"""
:param table_name: str
Expand All @@ -274,15 +277,15 @@ 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
:param row_data: dict
:param anchor_row_id: str
"""
return self.append_row(table_name, row_data, apply_default=apply_default)


def update_row(self, table_name, row_id, row_data):
"""
Expand All @@ -301,7 +304,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 @@ -318,7 +321,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 @@ -334,7 +337,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 @@ -350,7 +353,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 @@ -417,7 +420,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 @@ -440,7 +443,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 @@ -467,7 +470,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 @@ -492,6 +495,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 @@ -510,30 +529,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 @@ -561,7 +580,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 @@ -582,7 +601,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 @@ -604,7 +623,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 @@ -625,7 +644,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 @@ -646,7 +665,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 @@ -669,7 +688,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 @@ -688,7 +707,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 @@ -711,7 +730,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
Loading