Module: RapidApi::ActionController::ResourceActions

Extended by:
ActiveSupport::Concern
Includes:
Errors, FilterableParams, PermittedParams, Scope
Defined in:
lib/rapid_api/action_controller/resource_actions.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary

Constants included from Errors

Errors::NotAuthorizedError, Errors::NotFoundError

Instance Attribute Summary

Attributes included from Scope

#scope

Instance Method Summary collapse

Methods included from Scope

#define_scope

Methods included from Errors

#not_authorized!, #not_found!, #not_processable!

Methods included from FilterableParams

#filterable_params

Methods included from PermittedParams

#permitted_params

Instance Method Details

#createObject



31
32
33
34
35
36
37
38
39
# File 'lib/rapid_api/action_controller/resource_actions.rb', line 31

def create
  attributes   = _member_params
  query_result = _adapted_model.create attributes, scope
  if query_result.has_errors?
    not_processable! _adapted_serializer.serialize_errors(query_result)
  else
    render json: _adapted_serializer.serialize(query_result.data), status: response_code_for(:created)
  end
end

#destroyObject



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rapid_api/action_controller/resource_actions.rb', line 56

def destroy
  id           = _adapted_serializer.deserialize_id(params, _params_key)
  query_result = _adapted_model.destroy id, scope
  if query_result.found?
    if query_result.has_errors?
      not_processable! query_result.errors
    else
      head :no_content
    end
  else
    not_found!
  end
end

#find_memberObject



70
71
72
73
74
# File 'lib/rapid_api/action_controller/resource_actions.rb', line 70

def find_member
  id = _adapted_serializer.deserialize_id(params, _params_key)
  query_result = _adapted_model.find id, scope
  @member = query_result
end

#indexObject



16
17
18
19
# File 'lib/rapid_api/action_controller/resource_actions.rb', line 16

def index
  query_result = _adapted_model.find_all filterable_params.to_h, scope
  render json: _adapted_serializer.serialize_collection(query_result.data), status: response_code_for(:ok)
end

#render_member_ok(member) ⇒ Object



76
77
78
# File 'lib/rapid_api/action_controller/resource_actions.rb', line 76

def render_member_ok(member)
  render json: _adapted_serializer.serialize(member) , status: response_code_for(:ok)
end

#showObject



21
22
23
24
25
26
27
28
29
# File 'lib/rapid_api/action_controller/resource_actions.rb', line 21

def show
  id = _adapted_serializer.deserialize_id(params, _params_key)
  query_result = _adapted_model.find id, scope
  if query_result.found?
    render json: _adapted_serializer.serialize(query_result.data) , status: response_code_for(:ok)
  else
    not_found!
  end
end

#updateObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rapid_api/action_controller/resource_actions.rb', line 41

def update
  attributes   = _member_params
  id           = _adapted_serializer.deserialize_id(params, _params_key)
  query_result = _adapted_model.update id, attributes, scope
  if query_result.found?
    if query_result.has_errors?
      not_processable! _adapted_serializer.serialize_errors(query_result)
    else
      render json: _adapted_serializer.serialize(query_result.data), status: response_code_for(:ok)
    end
  else
    not_found!
  end
end