thecore_api 1.4.4 → 1.4.5

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: 77b761b925780fcc6028197f2bbb1cd181b0a4f65e59e59d7c3e44c49d075038
4
- data.tar.gz: 88559518468dcffe114a79d6a323a1f5b7ab0964d7036fbf09c14a6a37b719f1
3
+ metadata.gz: 425d080e2569d8b3c6a5890b26f03e5c50fdbf08fd387719b114af3d8d72ead4
4
+ data.tar.gz: 0def430ef68a0bae6f63fd3f8ed434b5111ae62bd246f79f38d44b5a0fce5576
5
5
  SHA512:
6
- metadata.gz: 36d00b25f1abc7c32e27008bb868b8e6da53af67c7539574650ea38a9ac3b41cf91cb924685c7543861130048437303e5c2ade9539d3e9476a65911c82ff8822
7
- data.tar.gz: 134a1e19be4ae5e2a5420e04b55b2638c7ff79c58507429bc6ae4c3501be208ab879249f8b3e22edc798c95a847f61982c60468e8b065738f4d6f503efcb6d0c
6
+ metadata.gz: ff82f98af88ed60a78e1c4996636a8074f0d95462d77dfad0c856f3c4cacb399324ee43c2007b35a9345fe9db5e6bd7475e568ea1045d4239661762e2314cb24
7
+ data.tar.gz: 209de01dbae0e5683609c75c19364f3f4149f370f98be9eeb21bf926de0772e909f194cd5e7f556f07088b9cf7989e581808a327266e5674762216ff978adcd3
@@ -22,7 +22,7 @@ class Api::V1::BaseController < ActionController::API
22
22
  before_action :destroy_session
23
23
 
24
24
  before_action :authenticate_user!
25
- before_action :find_model, except: [ :version, :available_roles, :translations, :schema ]
25
+ before_action :find_model#, except: [ :version, :available_roles, :translations, :schema ]
26
26
  before_action :find_record, only: [ :show, :update, :destroy ]
27
27
 
28
28
  rescue_from ActiveRecord::StatementInvalid, with: :unauthenticated!
@@ -152,7 +152,7 @@ class Api::V1::BaseController < ActionController::API
152
152
 
153
153
  def show
154
154
  result = @record.to_json(json_attrs)
155
- render json: result, status: result.blank? ? 404 : 200
155
+ render json: result, status: 200
156
156
  end
157
157
 
158
158
  def create
@@ -171,11 +171,9 @@ class Api::V1::BaseController < ActionController::API
171
171
  end
172
172
 
173
173
  def destroy
174
- unless @record.destroy
175
- return api_error(status: 500)
176
- end
177
-
178
- render json: {message: "Deleted"}, status: 200
174
+ return api_error(status: 500) unless @record.destroy
175
+ # render json: {message: "Deleted"}, status: 200
176
+ head :ok
179
177
  end
180
178
 
181
179
  protected
@@ -208,7 +206,7 @@ class Api::V1::BaseController < ActionController::API
208
206
 
209
207
  def api_error(status: 500, errors: [])
210
208
  # puts errors.full_messages if !Rails.env.production? && errors.respond_to?(:full_messages)
211
- head status: status && return if errors.empty?
209
+ head status && return if errors.empty?
212
210
 
213
211
  # For retrocompatibility, I try to send back only strings, as errors
214
212
  errors_response = if errors.respond_to?(:full_messages)
@@ -265,18 +263,17 @@ class Api::V1::BaseController < ActionController::API
265
263
  def find_record
266
264
  # find the records
267
265
  @record = @model.column_names.include?("user_id") ? @model.where(id: (@record_id.presence || params[:id]), user_id: current_user.id).first : @model.find((@record_id.presence || params[:id]))
266
+ return not_found! if @record.blank?
268
267
  end
269
268
 
270
269
  def find_model path=nil
271
270
  # Find the name of the model from controller
272
- path ||= params[:path]
273
- @singular_controller = (path.presence || controller_name).singularize.to_sym
274
- @model = (path.presence || controller_path).classify.constantize rescue controller_name.classify.constantize
271
+ path ||= params[:path].split("/").first
272
+ @model = (path.presence || controller_path).classify.constantize rescue controller_name.classify.constantize rescue nil
275
273
  end
276
274
 
277
275
  def request_params
278
- # controller_name.singularize.to_sym
279
- (@params.presence || params).require(@singular_controller).permit!
276
+ (@params.presence || params).require(params[:path].split("/").first.singularize.to_sym).permit!
280
277
  end
281
278
 
282
279
  def json_attrs
@@ -1,3 +1,3 @@
1
1
  module ThecoreApi
2
- VERSION = "1.4.4".freeze
2
+ VERSION = "1.4.5".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thecore_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.4
4
+ version: 1.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni