From 9e9b00021cc7612042f58dbb9285f754475bb563 Mon Sep 17 00:00:00 2001 From: basteks Date: Tue, 28 Oct 2025 16:46:44 +0100 Subject: [PATCH] Add batch_add_links and batch_remove_links --- seatable_api/api_gateway.py | 46 +++++++++++++++++++++++++++++++++++ seatable_api/main.py | 48 +++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/seatable_api/api_gateway.py b/seatable_api/api_gateway.py index 269136a..cecfbcc 100644 --- a/seatable_api/api_gateway.py +++ b/seatable_api/api_gateway.py @@ -419,6 +419,29 @@ 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 batch_add_links(self, link_id, table_name, other_table_name, other_rows_ids_map): + """ + :param link_id: str + :param table_name: str + :param other_table_name: str + :param other_rows_ids_map: dict + """ + url = self._row_link_server_url() + json_data = { + 'link_id': link_id, + 'table_name': table_name, + 'other_table_name': other_table_name, + 'other_rows_ids_map': other_rows_ids_map, + } + if like_table_id(table_name): + json_data['table_id'] = table_name + if like_table_id(other_table_name): + json_data['other_table_id'] = other_table_name + + 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): @@ -442,6 +465,29 @@ def remove_link(self, link_id, table_name, other_table_name, row_id, other_row_i json_data['other_table_id'] = other_table_name response = requests.delete(url, json=json_data, headers=self.headers, timeout=self.timeout) return parse_response(response) + + + def batch_remove_links(self, link_id, table_name, other_table_name, other_rows_ids_map): + """ + :param link_id: str + :param table_name: str + :param other_table_name: str + :param other_rows_ids_map: dict + """ + url = self._row_link_server_url() + json_data = { + 'link_id': link_id, + 'table_name': table_name, + 'other_table_name': other_table_name, + 'other_rows_ids_map': other_rows_ids_map, + } + if like_table_id(table_name): + json_data['table_id'] = table_name + if like_table_id(other_table_name): + json_data['other_table_id'] = other_table_name + + 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): diff --git a/seatable_api/main.py b/seatable_api/main.py index 698b250..7368d33 100644 --- a/seatable_api/main.py +++ b/seatable_api/main.py @@ -641,6 +641,30 @@ def add_link(self, link_id, table_name, other_table_name, row_id, other_row_id): json_data['other_table_id'] = other_table_name response = requests.post(url, json=json_data, headers=self.headers, timeout=self.timeout) return parse_response(response) + + @check_auth + @api_gateway_wrapper + def batch_add_links(self, link_id, table_name, other_table_name, other_rows_ids_map): + """ + :param link_id: str + :param table_name: str + :param other_table_name: str + :param other_rows_ids_map: dict + """ + url = self._row_link_server_url() + json_data = { + 'link_id': link_id, + 'table_name': table_name, + 'other_table_name': other_table_name, + 'other_rows_ids_map': other_rows_ids_map, + } + if like_table_id(table_name): + json_data['table_id'] = table_name + if like_table_id(other_table_name): + json_data['other_table_id'] = other_table_name + + response = requests.post(url, json=json_data, headers=self.headers, timeout=self.timeout) + return parse_response(response) @check_auth @api_gateway_wrapper @@ -666,6 +690,30 @@ def remove_link(self, link_id, table_name, other_table_name, row_id, other_row_i json_data['other_table_id'] = other_table_name response = requests.delete(url, json=json_data, headers=self.headers, timeout=self.timeout) return parse_response(response) + + @check_auth + @api_gateway_wrapper + def batch_remove_links(self, link_id, table_name, other_table_name, other_rows_ids_map): + """ + :param link_id: str + :param table_name: str + :param other_table_name: str + :param other_rows_ids_map: dict + """ + url = self._row_link_server_url() + json_data = { + 'link_id': link_id, + 'table_name': table_name, + 'other_table_name': other_table_name, + 'other_rows_ids_map': other_rows_ids_map, + } + if like_table_id(table_name): + json_data['table_id'] = table_name + if like_table_id(other_table_name): + json_data['other_table_id'] = other_table_name + + response = requests.delete(url, json=json_data, headers=self.headers, timeout=self.timeout) + return parse_response(response) @check_auth @api_gateway_wrapper