Module: JSONAPI::ResourceActions
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveStorageSupport, CrudHelpers, FieldValidation, FilterValidation, IncludeValidation, Pagination, ResourceLoading, TypeValidation, Serialization
- Included in:
- BaseController
- Defined in:
- lib/json_api/controllers/concerns/resource_actions.rb,
lib/json_api/controllers/concerns/resource_actions/pagination.rb,
lib/json_api/controllers/concerns/resource_actions/crud_helpers.rb,
lib/json_api/controllers/concerns/resource_actions/serialization.rb,
lib/json_api/controllers/concerns/resource_actions/type_validation.rb,
lib/json_api/controllers/concerns/resource_actions/field_validation.rb,
lib/json_api/controllers/concerns/resource_actions/resource_loading.rb,
lib/json_api/controllers/concerns/resource_actions/filter_validation.rb,
lib/json_api/controllers/concerns/resource_actions/include_preloading.rb,
lib/json_api/controllers/concerns/resource_actions/include_validation.rb
Defined Under Namespace
Modules: CrudHelpers, FieldValidation, FilterValidation, IncludePreloading, IncludeValidation, Pagination, ResourceLoading, Serialization, TypeValidation
Instance Method Summary
collapse
#validate_resource_id!, #validate_resource_type!
#validate_include_param
#validate_fields_param, #validate_sort_param
#validate_filter_param
empty_filter_value?, parse_column_filter
#active_storage_attachment?, #append_only_enabled?, #attach_active_storage_files, #extract_active_storage_params_from_hash, #filter_active_storage_from_includes, #filter_polymorphic_from_includes, #find_blob_by_signed_id, #find_relationship_definition, #process_active_storage_attachment, #purge_on_nil_enabled?, #resolve_model_class_for_attachment, #serialize_active_storage_relationship, #serialize_blob_identifier
Instance Method Details
#build_resource_for_create ⇒ Object
60
61
62
63
64
|
# File 'lib/json_api/controllers/concerns/resource_actions.rb', line 60
def build_resource_for_create
sti_class = determine_sti_class
params_hash, @create_attachments = prepare_create_params(sti_class)
sti_class.new(params_hash)
end
|
#create ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/json_api/controllers/concerns/resource_actions.rb', line 49
def create
resource = build_resource_for_create
authorize_resource_action!(resource, action: :create)
attach_active_storage_files(resource, @create_attachments, resource_class: determine_sti_resource_class)
save_created(resource)
rescue ArgumentError => e
render_create_error(e)
rescue JSONAPI::Errors::ParameterNotAllowed, ActiveSupport::MessageVerifier::InvalidSignature => e
handle_create_exception(e)
end
|
#destroy ⇒ Object
85
86
87
88
89
90
|
# File 'lib/json_api/controllers/concerns/resource_actions.rb', line 85
def destroy
authorize_resource_action!(@resource, action: :destroy)
@resource.destroy
emit_resource_event(:deleted, @resource)
head :no_content
end
|
#handle_create_exception(error) ⇒ Object
66
67
68
69
70
71
|
# File 'lib/json_api/controllers/concerns/resource_actions.rb', line 66
def handle_create_exception(error)
case error
when JSONAPI::Errors::ParameterNotAllowed then render_parameter_not_allowed_error(error)
when ActiveSupport::MessageVerifier::InvalidSignature then render_signed_id_error(error)
end
end
|
#index ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/json_api/controllers/concerns/resource_actions.rb', line 36
def index
scope = apply_authorization_scope(@resource_class.records, action: :index)
query = build_query(scope)
@total_count = query.total_count
= query.
render json: serialize_collection(query.scope), status: :ok
end
|
#show ⇒ Object
44
45
46
47
|
# File 'lib/json_api/controllers/concerns/resource_actions.rb', line 44
def show
authorize_resource_action!(@resource, action: :show)
render json: serialize_resource(@resource), status: :ok
end
|
#update ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/json_api/controllers/concerns/resource_actions.rb', line 73
def update
authorize_resource_action!(@resource, action: :update)
params_hash, attachments = prepare_update_params
save_updated(params_hash, attachments)
rescue ArgumentError => e
render_invalid_relationship_error(e)
rescue JSONAPI::Errors::ParameterNotAllowed => e
render_parameter_not_allowed_error(e)
rescue ActiveSupport::MessageVerifier::InvalidSignature => e
render_signed_id_error(e)
end
|