active_record_api-rest 1.0.18 → 1.0.19

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: 2f01a0f12a269874db175d06644de1761506e5196aca5e56ea8ef75f47322173
4
- data.tar.gz: 7b2ddf7670f178e15c3469131b7a03168861408c3fa61cb65af1138601fb5c01
3
+ metadata.gz: 9f7d5bdb3dba9f5d4da9bc806bfe5d3bce9d09149b419c74648481b18840621f
4
+ data.tar.gz: '09f75577ff7bc0275d4faea7ae57f9a7103582263702429073fd1217fb8e3636'
5
5
  SHA512:
6
- metadata.gz: 311522ba4552b5a9fa5b48a0fdf844d66f1fa4d298db893327f4a3a58607448d8c25bfe81f930391764f9ee1a0632392d94ccd41edcbb679726e47252eb00f7a
7
- data.tar.gz: c984599f0a0ea0d76b96e5528c878d593aef8d1a6e67e43cd655dd3ffd6b43d9d2a15158def15c32db02b84f1a2262aef9472e3ee242770abb92a875b7fd1337
6
+ metadata.gz: cdfd4c5a8f7b668dd78b24803aa2de4bcb69be77a3d23cf97a80e26b82b5385f779500f8c4a210a57d11716a7cec6901553d1e3054b25b64bc31cda2118779bb
7
+ data.tar.gz: af8af57d6ca48745d71cc4add6c32a272bdda6e24b63b34da7c3adec42a2ccfba8b0cb2dde90df0fe330b1777a08c244eeda3d7f7ed7afd4fe8ab3f1b7a92aee
data/README.md CHANGED
@@ -35,3 +35,10 @@ The gem is available as open source under the terms of the [MIT License](https:/
35
35
  ## Code of Conduct
36
36
 
37
37
  Everyone interacting in the Swagger::Api project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/swagger-api/blob/master/CODE_OF_CONDUCT.md).
38
+
39
+ ## Reverse proxy from nginx
40
+
41
+ add to nginx config this line
42
+ ```
43
+ proxy_set_header X-Real-Path $request_uri;
44
+ ```
@@ -8,9 +8,9 @@ module ActiveRecordApi
8
8
  before_action :validate_params
9
9
 
10
10
  def index
11
- response.headers['x-total'] = models.count
12
- response.headers['x-link-next'] = next_url
13
- render json: models, each_serializer: serializer
11
+ response.headers['x-total'] = @total
12
+ response.headers['x-link-next'] = next_url unless next_url.nil?
13
+ render json: models.limit(limit), each_serializer: serializer
14
14
  end
15
15
 
16
16
  def show
@@ -19,7 +19,7 @@ module ActiveRecordApi
19
19
 
20
20
  def create
21
21
  if model.save
22
- render json: model
22
+ redirect_to_model
23
23
  else
24
24
  render json: model.errors, status: :unprocessable_entity
25
25
  end
@@ -27,7 +27,7 @@ module ActiveRecordApi
27
27
 
28
28
  def update
29
29
  if model.update(modifiable_params)
30
- render json: model
30
+ redirect_to_model
31
31
  else
32
32
  render json: model.errors, status: :unprocessable_entity
33
33
  end
@@ -55,7 +55,8 @@ module ActiveRecordApi
55
55
 
56
56
  def models
57
57
  return @models unless @models.nil?
58
- @models = authorized_models.where(queryable_params)
58
+ @models = authorized_models.where(queryable_params).order(pagination_param_name => pagination_param_direction)
59
+ @total = @models.count
59
60
  return @models unless pagination_param_value.present?
60
61
  @models = @models&.where("\"#{pagination_param_name}\" > ?", pagination_param_value)
61
62
  end
@@ -76,6 +77,10 @@ module ActiveRecordApi
76
77
  @pagination_param_name ||= :id
77
78
  end
78
79
 
80
+ def pagination_param_direction
81
+ @pagination_param_direction ||= :asc # from params
82
+ end
83
+
79
84
  def pagination_param_value
80
85
  @pagination_param_value = params[pagination_param_name]
81
86
  end
@@ -99,6 +104,8 @@ module ActiveRecordApi
99
104
  action_name: action_name,
100
105
  request: request,
101
106
  models: models,
107
+ parameters: parameters,
108
+ total: @total,
102
109
  pagination_param_name: pagination_param_name
103
110
  )
104
111
  end
@@ -7,19 +7,26 @@ module ActiveRecordApi
7
7
  attribute :action_name
8
8
  attribute :models
9
9
  attribute :pagination_param_name
10
- delegate :host_with_port, :path, :query_params, to: :request
10
+ attribute :parameters
11
+ attribute :count
12
+ delegate :host_with_port, :path, :query_parameters, to: :request
13
+ delegate :limit, to: :parameters
11
14
 
12
15
  def next_url
13
- return if models.count == 0
14
- "#{current_url}?#{new_params}"
16
+ return if count == 0 || models.count <= limit
17
+ "#{current_url}?#{new_params.to_param}"
15
18
  end
16
19
 
17
20
  def new_params
18
- request.query_parameters.dup.merge(pagination_param_name.to_s => models.last.send(pagination_param_name))
21
+ query_parameters.dup.merge(pagination_param_name.to_s => models.limit(limit).last.send(pagination_param_name))
19
22
  end
20
23
 
21
24
  def current_url
22
- "#{protocol}#{host_with_port}#{path}"
25
+ "#{protocol}#{host_with_port}#{micro_service_prefix}#{path}"
26
+ end
27
+
28
+ def micro_service_prefix
29
+ request.headers['HTTP_X_REAL_PATH'].split(path).first if request.headers['HTTP_X_REAL_PATH'].present?
23
30
  end
24
31
 
25
32
  def protocol
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecordApi
4
4
  module Rest
5
- VERSION = '1.0.18'.freeze
5
+ VERSION = '1.0.19'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_api-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.18
4
+ version: 1.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Full Measure Education
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-16 00:00:00.000000000 Z
11
+ date: 2019-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler