mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-29 10:24:20 +01:00
4e030300cb
Also: tests for OpenAPI user trainings
31 lines
1001 B
Ruby
31 lines
1001 B
Ruby
# frozen_string_literal: true
|
|
|
|
# public API controller for user's trainings
|
|
class OpenAPI::V1::UserTrainingsController < OpenAPI::V1::BaseController
|
|
extend OpenAPI::ApiDoc
|
|
include Rails::Pagination
|
|
expose_doc
|
|
|
|
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: params[:user_id] }) if params[:user_id].present?
|
|
@user_trainings = @user_trainings.where(training_id: params[:training_id]) if params[:training_id].present?
|
|
|
|
return unless params[:page].present?
|
|
|
|
@user_trainings = @user_trainings.page(params[:page]).per(per_page)
|
|
paginate @user_trainings, per_page: per_page
|
|
end
|
|
|
|
private
|
|
|
|
def per_page
|
|
params[:per_page] || 20
|
|
end
|
|
end
|