Class: ForestLiana::AssociationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/forest_liana/associations_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_user_from_jwt, #forest_user, #internal_server_error, papertrail?, #serialize_model, #serialize_models

Methods inherited from BaseController

#route_not_found

Instance Method Details

#associateObject


55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/forest_liana/associations_controller.rb', line 55

def associate
  begin
    associator = HasManyAssociator.new(@resource, @association, params)
    associator.perform

    head :no_content
  rescue => error
    FOREST_LOGGER.error "Association Associate error: #{error}\n#{format_stacktrace(error)}"
    internal_server_error
  end
end

#countObject


26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/forest_liana/associations_controller.rb', line 26

def count
  begin
    getter = HasManyGetter.new(@resource, @association, params, forest_user)
    getter.count

    render serializer: nil, json: { count: getter.records_count }
  rescue => error
    FOREST_LOGGER.error "Association Index Count error: #{error}\n#{format_stacktrace(error)}"
    internal_server_error
  end
end

#dissociateObject


67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/forest_liana/associations_controller.rb', line 67

def dissociate
  begin
    dissociator = HasManyDissociator.new(@resource, @association, params)
    dissociator.perform

    head :no_content
  rescue => error
    FOREST_LOGGER.error "Association Associate error: #{error}\n#{format_stacktrace(error)}"
    internal_server_error
  end
end

#indexObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/forest_liana/associations_controller.rb', line 11

def index
  begin
    getter = HasManyGetter.new(@resource, @association, params, forest_user)
    getter.perform

    respond_to do |format|
      format.json { render_jsonapi(getter) }
      format.csv { render_csv(getter, @association.klass) }
    end
  rescue => error
    FOREST_LOGGER.error "Association Index error: #{error}\n#{format_stacktrace(error)}"
    internal_server_error
  end
end

#updateObject


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/forest_liana/associations_controller.rb', line 38

def update
  begin
    updater = BelongsToUpdater.new(@resource, @association, params)
    updater.perform

    if updater.errors
      render serializer: nil, json: ForestAdmin::JSONAPI::Serializer.serialize_errors(
        updater.errors), status: 422
    else
      head :no_content
    end
  rescue => error
    FOREST_LOGGER.error "Association Update error: #{error}\n#{format_stacktrace(error)}"
    internal_server_error
  end
end