rao-api-resources_controller 0.0.49.pre → 0.0.50.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: e51753ea3bc71fb2b7922f4797f44866b73458ed4c6aa10c3ab425e85362950b
4
+ data.tar.gz: 76a1ddc7c9522381e82745fa010c1a622aba6ebc41152004908c564a72bd6bae
5
5
  SHA512:
6
- metadata.gz: 5a59c63daf6e4b05bb82dd7f9ced2dcceb1faef3bf23fc709149944d43b8a4fd6500af38055ac20bfa4f54902808af81ea54a34663726d832ae119cc99e4434d
7
- data.tar.gz: 3571ce0c54415b95c17df3683e6437262885631f046965561774bbffcae8ee26803f8b94a673a7e5e8bc1d162f2352e3113c9afacfed6e1bea514300500c0cf1
6
+ metadata.gz: 0f657f1639bcc4960bd5639913b025b87bb9665593fa8bc55fa5875739b83701f2fff9b3f7fd1105b9db88332b5cf77b1292b9cc753377dbff96466e2e905016
7
+ data.tar.gz: 619a871ff4c23783c93a149dbda62f98b901956f9d685670a6ef1971461bcea5c16aa5d1d06159cc9f60571b804f08731954fd79933bc2e469610f3de8a641f1
@@ -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.50.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-16 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.20
209
210
  signing_key:
210
211
  specification_version: 4
211
212
  summary: API Resources Controller for Ruby on Rails.