Commit 69d3de3017c3f5bcd4a6297716be3cf2753cc92b
1 parent
fa43ac7e
Exists in
api_pagination
Add timestamp in API
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>
Showing
1 changed file
with
13 additions
and
1 deletions
Show diff stats
lib/noosfero/api/helpers.rb
... | ... | @@ -140,6 +140,17 @@ module Noosfero |
140 | 140 | params[:per_page].to_i |
141 | 141 | end |
142 | 142 | |
143 | + def make_timestamp_with_parameters_and_method(params, method) | |
144 | + timestamp = nil | |
145 | + if params[:timestamp] | |
146 | + datetime = DateTime.parse(params[:timestamp]) | |
147 | + table_name = method.to_s.singularize.camelize.constantize.table_name | |
148 | + timestamp = "#{table_name}.updated_at >= '#{datetime}'" | |
149 | + end | |
150 | + | |
151 | + timestamp | |
152 | + end | |
153 | + | |
143 | 154 | def by_reference(scope, params) |
144 | 155 | if params[:reference_id] |
145 | 156 | created_at = scope.find(params[:reference_id]).created_at |
... | ... | @@ -154,11 +165,12 @@ module Noosfero |
154 | 165 | order = make_order_with_parameters(params) |
155 | 166 | page_number = make_page_number_with_parameters(params) |
156 | 167 | per_page = make_per_page_with_parameters(params) |
168 | + timestamp = make_timestamp_with_parameters_and_method(params, method) | |
157 | 169 | |
158 | 170 | objects = object.send(method) |
159 | 171 | objects = by_reference(objects, params) |
160 | 172 | |
161 | - objects = objects.where(conditions).page(page_number).per_page(per_page).order(order) | |
173 | + objects = objects.where(conditions).where(timestamp).page(page_number).per_page(per_page).order(order) | |
162 | 174 | |
163 | 175 | objects |
164 | 176 | end | ... | ... |