rao-api-resources_controller 0.0.49.pre → 0.0.51.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7502d725f38fe2455137199dc9ae053918c5f94621ad475b26166290de74d3e6
4
- data.tar.gz: 201c4dc8a40768f51cc941998c140d043c333096884df865eee73d7f27e1b476
3
+ metadata.gz: f8f94143a580bd3b3177f3a92fead73d2514d673a97c99b1a043762acaf9203f
4
+ data.tar.gz: 699eb65047a5847c35d798cab2b2006719c36efd4bafaea04f749c116d6ba89d
5
5
  SHA512:
6
- metadata.gz: 5a59c63daf6e4b05bb82dd7f9ced2dcceb1faef3bf23fc709149944d43b8a4fd6500af38055ac20bfa4f54902808af81ea54a34663726d832ae119cc99e4434d
7
- data.tar.gz: 3571ce0c54415b95c17df3683e6437262885631f046965561774bbffcae8ee26803f8b94a673a7e5e8bc1d162f2352e3113c9afacfed6e1bea514300500c0cf1
6
+ metadata.gz: 4b2622caf380f817c5165cec750761684c008b272045b660b626c1dac49bddd0d5867352fac2599a98bc07891f92e1be9b5d6b9fd7bea676c3ca218c67f19721
7
+ data.tar.gz: d6154eb04c224f34def89b60f47e5306d971bf65e091b5133806ea727eb2a40266b7df1021ffc781257d1f1ac3b5a9a3dabab1e36429471ebd1a98fda24595aa
@@ -73,17 +73,24 @@ module Rao
73
73
 
74
74
  private
75
75
 
76
- def load_collection
77
- scope = if respond_to?(:with_conditions_from_query, true)
78
- scope = with_conditions_from_query(resource_class)
76
+ def load_collection_scope
77
+ if respond_to?(:with_conditions_from_query, true)
78
+ with_conditions_from_query(resource_class)
79
79
  else
80
80
  resource_class
81
81
  end
82
- @collection = scope.all
82
+ end
83
+
84
+ def load_collection
85
+ @collection = load_collection_scope.all
86
+ end
87
+
88
+ def load_resource_scope
89
+ resource_class
83
90
  end
84
91
 
85
92
  def load_resource
86
- @resource = resource_class.find(params[:id])
93
+ @resource = load_resource_scope.find(params[:id])
87
94
  end
88
95
 
89
96
  def load_resource_for_show
@@ -102,6 +109,10 @@ module Rao
102
109
  @resource = resource_class.new(permitted_params)
103
110
  end
104
111
 
112
+ def params
113
+ super.deep_transform_keys!(&:underscore)
114
+ end
115
+
105
116
  def permitted_params
106
117
  raise "not implemented"
107
118
  end
@@ -17,8 +17,8 @@ module Rao
17
17
  json
18
18
  end
19
19
 
20
- def serialize_errors(errors)
21
- errors.as_json(full_messages: true)
20
+ def serialize_errors(errors, full_messages: true)
21
+ errors.as_json(full_messages: full_messages)
22
22
  end
23
23
  end
24
24
  end
@@ -0,0 +1,30 @@
1
+ module Rao
2
+ module Api
3
+ module ResourcesController
4
+ module ValidationConcern
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ before_action :initialize_resource_for_validation, only: [:validate]
9
+ end
10
+
11
+ def validate
12
+ respond_to do |format|
13
+ if @resource.valid?
14
+ format.json { render json: { errors: serialize_errors(@resource.errors, full_messages: false) }, status: 200 }
15
+ # format.json { render json: serialize_resource(@resource), status: :created }
16
+ else
17
+ format.json { render json: { errors: serialize_errors(@resource.errors, full_messages: false) }, status: 422 }
18
+ end
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def initialize_resource_for_validation
25
+ initialize_resource_for_create
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rao-api-resources_controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.49.pre
4
+ version: 0.0.51.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Vasquez Angel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-11 00:00:00.000000000 Z
11
+ date: 2023-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -174,6 +174,7 @@ files:
174
174
  - app/concerns/rao/api/resources_controller/rest_actions_concern.rb
175
175
  - app/concerns/rao/api/resources_controller/serialization_concern.rb
176
176
  - app/concerns/rao/api/resources_controller/sorting_concern.rb
177
+ - app/concerns/rao/api/resources_controller/validation_concern.rb
177
178
  - app/controllers/rao/api/resource_controller/base.rb
178
179
  - app/controllers/rao/api/resources_controller/base.rb
179
180
  - config/locales/de.yml
@@ -205,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
206
  - !ruby/object:Gem::Version
206
207
  version: 1.3.1
207
208
  requirements: []
208
- rubygems_version: 3.4.11
209
+ rubygems_version: 3.4.21
209
210
  signing_key:
210
211
  specification_version: 4
211
212
  summary: API Resources Controller for Ruby on Rails.