Skip to content

Commit 1a0a450

Browse files
authored
feat: add from and to parameters to activities api endpoint (#1208)
* feat: add from and to parameters to activities api endpoint * Fix linter offenses * Fixed bug with ended activities not showing up * Added missing @
1 parent c07b732 commit 1a0a450

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

app/controllers/api/activities_controller.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ def index
1212
params[:date],
1313
params[:date]
1414
).order(:start_date).limit(params[:limit] ||= 10).offset(params[:offset] ||= 0)
15-
1615
else
17-
@activities = Activity.where('(end_date IS NULL AND start_date >= ?) OR end_date >= ?',
18-
Date.today, Date.today).order(:start_date).where(is_viewable: true)
19-
@activities.limit!(params[:limit]).offset(params[:offset] ||= 0) if params[:limit].present?
20-
@activities = @activities.reject(&:ended?)
16+
from = params[:from].present? ? Date.parse(params[:from]) : Date.today
17+
@activities = Activity.where('start_date >= ?', from)
18+
.order(:start_date)
19+
.where(is_viewable: true)
20+
21+
# Allow nil to mean no limit on the end date
22+
@activities = @activities.where('end_date <= ?', Date.parse(params[:to])) if params[:to].present?
23+
24+
@activities = @activities.limit!(params[:limit]).offset(params[:offset] ||= 0) if params[:limit].present?
25+
26+
@activities = @activities.reject(&:ended?) if params[:from].blank?
27+
@activities
2128
end
2229
end
2330

0 commit comments

Comments
 (0)