All checks were successful
ci/woodpecker/pr/pipeline Pipeline was successful
Implement full comments system: domain entities (Comment, CommentLike), value objects (CommentContent), use cases (CRUD, like toggle), SQLAlchemy repository, API v1 endpoints, web UI with comment form and nested replies, i18n translations (EN/RU/FR/DE), and E2E tests. Fix nested reply (reply-to-reply) not displaying — the flat reply_comments dict was only queried for top-level comment IDs, so deeply nested replies were saved to DB (incrementing comment count) but never rendered. Switch to a recursive Jinja2 macro that renders any nesting depth.
61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
"""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()
|