add storage foundation contracts
This commit is contained in:
parent
0ca0bac9bf
commit
5381c997e2
6 changed files with 208 additions and 0 deletions
35
domain/chat.py
Normal file
35
domain/chat.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
HISTORY_FILE_NAME = 'history.md'
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class ChatAttachmentName:
|
||||
value: str
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
if not self.value or self.value in {'.', '..'}:
|
||||
raise ValueError('invalid attachment name')
|
||||
if '/' in self.value or '\\' in self.value:
|
||||
raise ValueError('invalid attachment name')
|
||||
if self.value == HISTORY_FILE_NAME:
|
||||
raise ValueError('reserved attachment name')
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class Chat:
|
||||
chat_id: UUID
|
||||
workspace_id: UUID
|
||||
created_at: datetime
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class ChatFile:
|
||||
file_id: UUID
|
||||
chat_id: UUID
|
||||
name: ChatAttachmentName
|
||||
content_type: str | None
|
||||
size_bytes: int
|
||||
created_at: datetime
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
from uuid import UUID
|
||||
|
||||
|
||||
class DomainError(Exception):
|
||||
pass
|
||||
|
||||
|
|
@ -18,6 +21,48 @@ class UserConflictError(UserError):
|
|||
self.email = email
|
||||
|
||||
|
||||
class WorkspaceError(DomainError):
|
||||
pass
|
||||
|
||||
|
||||
class WorkspaceNotFoundError(WorkspaceError):
|
||||
def __init__(self, workspace_id: UUID) -> None:
|
||||
super().__init__('workspace_not_found')
|
||||
self.workspace_id = workspace_id
|
||||
|
||||
|
||||
class WorkspaceQuotaExceededError(WorkspaceError):
|
||||
def __init__(self, workspace_id: UUID) -> None:
|
||||
super().__init__('workspace_quota_exceeded')
|
||||
self.workspace_id = workspace_id
|
||||
|
||||
|
||||
class ChatError(DomainError):
|
||||
pass
|
||||
|
||||
|
||||
class ChatNotFoundError(ChatError):
|
||||
def __init__(self, chat_id: UUID) -> None:
|
||||
super().__init__('chat_not_found')
|
||||
self.chat_id = chat_id
|
||||
|
||||
|
||||
class ChatHasActiveSandboxError(ChatError):
|
||||
def __init__(self, chat_id: UUID) -> None:
|
||||
super().__init__('chat_has_active_sandbox')
|
||||
self.chat_id = chat_id
|
||||
|
||||
|
||||
class ChatFileError(DomainError):
|
||||
pass
|
||||
|
||||
|
||||
class ChatFileNotFoundError(ChatFileError):
|
||||
def __init__(self, file_id: UUID) -> None:
|
||||
super().__init__('chat_file_not_found')
|
||||
self.file_id = file_id
|
||||
|
||||
|
||||
class SandboxError(DomainError):
|
||||
pass
|
||||
|
||||
|
|
|
|||
17
domain/workspace.py
Normal file
17
domain/workspace.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class Workspace:
|
||||
workspace_id: UUID
|
||||
user_id: UUID
|
||||
created_at: datetime
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class WorkspaceUsage:
|
||||
workspace_id: UUID
|
||||
used_bytes: int
|
||||
quota_bytes: int
|
||||
Loading…
Add table
Add a link
Reference in a new issue