feat(lab5): async image processing with RabbitMQ, transactional outbox, and crash recovery
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
from pydantic import BaseModel, Field, ConfigDict, model_validator
|
||||
from typing import List, Optional
|
||||
from datetime import datetime
|
||||
|
||||
class User(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
id: str
|
||||
username: str
|
||||
display_name: str
|
||||
created_at: str
|
||||
|
||||
class CreateUser(BaseModel):
|
||||
username: str = Field(..., min_length=3, max_length=32, pattern="^[a-z0-9_]+$")
|
||||
display_name: str = Field(..., min_length=1, max_length=100)
|
||||
password: str = Field(..., min_length=12, max_length=128)
|
||||
|
||||
class Session(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
token: str
|
||||
token_type: str
|
||||
expires_at: datetime
|
||||
user: User
|
||||
|
||||
class Chat(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
id: str
|
||||
title: str
|
||||
member_ids: List[str]
|
||||
created_at: str
|
||||
|
||||
class CreateChat(BaseModel):
|
||||
title: str = Field(..., min_length=1, max_length=100)
|
||||
member_ids: List[str]
|
||||
|
||||
class ChatPage(BaseModel):
|
||||
items: List[Chat]
|
||||
next_cursor: Optional[str] = None
|
||||
|
||||
class Message(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
id: str
|
||||
chat_id: str
|
||||
sender_id: str
|
||||
text: str
|
||||
created_at: str
|
||||
attachment_ids: List[str]
|
||||
|
||||
class CreateMessage(BaseModel):
|
||||
text: str = Field(default="", max_length=4000)
|
||||
attachment_ids: List[str] = Field(default_factory=list)
|
||||
|
||||
@model_validator(mode='after')
|
||||
def check_text_or_attachments(self):
|
||||
if len(self.text) == 0 and len(self.attachment_ids) == 0:
|
||||
raise ValueError("Either text or attachment_ids must be provided")
|
||||
if len(self.attachment_ids) > 10:
|
||||
raise ValueError("attachment_ids cannot exceed 10 items")
|
||||
return self
|
||||
|
||||
class MessagePage(BaseModel):
|
||||
items: List[Message]
|
||||
next_cursor: Optional[str] = None
|
||||
|
||||
class Variant(BaseModel):
|
||||
name: str
|
||||
content_type: str
|
||||
size_bytes: int
|
||||
width: int
|
||||
height: int
|
||||
sha256: str
|
||||
|
||||
class Attachment(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
id: str
|
||||
chat_id: str
|
||||
owner_id: str
|
||||
filename: str
|
||||
content_type: str
|
||||
size_bytes: int
|
||||
sha256: str
|
||||
status: str
|
||||
variants: List[Variant]
|
||||
error_code: Optional[str] = None
|
||||
created_at: str
|
||||
updated_at: str
|
||||
|
||||
class ErrorResponse(BaseModel):
|
||||
error: dict
|
||||
Reference in New Issue
Block a user