Sha256: 31ce5e927bda8a1660b70db489b56b81065e9ea0cde549745147013e87e99529

Contents?: true

Size: 1.57 KB

Versions: 27

Compression:

Stored size: 1.57 KB

Contents

# <%= autogenerated_event_warning %>

module LiveEvents
  class SubmissionEvent < LiveEvents::BaseEvent
    # The following is provided in the live events call:
    # {
    #     submission_id: submission.global_id,
    #     assignment_id: submission.global_assignment_id,
    #     user_id: submission.global_user_id,
    #     submitted_at: submission.submitted_at,
    #     graded_at: submission.graded_at,
    #     updated_at: submission.updated_at,
    #     score: submission.score,
    #     grade: submission.grade,
    #     submission_type: submission.submission_type,
    #     body: LiveEvents.truncate(submission.body),
    #     url: submission.url,
    #     attempt: submission.attempt
    # }

    def perform(event_payload)
      super
      return if assignment.nil? || user.nil?
      attrs = {
        canvas_submission_id: local_canvas_id(payload[:submission_id]),
        canvas_assignment_id: assignment.try(:id),
        canvas_user_id: user.try(:id),
        submitted_at: payload[:submitted_at],
        graded_at: payload[:graded_at],
        score: payload[:score],
      }
      create_or_update(attrs)
    end
  end

  private

  def create_or_update(attrs)
    submission = Submission.where(canvas_submission_id: attrs[:canvas_submission_id]).first_or_initialize
    submission.assign_attributes(attrs)
    submission.save!
    submission
  end

  def assignment
    @assignment ||= Assignment.find_by(canvas_assignment_id: local_canvas_id(payload[:assignment_id]))
  end

  def user
    @user ||= User.find_by(canvas_user_id: local_canvas_id(payload[:user_id]))
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
canvas_sync-0.10.2 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.10.0 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.9.4 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.9.3 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.9.2 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.9.1 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.9.0 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.8.4 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.8.3 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.8.2 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.8.1 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.8.0 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.7.3 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.7.2 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.7.1 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.7.0 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.6.4 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.6.3 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.6.2 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb
canvas_sync-0.6.1 lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb