Class: Collavre::Comments::SnapshotsController

Inherits:
ApplicationController show all
Includes:
CommentScoping
Defined in:
app/controllers/collavre/comments/snapshots_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject

GET /creatives/:creative_id/comments/snapshots



12
13
14
15
16
17
18
# File 'app/controllers/collavre/comments/snapshots_controller.rb', line 12

def index
  snapshots = @creative.comment_snapshots
    .restorable
    .order(created_at: :desc)

  render json: snapshots.map { |s| snapshot_json(s) }
end

#restoreObject

POST /creatives/:creative_id/comments/snapshots/:id/restore



21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/collavre/comments/snapshots_controller.rb', line 21

def restore
  service = CommentSnapshotRestoreService.new(snapshot: @snapshot, user: Current.user)
  recreated = service.call
  render json: {
    message: I18n.t("collavre.comment_snapshots.restored"),
    count: recreated.size
  }
rescue CommentSnapshotRestoreService::RestoreError => e
  render json: { error: e.message }, status: :unprocessable_entity
end