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
35 lines
942 B
Python
35 lines
942 B
Python
"""API dependencies using Dishka."""
|
|
|
|
from typing import Annotated
|
|
|
|
from dishka.integrations.fastapi import FromDishka
|
|
from fastapi import Depends, Header
|
|
|
|
from app.application import (
|
|
CreatePostUseCase,
|
|
DeletePostUseCase,
|
|
GetPostUseCase,
|
|
ListPostsUseCase,
|
|
PublishPostUseCase,
|
|
UpdatePostUseCase,
|
|
)
|
|
|
|
# Use case dependencies - injected via Dishka
|
|
CreatePostDep = FromDishka[CreatePostUseCase]
|
|
GetPostDep = FromDishka[GetPostUseCase]
|
|
UpdatePostDep = FromDishka[UpdatePostUseCase]
|
|
DeletePostDep = FromDishka[DeletePostUseCase]
|
|
ListPostsDep = FromDishka[ListPostsUseCase]
|
|
PublishPostDep = FromDishka[PublishPostUseCase]
|
|
|
|
|
|
# Mock current user dependency (replace with real auth)
|
|
async def get_current_user_id(
|
|
x_user_id: Annotated[str | None, Header()] = "user-123",
|
|
) -> str:
|
|
"""Get current user ID from header."""
|
|
return x_user_id or "user-123"
|
|
|
|
|
|
CurrentUserDep = Annotated[str, Depends(get_current_user_id)]
|