forked from mtusi2026/mtusi2026lab4
Carry over lab3 HA stack and add private S3 storage, Attachment API, orphan compensation/reaper, own tests, and evidence for smoke/persistence/failover.
94 lines
2.1 KiB
Python
94 lines
2.1 KiB
Python
"""Доменные сущности."""
|
|
import uuid
|
|
from dataclasses import dataclass, field
|
|
from typing import List, Optional
|
|
|
|
|
|
@dataclass
|
|
class User:
|
|
id: str
|
|
username: str
|
|
display_name: str
|
|
created_at: str
|
|
password_hash: str = ""
|
|
|
|
def to_dict(self) -> dict:
|
|
return {
|
|
"id": self.id,
|
|
"username": self.username,
|
|
"display_name": self.display_name,
|
|
"created_at": self.created_at,
|
|
}
|
|
|
|
|
|
@dataclass
|
|
class Chat:
|
|
id: str
|
|
title: str
|
|
member_ids: List[str]
|
|
created_at: str
|
|
|
|
def to_dict(self) -> dict:
|
|
return {
|
|
"id": self.id,
|
|
"title": self.title,
|
|
"member_ids": list(self.member_ids),
|
|
"created_at": self.created_at,
|
|
}
|
|
|
|
|
|
@dataclass
|
|
class Message:
|
|
id: str
|
|
chat_id: str
|
|
sender_id: str
|
|
text: str
|
|
created_at: str
|
|
attachment_ids: List[str] = field(default_factory=list)
|
|
|
|
def to_dict(self) -> dict:
|
|
return {
|
|
"id": self.id,
|
|
"chat_id": self.chat_id,
|
|
"sender_id": self.sender_id,
|
|
"text": self.text,
|
|
"created_at": self.created_at,
|
|
"attachment_ids": list(self.attachment_ids),
|
|
}
|
|
|
|
def sort_key(self):
|
|
return (self.created_at, uuid.UUID(self.id).int)
|
|
|
|
|
|
@dataclass
|
|
class Attachment:
|
|
id: str
|
|
chat_id: str
|
|
owner_id: str
|
|
filename: str
|
|
content_type: str
|
|
size_bytes: int
|
|
sha256: str
|
|
object_key: str
|
|
status: str
|
|
created_at: str
|
|
updated_at: str
|
|
error_code: Optional[str] = None
|
|
variants: List[dict] = field(default_factory=list)
|
|
|
|
def to_dict(self) -> dict:
|
|
return {
|
|
"id": self.id,
|
|
"chat_id": self.chat_id,
|
|
"owner_id": self.owner_id,
|
|
"filename": self.filename,
|
|
"content_type": self.content_type,
|
|
"size_bytes": self.size_bytes,
|
|
"sha256": self.sha256,
|
|
"status": self.status,
|
|
"variants": list(self.variants),
|
|
"error_code": self.error_code,
|
|
"created_at": self.created_at,
|
|
"updated_at": self.updated_at,
|
|
}
|