feat: add models part 2
This commit is contained in:
@@ -1,17 +1,26 @@
|
||||
from uuid import UUID
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
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[UUID]
|
||||
attachments: list[Attach] = []
|
||||
|
||||
created_at: datetime = Field(alias='createdAt')
|
||||
|
||||
model_config = {'populate_by_name': True}
|
||||
model_config = {'populate_by_name': True}
|
||||
|
||||
@field_validator('created_at', mode='plain')
|
||||
@classmethod
|
||||
def validate_created_at(cls, v: str):
|
||||
try:
|
||||
return datetime.strptime(v + '00', '%Y-%m-%d %H:%M:%S.%f%z')
|
||||
except ValueError:
|
||||
return datetime.strptime(v, '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||
@@ -1,11 +1,13 @@
|
||||
from pydantic import Field
|
||||
|
||||
from itd.models._text import TextObject
|
||||
from itd.models.user import UserPost
|
||||
|
||||
|
||||
class CommentShort(TextObject):
|
||||
class Comment(TextObject):
|
||||
likes_count: int = Field(0, alias='likesCount')
|
||||
replies_count: int = Field(0, alias='repliesCount')
|
||||
is_liked: bool = Field(False, alias='isLiked')
|
||||
|
||||
replies: list['CommentShort'] = []
|
||||
replies: list['Comment'] = []
|
||||
reply_to: UserPost | None = None # author of replied comment, if this comment is reply
|
||||
@@ -2,9 +2,25 @@ from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from itd.enums import AttachType
|
||||
|
||||
class File(BaseModel):
|
||||
id: UUID
|
||||
url: str
|
||||
filename: str
|
||||
mime_type: str = Field('image/png', alias='mimeType')
|
||||
size: int
|
||||
size: int
|
||||
|
||||
|
||||
class Attach(BaseModel):
|
||||
id: UUID
|
||||
type: AttachType = AttachType.IMAGE
|
||||
url: str
|
||||
thumbnail_url: str | None = Field(None, alias='thumbnailUrl')
|
||||
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
|
||||
@@ -13,7 +13,7 @@ class UserPrivacy(BaseModel):
|
||||
|
||||
class UserProfileUpdate(BaseModel):
|
||||
id: UUID
|
||||
username: str
|
||||
username: str | None = None
|
||||
display_name: str = Field(alias='displayName')
|
||||
bio: str | None = None
|
||||
|
||||
@@ -24,7 +24,7 @@ class UserProfileUpdate(BaseModel):
|
||||
|
||||
class UserNotification(BaseModel):
|
||||
id: UUID
|
||||
username: str
|
||||
username: str | None = None
|
||||
display_name: str = Field(alias='displayName')
|
||||
avatar: str
|
||||
|
||||
|
||||
Reference in New Issue
Block a user