From 614abec39edebbd40e48d5e3b0ed9da9fad24471 Mon Sep 17 00:00:00 2001 From: Du Peng Date: Mon, 30 Oct 2023 08:08:35 +0100 Subject: [PATCH] (feat) add deleted_user param for open api users --- CHANGELOG.md | 1 + .../open_api/v1/users_controller.rb | 4 ++- app/doc/open_api/v1/users_doc.rb | 1 + .../open_api/v1/users/_user.json.jbuilder | 26 ++++++++++--------- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d412793c5..b8c907f06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fix a bug: fix all failing tasks of rake task file chain.rake - Fix a bug: file_size_validator.rb was broken since ruby v3, see https://github.com/rails/rails/issues/41270 - improvement: pre-registration event reservations ilimit places +- improvement: add deleted_user param for open api users - decreases sidekiq concurrency from 25 to 5, 25 is too much and consumes memory for nothing - do not log Notifications#polling action anymore, by default, can be enable via env variable ENABLE_NOTIFICATIONS_POLLING_LOGGING=true diff --git a/app/controllers/open_api/v1/users_controller.rb b/app/controllers/open_api/v1/users_controller.rb index 91713096d..4500d32cc 100644 --- a/app/controllers/open_api/v1/users_controller.rb +++ b/app/controllers/open_api/v1/users_controller.rb @@ -7,7 +7,9 @@ class OpenAPI::V1::UsersController < OpenAPI::V1::BaseController expose_doc def index - @users = User.order(created_at: :desc).includes(:group, :profile, :invoicing_profile) + @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? if params[:email].present? email_param = params[:email].is_a?(String) ? params[:email].downcase : params[:email].map(&:downcase) diff --git a/app/doc/open_api/v1/users_doc.rb b/app/doc/open_api/v1/users_doc.rb index 731858985..ef1089052 100644 --- a/app/doc/open_api/v1/users_doc.rb +++ b/app/doc/open_api/v1/users_doc.rb @@ -18,6 +18,7 @@ class OpenAPI::V1::UsersDoc < OpenAPI::V1::BaseDoc param :email, [String, Array], optional: true, desc: 'Filter users by *email* using strict matching.' param :user_id, [Integer, Array], optional: true, desc: 'Filter users by *id* using strict matching.' param :created_after, DateTime, optional: true, desc: 'Filter users to accounts created after the given date.' + param :deleted_user, [true, false], optional: true, desc: 'Filter users to accounts deleted or not.' example <<-USERS # /open_api/v1/users?page=1&per_page=4 { diff --git a/app/views/open_api/v1/users/_user.json.jbuilder b/app/views/open_api/v1/users/_user.json.jbuilder index 129b7d782..9a6d990f8 100644 --- a/app/views/open_api/v1/users/_user.json.jbuilder +++ b/app/views/open_api/v1/users/_user.json.jbuilder @@ -1,20 +1,22 @@ # frozen_string_literal: true -json.extract! user, :id, :email, :created_at -json.extract! user.profile, :full_name, :first_name, :last_name if user.association(:profile).loaded? -json.gender user.statistic_profile.gender ? 'man' : 'woman' - -if user.association(:invoicing_profile).loaded? - json.invoicing_profile_id user.invoicing_profile.id - json.external_id user.invoicing_profile.external_id - json.organization !user.invoicing_profile.organization.nil? - json.address user.invoicing_profile.invoicing_address +json.id user.user_id || user.id +json.extract! user, :email, :full_name, :first_name, :last_name, :created_at +if user.user + json.gender user.user.statistic_profile.gender ? 'man' : 'woman' +else + json.gender 'man' end -if user.association(:group).loaded? +json.invoicing_profile_id user.id +json.external_id user.external_id +json.organization !user.organization.nil? +json.address user.invoicing_address + +if user&.user&.group json.group do - if user.group_id? - json.extract! user.group, :id, :name, :slug + if user.user.group_id? + json.extract! user.user.group, :id, :name, :slug else json.nil! end