feat: add models and partially custom error messages

This commit is contained in:
firedotguy
2026-01-31 12:10:20 +03:00
parent c7e3812ee8
commit a388426d8d
15 changed files with 352 additions and 71 deletions

View File

@@ -6,7 +6,7 @@ from pydantic import BaseModel, Field
from itd.models.user import UserPost
class _TextObject(BaseModel):
class TextObject(BaseModel):
id: UUID
content: str
author: UserPost

6
itd/models/clan.py Normal file
View File

@@ -0,0 +1,6 @@
from pydantic import BaseModel, Field
class Clan(BaseModel):
avatar: str
member_count: int = Field(0, alias='memberCount')

View File

@@ -1,12 +1,9 @@
from uuid import UUID
from datetime import datetime
from pydantic import Field
from itd.models._text import _TextObject
from itd.models._text import TextObject
class CommentShort(_TextObject):
class CommentShort(TextObject):
likes_count: int = Field(0, alias='likesCount')
replies_count: int = Field(0, alias='repliesCount')
is_liked: bool = Field(False, alias='isLiked')

7
itd/models/pagination.py Normal file
View File

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

View File

@@ -1,10 +1,10 @@
from pydantic import Field
from itd.models.user import UserPost
from itd.models._text import _TextObject
from itd.models._text import TextObject
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')

View File

@@ -3,6 +3,25 @@ from datetime import datetime
from pydantic import BaseModel, Field
class UserPrivacy(BaseModel):
private: bool | None = Field(None, alias='isPrivate') # none for not me
wall_closed: bool = Field(False, alias='wallClosed')
model_config = {'populate_by_name': True}
class UserProfileUpdate(BaseModel):
id: UUID
username: str
display_name: str = Field(alias='displayName')
bio: str | None = None
updated_at: datetime | None = Field(None, alias='updatedAt')
model_config = {'populate_by_name': True}
class UserNotification(BaseModel):
id: UUID
username: str
@@ -16,22 +35,26 @@ class UserPost(UserNotification):
verified: bool = False
class UserSearch(UserPost):
class UserWhoToFollow(UserPost):
followers_count: int = Field(0, alias='followersCount')
class User(UserSearch):
class UserFollower(UserPost):
is_following: bool = Field(False, alias='isFollowing') # none for me
class UserSearch(UserFollower, UserWhoToFollow):
pass
class User(UserSearch, UserPrivacy):
banner: str | None = None
bio: str | None = None
pinned_post_id: UUID | None
private: bool | None = Field(None, alias='isPrivate') # none for not me
wall_closed: bool = Field(False, alias='wallClosed')
pinned_post_id: UUID | None = Field(None, alias='pinnedPostId')
following_count: int = Field(0, alias='followingCount')
posts_count: int = Field(0, alias='postsCount')
is_following: bool | None = Field(None, alias='isFollowing') # none for me
is_followed: bool | None = Field(None, alias='isFollowedBy') # none for me
created_at: datetime = Field(alias='createdAt')