1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-05 16:24:21 +01:00
fab-manager/app/controllers/open_api/v1/user_trainings_controller.rb

31 lines
811 B
Ruby
Raw Normal View History

2016-05-04 18:17:50 +02:00
class OpenAPI::V1::UserTrainingsController < OpenAPI::V1::BaseController
2016-05-05 15:02:02 +02:00
extend OpenAPI::ApiDoc
expose_doc
2016-05-04 18:17:50 +02:00
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