Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pagination for upload API #3425

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/controllers/courses_controller.rb
Expand Up @@ -113,6 +113,7 @@ def timeline

def uploads
set_course
set_page
end

##########################
Expand Down Expand Up @@ -176,6 +177,16 @@ def delete_all_weeks
render plain: '', status: :ok
end

def set_presenter
@presenter = CoursesPresenter.new(current_user: current_user,
campaign_param: @campaign.slug, page: @page)
end

def set_page
@page = params[:page]&.to_i
@page = nil unless @page&.positive?
end

##################
# Helper methods #
##################
Expand Down
2 changes: 1 addition & 1 deletion app/views/courses/uploads.json.jbuilder
@@ -1,7 +1,7 @@
# frozen_string_literal: true

json.course do
json.uploads @course.uploads.includes(:user) do |upload|
will_paginate json.uploads @course.uploads.includes(:user) do |upload|
json.call(upload, :id, :uploaded_at, :usage_count, :url, :thumburl, :deleted,
:thumbwidth, :thumbheight)
json.file_name pretty_filename(upload)
Expand Down