2021-06-24 12:36:16 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# public API controller for users
|
2016-05-04 18:17:50 +02:00
|
|
|
class OpenAPI::V1::UsersController < OpenAPI::V1::BaseController
|
2023-02-24 17:26:55 +01:00
|
|
|
extend OpenAPI::APIDoc
|
2021-06-24 12:36:16 +02:00
|
|
|
include Rails::Pagination
|
2016-05-05 15:02:02 +02:00
|
|
|
expose_doc
|
|
|
|
|
2016-05-04 18:17:50 +02:00
|
|
|
def index
|
2023-10-30 08:08:35 +01:00
|
|
|
@users = InvoicingProfile.order(created_at: :desc).includes(user: %i[group profile statistic_profile])
|
|
|
|
|
|
|
|
@users = @users.where.not(user_id: nil) if params[:deleted_user].blank?
|
2016-05-04 18:17:50 +02:00
|
|
|
|
|
|
|
if params[:email].present?
|
2016-05-05 15:02:02 +02:00
|
|
|
email_param = params[:email].is_a?(String) ? params[:email].downcase : params[:email].map(&:downcase)
|
|
|
|
@users = @users.where(email: email_param)
|
2016-05-04 18:17:50 +02:00
|
|
|
end
|
2022-11-23 17:35:39 +01:00
|
|
|
@users = @users.where(id: may_array(params[:user_id])) if params[:user_id].present?
|
2023-02-17 11:44:04 +01:00
|
|
|
@users = @users.where('created_at >= ?', Time.zone.parse(params[:created_after])) if params[:created_after].present?
|
2016-05-04 18:17:50 +02:00
|
|
|
|
2022-11-23 17:35:39 +01:00
|
|
|
return if params[:page].blank?
|
2016-05-04 18:17:50 +02:00
|
|
|
|
2023-03-03 10:09:07 +01:00
|
|
|
@users = @users.page(page).per(per_page)
|
2021-06-24 12:36:16 +02:00
|
|
|
paginate @users, per_page: per_page
|
2016-05-04 18:17:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2021-06-24 12:36:16 +02:00
|
|
|
|
2023-03-03 10:09:07 +01:00
|
|
|
def page
|
|
|
|
params[:page] || 1
|
|
|
|
end
|
|
|
|
|
2021-06-24 12:36:16 +02:00
|
|
|
def per_page
|
|
|
|
params[:per_page] || 20
|
|
|
|
end
|
2016-05-04 18:17:50 +02:00
|
|
|
end
|