diff --git a/itd/client.py b/itd/client.py index 6bb9d6c..0a5d94e 100644 --- a/itd/client.py +++ b/itd/client.py @@ -158,14 +158,14 @@ class Client: return self.get_user('me') @refresh_on_error - def update_profile(self, username: str | None = None, display_name: str | None = None, bio: str | None = None, banner_id: UUID | str | None = None) -> UserProfileUpdate: + def update_profile(self, username: str | None = None, display_name: str | None = None, bio: str | None = None, banner_id: UUID | None = None) -> UserProfileUpdate: """Обновить профиль Args: username (str | None, optional): username. Defaults to None. display_name (str | None, optional): Отображаемое имя. Defaults to None. bio (str | None, optional): Биография (о себе). Defaults to None. - banner_id (UUID | str | None, optional): UUID баннера. Defaults to None. + banner_id (UUID | None, optional): UUID баннера. Defaults to None. Raises: ValidationError: Ошибка валидации @@ -173,9 +173,6 @@ class Client: Returns: UserProfileUpdate: Обновленный профиль """ - if isinstance(banner_id, str): - banner_id = UUID(banner_id) - res = update_profile(self.token, bio, display_name, username, banner_id) if res.status_code == 422 and 'found' in res.json(): raise ValidationError(*list(res.json()['found'].items())[0]) @@ -376,13 +373,14 @@ class Client: @refresh_on_error - def add_comment(self, post_id: UUID | str, content: str, attachment_ids: list[UUID | str] = []) -> Comment: + def add_comment(self, post_id: UUID, content: str, attachment_ids: list[UUID] = []) -> Comment: """Добавить комментарий Args: - post_id (str | UUID): UUID поста + post_id (str): UUID поста content (str): Содержание - attachment_ids (list[UUID | str]): Список UUID прикреплённых файлов + attachment_ids (list[UUID]): Список UUID прикреплённых файлов + reply_comment_id (UUID | None, optional): ID коммента для ответа. Defaults to None. Raises: ValidationError: Ошибка валидации @@ -391,12 +389,7 @@ class Client: Returns: Comment: Комментарий """ - if isinstance(post_id, str): - post_id = UUID(post_id) - attachment_ids = list(map(lambda id: UUID(id) if isinstance(id, str) else id, attachment_ids)) - - res = add_comment(self.token, post_id, content, cast(list[UUID], attachment_ids)) - + 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': @@ -407,14 +400,14 @@ class Client: @refresh_on_error - def add_reply_comment(self, comment_id: UUID | str, content: str, author_id: UUID | str, attachment_ids: list[UUID | str] = []) -> Comment: + def add_reply_comment(self, comment_id: UUID, content: str, author_id: UUID, attachment_ids: list[UUID] = []) -> Comment: """Добавить ответный комментарий Args: - comment_id (str | UUID): UUID комментария + comment_id (str): UUID комментария content (str): Содержание - author_id (UUID | str): ID пользователя, отправившего комментарий. - attachment_ids (list[UUID | str]): Список UUID прикреплённых файлов + author_id (UUID | None, optional): ID пользователя, отправившего комментарий. Defaults to None. + attachment_ids (list[UUID]): Список UUID прикреплённых файлов Raises: ValidationError: Ошибка валидации @@ -423,13 +416,7 @@ class Client: Returns: Comment: Комментарий """ - if isinstance(comment_id, str): - comment_id = UUID(comment_id) - if isinstance(author_id, str): - author_id = UUID(author_id) - attachment_ids = list(map(lambda id: UUID(id) if isinstance(id, str) else id, attachment_ids)) - - res = add_reply_comment(self.token, comment_id, content, author_id, cast(list[UUID], attachment_ids)) + 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(): @@ -442,11 +429,11 @@ class Client: @refresh_on_error - def get_comments(self, post_id: UUID | str, limit: int = 20, cursor: int = 0, sort: str = 'popular') -> tuple[list[Comment], Pagination]: + def get_comments(self, post_id: UUID, limit: int = 20, cursor: int = 0, sort: str = 'popular') -> tuple[list[Comment], Pagination]: """Получить список комментариев Args: - post_id (UUID | str): UUID поста + post_id (UUID): UUID поста limit (int, optional): Лимит. Defaults to 20. cursor (int, optional): Курсор (сколько пропустить). Defaults to 0. sort (str, optional): Сортировка. Defaults to 'popular'. @@ -458,9 +445,6 @@ class Client: list[Comment]: Список комментариев Pagination: Пагинация """ - if isinstance(post_id, str): - post_id = UUID(post_id) - res = get_comments(self.token, post_id, limit, cursor, sort) if res.json().get('error', {}).get('code') == 'NOT_FOUND': raise NotFound('Post') @@ -470,11 +454,11 @@ class Client: return [Comment.model_validate(comment) for comment in data['comments']], Pagination(page=(cursor // limit) or 1, limit=limit, total=data['total'], hasMore=data['hasMore'], nextCursor=None) @refresh_on_error - def like_comment(self, id: UUID | str) -> int: + def like_comment(self, id: UUID) -> int: """Лайкнуть комментарий Args: - id (UUID | str): UUID комментария + id (UUID): UUID комментария Raises: NotFound: Комментарий не найден @@ -482,9 +466,6 @@ class Client: Returns: int: Количество лайков """ - if isinstance(id, str): - id = UUID(id) - res = like_comment(self.token, id) if res.json().get('error', {}).get('code') == 'NOT_FOUND': raise NotFound('Comment') @@ -493,11 +474,11 @@ class Client: return res.json()['likesCount'] @refresh_on_error - def unlike_comment(self, id: UUID | str) -> int: + def unlike_comment(self, id: UUID) -> int: """Убрать лайк с комментария Args: - id (UUID | str): UUID комментария + id (UUID): UUID комментария Raises: NotFound: Комментарий не найден @@ -505,9 +486,6 @@ class Client: Returns: int: Количество лайков """ - if isinstance(id, str): - id = UUID(id) - res = unlike_comment(self.token, id) if res.json().get('error', {}).get('code') == 'NOT_FOUND': raise NotFound('Comment') @@ -516,19 +494,16 @@ class Client: return res.json()['likesCount'] @refresh_on_error - def delete_comment(self, id: UUID | str) -> None: + def delete_comment(self, id: UUID) -> None: """Удалить комментарий Args: - id (UUID | str): UUID комментария + id (UUID): UUID комментария Raises: NotFound: Комментарий не найден Forbidden: Нет прав на удаление """ - if isinstance(id, str): - id = UUID(id) - res = delete_comment(self.token, id) if res.status_code == 204: return @@ -567,22 +542,19 @@ class Client: return [Hashtag.model_validate(hashtag) for hashtag in res.json()['data']['hashtags']] @refresh_on_error - def get_posts_by_hashtag(self, hashtag: str, limit: int = 20, cursor: UUID | str | None = None) -> tuple[Hashtag | None, list[Post], Pagination]: + def get_posts_by_hashtag(self, hashtag: str, limit: int = 20, cursor: UUID | None = None) -> tuple[Hashtag | None, list[Post], Pagination]: """Получить посты по хэштэгу Args: hashtag (str): Хэштэг (без #) limit (int, optional): Лимит. Defaults to 20. - cursor (UUID | str | None, optional): Курсор (UUID последнего поста, после которого брать данные). Defaults to None. + cursor (UUID | None, optional): Курсор (UUID последнего поста, после которого брать данные). Defaults to None. Returns: Hashtag | None: Хэштэг list[Post]: Посты Pagination: Пагинация """ - if isinstance(cursor, str): - cursor = UUID(cursor) - res = get_posts_by_hashtag(self.token, hashtag, limit, cursor) res.raise_for_status() data = res.json()['data'] @@ -611,18 +583,15 @@ class Client: ) @refresh_on_error - def mark_as_read(self, id: UUID | str) -> bool: + def mark_as_read(self, id: UUID) -> bool: """Прочитать уведомление Args: - id (UUID | str): UUID уведомления + id (UUID): UUID уведомления Returns: bool: Успешно (False - уже прочитано) """ - if isinstance(id, str): - id = UUID(id) - res = mark_as_read(self.token, id) res.raise_for_status() @@ -649,13 +618,13 @@ class Client: @refresh_on_error - def create_post(self, content: str, wall_recipient_id: UUID | str | None = None, attachment_ids: list[UUID | str] = []) -> NewPost: + def create_post(self, content: str, wall_recipient_id: UUID | None = None, attach_ids: list[UUID] = []) -> NewPost: """Создать пост Args: content (str): Содержимое - wall_recipient_id (UUID | str | None, optional): UUID пользователя (чтобы создать пост ему на стене). Defaults to None. - attachment_ids (list[UUID | str], optional): UUID вложений. Defaults to []. + wall_recipient_id (UUID | None, optional): UUID пользователя (чтобы создать пост ему на стене). Defaults to None. + attach_ids (list[UUID], optional): UUID вложений. Defaults to []. Raises: NotFound: Пользователь не найден @@ -664,11 +633,7 @@ class Client: Returns: NewPost: Новый пост """ - if isinstance(wall_recipient_id, str): - wall_recipient_id = UUID(wall_recipient_id) - attachment_ids = list(map(lambda id: UUID(id) if isinstance(id, str) else id, attachment_ids)) - - res = create_post(self.token, content, wall_recipient_id, cast(list[UUID], attachment_ids)) + res = create_post(self.token, content, wall_recipient_id, attach_ids) if res.json().get('error', {}).get('code') == 'NOT_FOUND': raise NotFound('Wall recipient') if res.status_code == 422 and 'found' in res.json(): @@ -696,11 +661,11 @@ class Client: return [Post.model_validate(post) for post in data['posts']], PostsPagintaion.model_validate(data['pagination']) @refresh_on_error - def get_post(self, id: UUID | str) -> Post: + def get_post(self, id: UUID) -> Post: """Получить пост Args: - id (UUID | str): UUID поста + id (UUID): UUID поста Raises: NotFound: Пост не найден @@ -708,9 +673,6 @@ class Client: Returns: Post: Пост """ - if isinstance(id, str): - id = UUID(id) - res = get_post(self.token, id) if res.json().get('error', {}).get('code') == 'NOT_FOUND': raise NotFound('Post') @@ -719,11 +681,11 @@ class Client: return Post.model_validate(res.json()['data']) @refresh_on_error - def edit_post(self, id: UUID | str, content: str) -> str: + def edit_post(self, id: UUID, content: str) -> str: """Редактировать пост Args: - id (UUID | str): UUID поста + id (UUID): UUID поста content (str): Содержимое Raises: @@ -734,9 +696,6 @@ class Client: Returns: str: Новое содержимое """ - if isinstance(id, str): - id = UUID(id) - res = edit_post(self.token, id, content) if res.json().get('error', {}).get('code') == 'NOT_FOUND': @@ -750,19 +709,16 @@ class Client: return res.json()['content'] @refresh_on_error - def delete_post(self, id: UUID | str) -> None: + def delete_post(self, id: UUID) -> None: """Удалить пост Args: - id (UUID | str): UUID поста + id (UUID): UUID поста Raises: NotFound: Пост не найден Forbidden: Нет доступа """ - if isinstance(id, str): - id = UUID(id) - res = delete_post(self.token, id) if res.status_code == 204: return @@ -774,19 +730,16 @@ class Client: res.raise_for_status() @refresh_on_error - def pin_post(self, id: UUID | str): + def pin_post(self, id: UUID): """Закрепить пост Args: - id (UUID | str): UUID поста + id (UUID): UUID поста Raises: NotFound: Пост не найден Forbidden: Нет доступа """ - if isinstance(id, str): - id = UUID(id) - res = pin_post(self.token, id) if res.json().get('error', {}).get('code') == 'NOT_FOUND': @@ -796,11 +749,11 @@ class Client: res.raise_for_status() @refresh_on_error - def repost(self, id: UUID | str, content: str | None = None) -> NewPost: + def repost(self, id: UUID, content: str | None = None) -> NewPost: """Репостнуть пост Args: - id (UUID | str): UUID поста + id (UUID): UUID поста content (str | None, optional): Содержимое (доп. комментарий). Defaults to None. Raises: @@ -812,9 +765,6 @@ class Client: Returns: NewPost: Новый пост """ - if isinstance(id, str): - id = UUID(id) - res = repost(self.token, id, content) if res.json().get('error', {}).get('code') == 'NOT_FOUND': @@ -830,18 +780,15 @@ class Client: return NewPost.model_validate(res.json()) @refresh_on_error - def view_post(self, id: UUID | str) -> None: + def view_post(self, id: UUID) -> None: """Просмотреть пост Args: - id (UUID | str): UUID поста + id (UUID): UUID поста Raises: NotFound: Пост не найден """ - if isinstance(id, str): - id = UUID(id) - res = view_post(self.token, id) if res.status_code == 204: return @@ -861,27 +808,19 @@ class Client: @refresh_on_error - def report(self, id: str | UUID, type: str = 'post', reason: str = 'other', description: str = ''): - if isinstance(id, str): - id = UUID(id) + def report(self, id: str, type: str = 'post', reason: str = 'other', description: str = ''): return report(self.token, id, type, reason, description) @refresh_on_error - def report_user(self, id: str | UUID, reason: str = 'other', description: str = ''): - if isinstance(id, str): - id = UUID(id) + def report_user(self, id: str, reason: str = 'other', description: str = ''): return report(self.token, id, 'user', reason, description) @refresh_on_error - def report_post(self, id: str | UUID, reason: str = 'other', description: str = ''): - if isinstance(id, str): - id = UUID(id) + def report_post(self, id: str, reason: str = 'other', description: str = ''): return report(self.token, id, 'post', reason, description) @refresh_on_error - def report_comment(self, id: str | UUID, reason: str = 'other', description: str = ''): - if isinstance(id, str): - id = UUID(id) + def report_comment(self, id: str, reason: str = 'other', description: str = ''): return report(self.token, id, 'comment', reason, description) diff --git a/itd/routes/reports.py b/itd/routes/reports.py index a186c1e..933f48d 100644 --- a/itd/routes/reports.py +++ b/itd/routes/reports.py @@ -1,5 +1,4 @@ from itd.request import fetch -from uuid import UUID -def report(token: str, id: UUID, type: str = 'post', reason: str = 'other', description: str = ''): +def report(token: str, id: str, type: str = 'post', reason: str = 'other', description: str = ''): return fetch(token, 'post', 'reports', {'targetId': id, 'targetType': type, 'reason': reason, 'description': description}) \ No newline at end of file