Complete architectural refactoring from simple MVC to Clean Architecture/DDD pattern: Domain Layer: - Add entities (Post, BaseEntity) with business logic - Add value objects (Title, Content, Slug) with validation - Add repository interfaces (PostRepository) - Add domain exceptions Application Layer: - Add use cases (CreatePost, GetPost, UpdatePost, DeletePost, ListPosts, PublishPost) - Add DTOs for data transfer - Add TransactionManager interface Infrastructure Layer: - Add SQLAlchemy models and async database connection - Add SQLAlchemyPostRepository implementation - Add Dishka DI container with providers - Add error handlers and middleware Presentation Layer: - Add FastAPI routes with Dishka integration - Add Pydantic schemas - Add dependency injection using FromDishka[T] Other Changes: - Remove old flat structure (api/, common/, core/, modules/) - Add hatchling build system for package scripts - Add blog CLI command - Update AGENTS.md with new architecture docs - All 48 tests passing, mypy clean, ruff clean
24 lines
790 B
Python
24 lines
790 B
Python
"""Content value object."""
|
|
|
|
from dataclasses import dataclass
|
|
|
|
from app.domain.value_objects.base import ValueObject
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class Content(ValueObject[str]):
|
|
"""Blog post content value object."""
|
|
|
|
MIN_LENGTH: int = 10
|
|
MAX_LENGTH: int = 50000
|
|
|
|
def _validate(self) -> None:
|
|
if not isinstance(self.value, str):
|
|
raise ValueError("Content must be a string")
|
|
if not self.value.strip():
|
|
raise ValueError("Content cannot be empty or whitespace")
|
|
if len(self.value) < self.MIN_LENGTH:
|
|
raise ValueError(f"Content must be at least {self.MIN_LENGTH} characters")
|
|
if len(self.value) > self.MAX_LENGTH:
|
|
raise ValueError(f"Content must be at most {self.MAX_LENGTH} characters")
|