Moves changed since condition to scope

pull/852/head
Hagen Schink 11 years ago
parent 4f4c445581
commit f6a0c90eb1
  1. 15
      app/controllers/api/v2/planning_elements_controller.rb
  2. 4
      app/models/work_package.rb

@ -38,6 +38,7 @@ module Api
before_filter :find_project_by_project_id,
:authorize, :except => [:index]
before_filter :parse_changed_since, only: [:index]
before_filter :assign_planning_elements, :except => [:index, :update, :create]
# Attention: find_all_projects_by_project_id needs to mimic all of the above
@ -207,13 +208,9 @@ module Api
def current_work_packages(projects)
work_packages = WorkPackage.for_projects(projects)
.changed_since(@since)
.includes(:status, :project, :type)
if params[:changed_since]
since = Time.at(Float(params[:changed_since]).to_i) rescue render_400
work_packages = work_packages.where(["updated_at >= ?", since])
end
if params[:f]
query = Query.new
query.add_filters(params[:f], params[:op], params[:v])
@ -283,6 +280,14 @@ module Api
end
private
def parse_changed_since
if params[:changed_since]
@since = Time.at(Float(params[:changed_since]).to_i) rescue render_400
end
end
end
end
end

@ -78,6 +78,10 @@ class WorkPackage < ActiveRecord::Base
{:conditions => {:project_id => projects}}
}
scope :changed_since, lambda { |changed_since|
changed_since ? { conditions: ["updated_at >= ?", changed_since] } : nil
}
# >>> issues.rb >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
scope :open, :conditions => ["#{Status.table_name}.is_closed = ?", false], :include => :status

Loading…
Cancel
Save