Merge pull request #4 from EpsilonRationes/comment-attachments
This commit is contained in:
@@ -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():
|
||||
|
||||
@@ -8,7 +8,7 @@ class File(BaseModel):
|
||||
id: UUID
|
||||
url: str
|
||||
filename: str
|
||||
mime_type: str = Field('image/png', alias='mimeType')
|
||||
mime_type: str = Field(alias='mimeType')
|
||||
size: int
|
||||
|
||||
|
||||
|
||||
@@ -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})
|
||||
|
||||
Reference in New Issue
Block a user