thecore_api 1.4.4 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/api/v1/base_controller.rb +10 -13
- data/lib/thecore_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 425d080e2569d8b3c6a5890b26f03e5c50fdbf08fd387719b114af3d8d72ead4
|
4
|
+
data.tar.gz: 0def430ef68a0bae6f63fd3f8ed434b5111ae62bd246f79f38d44b5a0fce5576
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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:
|
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
|
-
|
176
|
-
|
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
|
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
|
-
@
|
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
|
-
|
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
|
data/lib/thecore_api/version.rb
CHANGED