"""List comments use case. This module implements the use case for listing comments on a blog post. """ from uuid import UUID from app.application.dtos.comment import CommentResponseDTO from app.domain.entities.comment import Comment from app.domain.repositories import CommentRepository class ListCommentsUseCase: """Use case for listing comments on a blog post. Retrieves all comments for a given post ordered by creation time. Attributes: _comment_repo: Repository for comment data access. """ def __init__( self, comment_repo: CommentRepository, ) -> None: """Initialize use case with dependencies. Args: comment_repo: Repository for comment operations. """ self._comment_repo = comment_repo async def execute(self, post_id: UUID) -> list[CommentResponseDTO]: """List all comments for a post. Args: post_id: UUID of the post. Returns: List of CommentResponseDTO for the post. """ comments = await self._comment_repo.get_by_post(post_id) return [self._map_to_dto(c) for c in comments] def _map_to_dto(self, comment: Comment) -> CommentResponseDTO: """Map domain entity to response DTO. Args: comment: Domain Comment entity. Returns: CommentResponseDTO with all comment attributes. """ return CommentResponseDTO( id=comment.id, post_id=comment.post_id, author_id=comment.author_id, content=comment.content.value, parent_id=comment.parent_id, like_count=comment.like_count, created_at=comment.created_at, updated_at=comment.updated_at, )