Class: Collavre::CommentMoveService
- Inherits:
-
Object
- Object
- Collavre::CommentMoveService
- Defined in:
- app/services/collavre/comment_move_service.rb
Defined Under Namespace
Classes: MoveError
Instance Method Summary collapse
-
#call(comment_ids:, target_creative_id: nil, target_topic_id: nil) ⇒ Object
Returns { success: true, moved_count: N } Raises MoveError on validation failures.
-
#initialize(creative:, user:) ⇒ CommentMoveService
constructor
A new instance of CommentMoveService.
Constructor Details
#initialize(creative:, user:) ⇒ CommentMoveService
Returns a new instance of CommentMoveService.
5 6 7 8 |
# File 'app/services/collavre/comment_move_service.rb', line 5 def initialize(creative:, user:) @creative = creative @user = user end |
Instance Method Details
#call(comment_ids:, target_creative_id: nil, target_topic_id: nil) ⇒ Object
Returns { success: true, moved_count: N } Raises MoveError on validation failures
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/services/collavre/comment_move_service.rb', line 12 def call(comment_ids:, target_creative_id: nil, target_topic_id: nil) comment_ids = Array(comment_ids).map(&:presence).compact.map(&:to_i) raise MoveError, I18n.t("collavre.comments.move_no_selection") if comment_ids.empty? target_origin, new_topic_id = resolve_target(target_creative_id, target_topic_id) (target_origin) comments = fetch_visible_comments(comment_ids) moved_count = perform_move(comments, target_origin, new_topic_id) Comment.broadcast_badges(@creative) Comment.broadcast_badges(target_origin) unless target_origin == @creative { success: true, moved_count: moved_count } end |