feat: add models part 3

This commit is contained in:
firedotguy
2026-02-01 17:20:37 +03:00
parent 2a9f7da9a9
commit ba78457de5
13 changed files with 267 additions and 78 deletions

View File

@@ -3,15 +3,10 @@ from datetime import datetime
from pydantic import BaseModel, Field, field_validator
from itd.models.user import UserPost
from itd.models.file import Attach
class TextObject(BaseModel):
id: UUID
content: str
author: UserPost
attachments: list[Attach] = []
created_at: datetime = Field(alias='createdAt')

View File

@@ -2,12 +2,16 @@ from pydantic import Field
from itd.models._text import TextObject
from itd.models.user import UserPost
from itd.models.file import Attach
class Comment(TextObject):
author: UserPost
likes_count: int = Field(0, alias='likesCount')
replies_count: int = Field(0, alias='repliesCount')
is_liked: bool = Field(False, alias='isLiked')
attachments: list[Attach] = []
replies: list['Comment'] = []
reply_to: UserPost | None = None # author of replied comment, if this comment is reply

View File

@@ -12,15 +12,18 @@ class File(BaseModel):
size: int
class Attach(BaseModel):
class PostAttach(BaseModel):
id: UUID
type: AttachType = AttachType.IMAGE
url: str
thumbnail_url: str | None = Field(None, alias='thumbnailUrl')
width: int | None = None
height: int | None = None
class Attach(PostAttach):
filename: str
mime_type: str = Field(alias='mimeType')
size: int
width: int | None = None
height: int | None = None
duration: int | None = None
order: int = 0

View File

@@ -11,7 +11,7 @@ class Notification(BaseModel):
type: NotificationType
target_type: NotificationTargetType | None = Field(None, alias='targetType') # none - follows, other - NotificationTragetType.POST
target_id: int | None = Field(None, alias='targetId') # none - follows
target_id: UUID | None = Field(None, alias='targetId') # none - follows
preview: str | None = None # follow - none, comment/reply - content, repost - original post content, like - post content, wall_post - wall post content

View File

@@ -1,7 +1,10 @@
from uuid import UUID
from pydantic import BaseModel, Field
class Pagination(BaseModel):
page: int = 1
page: int | None = 1
limit: int = 20
total: int | None = None
has_more: bool = Field(True, alias='hasMore')
has_more: bool = Field(True, alias='hasMore')
next_cursor: UUID | None = Field(None, alias='nextCursor')

View File

@@ -1,29 +1,47 @@
from uuid import UUID
from pydantic import Field
from itd.models.user import UserPost
from itd.models.user import UserPost, UserNewPost
from itd.models._text import TextObject
from itd.models.file import PostAttach
from itd.models.comment import Comment
class PostShort(TextObject):
class _PostShort(TextObject):
likes_count: int = Field(0, alias='likesCount')
comments_count: int = Field(0, alias='commentsCount')
reposts_count: int = Field(0, alias='repostsCount')
views_count: int = Field(0, alias='viewsCount')
class PostShort(_PostShort):
author: UserPost
class OriginalPost(PostShort):
is_deleted: bool = Field(False, alias='isDeleted')
class Post(PostShort):
class _Post(_PostShort):
is_liked: bool = Field(False, alias='isLiked')
is_reposted: bool = Field(False, alias='isReposted')
is_viewed: bool = Field(False, alias='isViewed')
is_owner: bool = Field(False, alias='isOwner')
comments: list = []
attachments: list[PostAttach] = []
comments: list[Comment] = []
original_post: OriginalPost | None = None
wall_recipient_id: int | None = None
wall_recipient: UserPost | None = None
wall_recipient_id: UUID | None = Field(None, alias='wallRecipientId')
wall_recipient: UserPost | None = Field(None, alias='wallRecipient')
class Post(_Post, PostShort):
pass
class NewPost(_Post):
author: UserNewPost

View File

@@ -19,22 +19,23 @@ class UserProfileUpdate(BaseModel):
updated_at: datetime | None = Field(None, alias='updatedAt')
model_config = {'populate_by_name': True}
class UserNotification(BaseModel):
id: UUID
class UserNewPost(BaseModel):
username: str | None = None
display_name: str = Field(alias='displayName')
avatar: str
model_config = {'populate_by_name': True}
class UserPost(UserNotification):
verified: bool = False
class UserNotification(UserNewPost):
id: UUID
class UserPost(UserNotification, UserNewPost):
pass
class UserWhoToFollow(UserPost):
followers_count: int = Field(0, alias='followersCount')