active_record_api-rest 1.0.19 → 1.0.20
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 164c784fae2fd7add5d47ffc1f6b31bfcc61d66dda43cd5b2bec8273421b8d0a
|
4
|
+
data.tar.gz: c1770286f9925be1005f2a1a1bd1237b7f1cba453a93f5a28d755f0386471466
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07def8142c96d536e7219d59d1514075fd284f856560cb0064053515f410573c4c1eb9eafc8179e27644cc9d566cf043e8f78b4a92ceac2e6f22188a7e56f000
|
7
|
+
data.tar.gz: fd8a436fcc2a0471a2ba6624925304a02ff82a52cc71923091c4e1eed63e4ab7da820371729909a9418d2d8e7e6e812de6ab934817dc6bb539fc794378a7b8a3
|
@@ -8,9 +8,9 @@ module ActiveRecordApi
|
|
8
8
|
before_action :validate_params
|
9
9
|
|
10
10
|
def index
|
11
|
-
response.headers['x-total'] =
|
11
|
+
response.headers['x-total'] = models_count
|
12
12
|
response.headers['x-link-next'] = next_url unless next_url.nil?
|
13
|
-
render json:
|
13
|
+
render json: models_remaining.limit(limit), each_serializer: serializer
|
14
14
|
end
|
15
15
|
|
16
16
|
def show
|
@@ -53,12 +53,19 @@ module ActiveRecordApi
|
|
53
53
|
@model ||= authorized_models.find_by(id: queryable_params[:id])
|
54
54
|
end
|
55
55
|
|
56
|
-
def
|
57
|
-
return @
|
58
|
-
@
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
def models_full_results
|
57
|
+
return @models_full_results unless @models_full_results.nil?
|
58
|
+
@models_full_results = authorized_models.where(queryable_params).order(pagination_param_name => pagination_param_direction)
|
59
|
+
end
|
60
|
+
|
61
|
+
def models_count
|
62
|
+
@total = models_full_results.count
|
63
|
+
end
|
64
|
+
|
65
|
+
def models_remaining
|
66
|
+
return @models_remaining unless @models_remaining.nil?
|
67
|
+
@models_remaining = models_full_results&.where("\"#{pagination_param_name}\" > ?", pagination_param_value) if pagination_param_value.present?
|
68
|
+
@models_remaining
|
62
69
|
end
|
63
70
|
|
64
71
|
def initialize_model
|
@@ -103,9 +110,9 @@ module ActiveRecordApi
|
|
103
110
|
RequestUrlGenerator.new(
|
104
111
|
action_name: action_name,
|
105
112
|
request: request,
|
106
|
-
|
113
|
+
models_remaining: models_remaining,
|
107
114
|
parameters: parameters,
|
108
|
-
|
115
|
+
total_count: models_count,
|
109
116
|
pagination_param_name: pagination_param_name
|
110
117
|
)
|
111
118
|
end
|
@@ -5,20 +5,20 @@ module ActiveRecordApi
|
|
5
5
|
include ActiveAttr::Model
|
6
6
|
attribute :request
|
7
7
|
attribute :action_name
|
8
|
-
attribute :
|
8
|
+
attribute :models_remaining
|
9
9
|
attribute :pagination_param_name
|
10
10
|
attribute :parameters
|
11
|
-
attribute :
|
11
|
+
attribute :total_count
|
12
12
|
delegate :host_with_port, :path, :query_parameters, to: :request
|
13
13
|
delegate :limit, to: :parameters
|
14
14
|
|
15
15
|
def next_url
|
16
|
-
return if
|
16
|
+
return if total_count == 0 || models_remaining.count <= limit
|
17
17
|
"#{current_url}?#{new_params.to_param}"
|
18
18
|
end
|
19
19
|
|
20
20
|
def new_params
|
21
|
-
query_parameters.dup.merge(pagination_param_name.to_s =>
|
21
|
+
query_parameters.dup.merge(pagination_param_name.to_s => models_remaining.limit(limit).last.send(pagination_param_name))
|
22
22
|
end
|
23
23
|
|
24
24
|
def current_url
|