2014-09-02 18:07:02 +05:30
|
|
|
class TrendingProjectsFinder
|
|
|
|
def execute(current_user, start_date = nil)
|
|
|
|
start_date ||= Date.today - 1.month
|
|
|
|
|
|
|
|
projects = projects_for(current_user)
|
|
|
|
|
|
|
|
# Determine trending projects based on comments count
|
|
|
|
# for period of time - ex. month
|
|
|
|
projects.joins(:notes).where('notes.created_at > ?', start_date).
|
2015-09-25 12:07:36 +05:30
|
|
|
group("projects.id").reorder("count(notes.id) DESC")
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def projects_for(current_user)
|
|
|
|
ProjectsFinder.new.execute(current_user)
|
|
|
|
end
|
|
|
|
end
|