1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/controllers/open_api/v1/user_trainings_controller.rb
2016-05-04 18:17:50 +02:00

28 lines
770 B
Ruby

class OpenAPI::V1::UserTrainingsController < OpenAPI::V1::BaseController
def index
@user_trainings = UserTraining.order(created_at: :desc)
if params[:user_id].present?
@user_trainings = @user_trainings.where(user_id: params[:user_id])
else
@user_trainings = @user_trainings.includes(user: :profile)
end
if params[:training_id].present?
@user_trainings = @user_trainings.where(training_id: params[:training_id])
else
@user_trainings = @user_trainings.includes(:training)
end
if params[:page].present?
@user_trainings = @user_trainings.page(params[:page]).per(per_page)
paginate @user_trainings, per_page: per_page
end
end
private
def per_page
params[:per_page] || 20
end
end