diff --git a/itd/client.py b/itd/client.py index 714f5cd..9b8bd38 100644 --- a/itd/client.py +++ b/itd/client.py @@ -352,12 +352,13 @@ class Client: @refresh_on_error - def add_comment(self, post_id: UUID, content: str) -> Comment: + def add_comment(self, post_id: UUID, content: str, attachment_ids: list[UUID] = []) -> Comment: """Добавить комментарий Args: post_id (str): UUID поста content (str): Содержание + attachment_ids (list[UUID]): Список UUID прикреплённых файлов reply_comment_id (UUID | None, optional): ID коммента для ответа. Defaults to None. Raises: @@ -367,7 +368,7 @@ class Client: Returns: Comment: Комментарий """ - res = add_comment(self.token, post_id, content) + res = add_comment(self.token, post_id, content, attachment_ids) if res.status_code == 422 and 'found' in res.json(): raise ValidationError(*list(res.json()['found'].items())[0]) if res.json().get('error', {}).get('code') == 'NOT_FOUND': @@ -378,13 +379,14 @@ class Client: @refresh_on_error - def add_reply_comment(self, comment_id: UUID, content: str, author_id: UUID) -> Comment: + def add_reply_comment(self, comment_id: UUID, content: str, author_id: UUID, attachment_ids: list[UUID] = []) -> Comment: """Добавить ответный комментарий Args: comment_id (str): UUID комментария content (str): Содержание author_id (UUID | None, optional): ID пользователя, отправившего комментарий. Defaults to None. + attachment_ids (list[UUID]): Список UUID прикреплённых файлов Raises: ValidationError: Ошибка валидации @@ -393,7 +395,7 @@ class Client: Returns: Comment: Комментарий """ - res = add_reply_comment(self.token, comment_id, content, author_id) + res = add_reply_comment(self.token, comment_id, content, author_id, attachment_ids) if res.status_code == 500 and 'Failed query' in res.text: raise NotFound('User') if res.status_code == 422 and 'found' in res.json(): diff --git a/itd/routes/comments.py b/itd/routes/comments.py index d98ddf2..c211b17 100644 --- a/itd/routes/comments.py +++ b/itd/routes/comments.py @@ -2,11 +2,11 @@ from uuid import UUID from itd.request import fetch -def add_comment(token: str, post_id: UUID, content: str): - return fetch(token, 'post', f'posts/{post_id}/comments', {'content': content}) +def add_comment(token: str, post_id: UUID, content: str, attachment_ids: list[UUID] = []): + return fetch(token, 'post', f'posts/{post_id}/comments', {'content': content, "attachmentIds": list(map(str, attachment_ids))}) -def add_reply_comment(token: str, comment_id: UUID, content: str, author_id: UUID): - return fetch(token, 'post', f'comments/{comment_id}/replies', {'content': content, 'replyToUserId': str(author_id)}) +def add_reply_comment(token: str, comment_id: UUID, content: str, author_id: UUID, attachment_ids: list[UUID] = []): + return fetch(token, 'post', f'comments/{comment_id}/replies', {'content': content, 'replyToUserId': str(author_id), "attachmentIds": list(map(str, attachment_ids))}) def get_comments(token: str, post_id: UUID, limit: int = 20, cursor: int = 0, sort: str = 'popular'): return fetch(token, 'get', f'posts/{post_id}/comments', {'limit': limit, 'sort': sort, 'cursor': cursor})