Class: EventCapture::EventsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/event_capture/events_controller.rb

Overview

Provide event creation.

Instance Method Summary collapse

Instance Method Details

#createObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/event_capture/events_controller.rb', line 4

def create
  @event = Event.create!(event_params)

  render json: {
    id: @event.id,
    emittedAt: @event.emitted_at,
    recordedAt: @event.recorded_at,
    payload: @event.payload,
    userId: @event.user_id,
    userAgent: @event.user_agent,
    source: @event.source,
    kind: @event.kind
  }, status: :created

rescue ActiveRecord::ActiveRecordError => invalid
  render json: { error: model_errors(invalid.record) },
         status: :bad_request
end