1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-12 23:09:03 +01:00
fab-manager/app/controllers/open_api/v1/user_trainings_controller.rb

30 lines
1016 B
Ruby
Raw Normal View History

# frozen_string_literal: true
# public API controller for user's trainings
2016-05-04 18:17:50 +02:00
class OpenAPI::V1::UserTrainingsController < OpenAPI::V1::BaseController
2023-02-24 17:26:55 +01:00
extend OpenAPI::APIDoc
include Rails::Pagination
2016-05-05 15:02:02 +02:00
expose_doc
2016-05-04 18:17:50 +02:00
def index
@user_trainings = StatisticProfileTraining.includes(statistic_profile: :user)
.includes(:training)
.references(:statistic_profiles)
.order(created_at: :desc)
@user_trainings = @user_trainings.where(statistic_profiles: { user_id: may_array(params[:user_id]) }) if params[:user_id].present?
@user_trainings = @user_trainings.where(training_id: may_array(params[:training_id])) if params[:training_id].present?
return if params[:page].blank?
@user_trainings = @user_trainings.page(params[:page]).per(per_page)
paginate @user_trainings, per_page: per_page
2016-05-04 18:17:50 +02:00
end
private
def per_page
params[:per_page] || 20
end
2016-05-04 18:17:50 +02:00
end