"""Delete comment use case. This module implements the use case for deleting comments. Users can delete their own comments. """ from uuid import UUID from app.application.interfaces import TransactionManager from app.domain.exceptions import ForbiddenException, NotFoundException from app.domain.repositories import CommentRepository class DeleteCommentUseCase: """Use case for deleting a comment. Allows users to delete their own comments. Attributes: _comment_repo: Repository for comment data access. _tx_manager: Transaction manager for commit control. """ def __init__( self, comment_repo: CommentRepository, tx_manager: TransactionManager, ) -> None: """Initialize use case with dependencies. Args: comment_repo: Repository for comment operations. tx_manager: Transaction manager instance. """ self._comment_repo = comment_repo self._tx_manager = tx_manager async def execute( self, comment_id: UUID, user_id: str, ) -> None: """Delete a comment. Args: comment_id: UUID of the comment to delete. user_id: Identifier of the user requesting deletion. Raises: NotFoundException: If the comment does not exist. """ comment = await self._comment_repo.get_by_id(comment_id) if not comment: raise NotFoundException(f"Comment with id '{comment_id}' not found") if comment.author_id != user_id: raise ForbiddenException("You are not allowed to delete this comment") await self._comment_repo.delete(comment_id) await self._tx_manager.commit()