Class: Motor::NotesController

Inherits:
ApiBaseController show all
Defined in:
app/controllers/motor/notes_controller.rb

Instance Method Summary collapse

Methods included from CurrentAbility

#current_ability

Methods included from CurrentUserMethod

#current_user

Instance Method Details

#createObject



21
22
23
24
25
26
# File 'app/controllers/motor/notes_controller.rb', line 21

def create
  Motor::Notes::Persist.call(@note, current_user)
  Motor::NotifyNoteMentionsJob.perform_later(@note, current_user)

  render json: { data: Motor::ApiQuery::BuildJson.call(@note, params, current_ability) }
end

#destroyObject



37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/motor/notes_controller.rb', line 37

def destroy
  @note.update!(deleted_at: Time.current)

  Motor::NotesChannel.broadcast_to(
    @note.values_at(:record_type, :record_id).join(':'),
    ['remove', @note.as_json(only: %i[id body created_at updated_at])]
  )

  head :ok
end

#indexObject



11
12
13
14
15
# File 'app/controllers/motor/notes_controller.rb', line 11

def index
  @notes = Motor::ApiQuery.call(@notes.active.order(created_at: :asc), params)

  render json: { data: Motor::ApiQuery::BuildJson.call(@notes, params, current_ability) }
end

#showObject



17
18
19
# File 'app/controllers/motor/notes_controller.rb', line 17

def show
  render json: { data: Motor::ApiQuery::BuildJson.call(@note, params, current_ability) }
end

#updateObject



28
29
30
31
32
33
34
35
# File 'app/controllers/motor/notes_controller.rb', line 28

def update
  @note.assign_attributes(note_params)

  Motor::Notes::Persist.call(@note, current_user)
  Motor::NotifyNoteMentionsJob.perform_later(@note, current_user)

  render json: { data: Motor::ApiQuery::BuildJson.call(@note, params, current_ability) }
end