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



58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/forest_liana/associations_controller.rb', line 58

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

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

#countObject



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

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

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

#dissociateObject



71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/forest_liana/associations_controller.rb', line 71

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
25
# 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_REPORTER.report error
    FOREST_LOGGER.error "Association Index error: #{error}\n#{format_stacktrace(error)}"
    internal_server_error
  end
end

#updateObject



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

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_REPORTER.report error
    FOREST_LOGGER.error "Association Update error: #{error}\n#{format_stacktrace(error)}"
    internal_server_error
  end
end