souls 0.22.4 → 0.22.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +7 -2
- data/exe/souls +27 -6
- data/hoy/.env.sample +7 -0
- data/hoy/.gitignore +32 -0
- data/hoy/.irbrc +1 -0
- data/hoy/.rspec +3 -0
- data/hoy/.rubocop.yml +132 -0
- data/hoy/.ruby-version +1 -0
- data/hoy/CODE_OF_CONDUCT.md +74 -0
- data/hoy/Dockerfile +16 -0
- data/hoy/Dockerfile.dev +17 -0
- data/hoy/Gemfile +50 -0
- data/hoy/Gemfile.lock +407 -0
- data/hoy/LICENSE.txt +67 -0
- data/hoy/Procfile +2 -0
- data/hoy/Procfile.dev +2 -0
- data/hoy/README.md +61 -0
- data/hoy/Rakefile +5 -0
- data/hoy/app.rb +116 -0
- data/hoy/app/graphql/mutations/.keep +0 -0
- data/hoy/app/graphql/mutations/base/article/create_article.rb +30 -0
- data/hoy/app/graphql/mutations/base/article/delete_article.rb +17 -0
- data/hoy/app/graphql/mutations/base/article/destroy_delete_article.rb +17 -0
- data/hoy/app/graphql/mutations/base/article/update_article.rb +30 -0
- data/hoy/app/graphql/mutations/base/article_category/create_article_category.rb +21 -0
- data/hoy/app/graphql/mutations/base/article_category/delete_article_category.rb +17 -0
- data/hoy/app/graphql/mutations/base/article_category/destroy_delete_article_category.rb +17 -0
- data/hoy/app/graphql/mutations/base/article_category/update_article_category.rb +21 -0
- data/hoy/app/graphql/mutations/base/user/create_user.rb +31 -0
- data/hoy/app/graphql/mutations/base/user/delete_user.rb +17 -0
- data/hoy/app/graphql/mutations/base/user/destroy_delete_user.rb +17 -0
- data/hoy/app/graphql/mutations/base/user/update_user.rb +31 -0
- data/hoy/app/graphql/mutations/base_mutation.rb +33 -0
- data/hoy/app/graphql/mutations/user_manager/add_user_role.rb +22 -0
- data/hoy/app/graphql/mutations/user_manager/remove_user_role.rb +22 -0
- data/hoy/app/graphql/mutations/user_manager/sign_in_user.rb +45 -0
- data/hoy/app/graphql/queries/article.rb +13 -0
- data/hoy/app/graphql/queries/article_categories.rb +11 -0
- data/hoy/app/graphql/queries/article_category.rb +13 -0
- data/hoy/app/graphql/queries/articles.rb +11 -0
- data/hoy/app/graphql/queries/base_query.rb +9 -0
- data/hoy/app/graphql/queries/me.rb +11 -0
- data/hoy/app/graphql/queries/user.rb +13 -0
- data/hoy/app/graphql/queries/users.rb +11 -0
- data/hoy/app/graphql/resolvers/article_category_search.rb +41 -0
- data/hoy/app/graphql/resolvers/article_search.rb +57 -0
- data/hoy/app/graphql/resolvers/base.rb +17 -0
- data/hoy/app/graphql/resolvers/user_search.rb +63 -0
- data/hoy/app/graphql/souls_api_schema.rb +43 -0
- data/hoy/app/graphql/types/.keep +0 -0
- data/hoy/app/graphql/types/article_category_type.rb +12 -0
- data/hoy/app/graphql/types/article_type.rb +30 -0
- data/hoy/app/graphql/types/base/base_argument.rb +4 -0
- data/hoy/app/graphql/types/base/base_enum.rb +4 -0
- data/hoy/app/graphql/types/base/base_field.rb +5 -0
- data/hoy/app/graphql/types/base/base_input_object.rb +5 -0
- data/hoy/app/graphql/types/base/base_interface.rb +7 -0
- data/hoy/app/graphql/types/base/base_object.rb +6 -0
- data/hoy/app/graphql/types/base/base_scalar.rb +4 -0
- data/hoy/app/graphql/types/base/base_union.rb +4 -0
- data/hoy/app/graphql/types/base/mutation_type.rb +16 -0
- data/hoy/app/graphql/types/base/query_type.rb +18 -0
- data/hoy/app/graphql/types/connections/article_category_connection.rb +3 -0
- data/hoy/app/graphql/types/connections/article_connection.rb +3 -0
- data/hoy/app/graphql/types/connections/base_connection.rb +14 -0
- data/hoy/app/graphql/types/connections/user_connection.rb +3 -0
- data/hoy/app/graphql/types/edges/article_category_edge.rb +5 -0
- data/hoy/app/graphql/types/edges/article_edge.rb +5 -0
- data/hoy/app/graphql/types/edges/base_edge.rb +4 -0
- data/hoy/app/graphql/types/edges/user_edge.rb +5 -0
- data/hoy/app/graphql/types/user_type.rb +22 -0
- data/hoy/app/models/article.rb +4 -0
- data/hoy/app/models/article_category.rb +3 -0
- data/hoy/app/models/user.rb +19 -0
- data/hoy/app/policies/application_policy.rb +40 -0
- data/hoy/app/policies/article_category_policy.rb +31 -0
- data/hoy/app/policies/article_policy.rb +31 -0
- data/hoy/app/policies/user_policy.rb +35 -0
- data/hoy/app/utils/association_loader.rb +50 -0
- data/hoy/app/utils/firebase_id_token.rb +4 -0
- data/hoy/app/utils/json_web_token.rb +13 -0
- data/hoy/app/utils/record_loader.rb +10 -0
- data/hoy/app/utils/souls_helper.rb +96 -0
- data/hoy/cloudbuild.yml +32 -0
- data/hoy/config.ru +17 -0
- data/hoy/config/database.yml +33 -0
- data/hoy/config/souls.rb +4 -0
- data/hoy/constants/areas.rb +71 -0
- data/hoy/constants/column_name_ja.rb +27 -0
- data/hoy/db/migrate/20200006095538_create_users.rb +30 -0
- data/hoy/db/migrate/20200712180236_create_article_categories.rb +12 -0
- data/hoy/db/migrate/20200714215521_create_articles.rb +22 -0
- data/hoy/db/schema.rb +78 -0
- data/hoy/db/seeds.rb +44 -0
- data/hoy/github/workflows/delivery.yml +81 -0
- data/hoy/log/.keep +0 -0
- data/hoy/spec/factories/article_categories.rb +9 -0
- data/hoy/spec/factories/articles.rb +17 -0
- data/hoy/spec/factories/users.rb +23 -0
- data/hoy/spec/models/article_category_spec.rb +7 -0
- data/hoy/spec/models/article_spec.rb +7 -0
- data/hoy/spec/models/user_spec.rb +7 -0
- data/hoy/spec/mutations/base/article_category_spec.rb +46 -0
- data/hoy/spec/mutations/base/article_spec.rb +70 -0
- data/hoy/spec/mutations/base/user_spec.rb +76 -0
- data/hoy/spec/policies/article_category_policy_spec.rb +25 -0
- data/hoy/spec/policies/article_policy_spec.rb +25 -0
- data/hoy/spec/policies/user_policy_spec.rb +5 -0
- data/hoy/spec/queries/article_category_spec.rb +39 -0
- data/hoy/spec/queries/article_spec.rb +53 -0
- data/hoy/spec/queries/user_spec.rb +59 -0
- data/hoy/spec/resolvers/article_category_search_spec.rb +54 -0
- data/hoy/spec/resolvers/article_search_spec.rb +68 -0
- data/hoy/spec/resolvers/user_search_spec.rb +74 -0
- data/hoy/spec/spec_helper.rb +110 -0
- data/hoy/tmp/.keep +0 -0
- data/lib/souls.rb +47 -9
- data/lib/souls/generate/mutation.rb +4 -6
- data/lib/souls/init.rb +16 -9
- data/lib/souls/version.rb +1 -1
- data/souls.gemspec +3 -1
- metadata +146 -4
@@ -0,0 +1,31 @@
|
|
1
|
+
module Mutations
|
2
|
+
module Base::User
|
3
|
+
class UpdateUser < BaseMutation
|
4
|
+
field :user_edge, Types::UserType.edge_type, null: false
|
5
|
+
|
6
|
+
argument :birthday, String, required: false
|
7
|
+
argument :email, String, required: false
|
8
|
+
argument :first_name, String, required: false
|
9
|
+
argument :first_name_kana, String, required: false
|
10
|
+
argument :first_name_kanji, String, required: false
|
11
|
+
argument :icon_url, String, required: false
|
12
|
+
argument :id, String, required: true
|
13
|
+
argument :last_name, String, required: false
|
14
|
+
argument :last_name_kana, String, required: false
|
15
|
+
argument :last_name_kanji, String, required: false
|
16
|
+
argument :screen_name, String, required: false
|
17
|
+
argument :tel, String, required: false
|
18
|
+
argument :uid, String, required: false
|
19
|
+
argument :username, String, required: false
|
20
|
+
|
21
|
+
def resolve(**args)
|
22
|
+
_, args[:id] = SoulsApiSchema.from_global_id(args[:id])
|
23
|
+
user = ::User.find(args[:id])
|
24
|
+
user.update(args)
|
25
|
+
{ user_edge: { node: ::User.find(args[:id]) } }
|
26
|
+
rescue StandardError => e
|
27
|
+
GraphQL::ExecutionError.new(e)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Mutations
|
2
|
+
class BaseMutation < GraphQL::Schema::RelayClassicMutation
|
3
|
+
argument_class Types::BaseArgument
|
4
|
+
field_class Types::BaseField
|
5
|
+
input_object_class Types::BaseInputObject
|
6
|
+
object_class Types::BaseObject
|
7
|
+
|
8
|
+
def fb_auth(token:)
|
9
|
+
FirebaseIdToken::Certificates.request!
|
10
|
+
sleep(3) if ENV["RACK_ENV"] == "development"
|
11
|
+
@payload = FirebaseIdToken::Signature.verify(token)
|
12
|
+
raise(ArgumentError, "Invalid or Missing Token") if @payload.blank?
|
13
|
+
|
14
|
+
@payload
|
15
|
+
end
|
16
|
+
|
17
|
+
def auth_check(context)
|
18
|
+
raise(GraphQL::ExecutionError, "You need to sign in!!") if context[:user].nil?
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_token(token)
|
22
|
+
JsonWebToken.decode(token)
|
23
|
+
end
|
24
|
+
|
25
|
+
def production?
|
26
|
+
ENV["RACK_ENV"] == "production"
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_instance_id
|
30
|
+
`curl http://metadata.google.internal/computeMetadata/v1/instance/id -H Metadata-Flavor:Google`
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Mutations
|
2
|
+
module UserManager
|
3
|
+
class AddUserRole < BaseMutation
|
4
|
+
argument :target_user_id, String, required: true
|
5
|
+
argument :user_roles, [String], required: true
|
6
|
+
|
7
|
+
field :user, Types::UserType, null: true
|
8
|
+
|
9
|
+
def resolve(**args)
|
10
|
+
check_user_permissions(context[:user], context[:user], :update_user_role?)
|
11
|
+
_, user_id = SoulsApiSchema.from_global_id(args[:target_user_id])
|
12
|
+
target_user = ::User.find(user_id)
|
13
|
+
target_user.roles << args[:user_roles].map(&:to_sym)
|
14
|
+
return { user: target_user } if target_user.save
|
15
|
+
|
16
|
+
raise
|
17
|
+
rescue StandardError => e
|
18
|
+
GraphQL::ExecutionError.new(e.to_s)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Mutations
|
2
|
+
module UserManager
|
3
|
+
class RemoveUserRole < BaseMutation
|
4
|
+
argument :target_user_id, String, required: true
|
5
|
+
argument :user_roles, [String], required: true
|
6
|
+
|
7
|
+
field :user, Types::UserType, null: true
|
8
|
+
|
9
|
+
def resolve(**args)
|
10
|
+
check_user_permissions(context[:user], context[:user], :update_user_role?)
|
11
|
+
_, user_id = SoulsApiSchema.from_global_id(args[:target_user_id])
|
12
|
+
target_user = ::User.find(user_id)
|
13
|
+
args[:user_roles].each { |role| target_user.roles.delete(role) }
|
14
|
+
return { user: target_user } if target_user.save
|
15
|
+
|
16
|
+
raise
|
17
|
+
rescue StandardError => e
|
18
|
+
GraphQL::ExecutionError.new(e.to_s)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Mutations
|
2
|
+
module UserManager
|
3
|
+
class SignInUser < BaseMutation
|
4
|
+
field :status, String, null: false
|
5
|
+
field :token, String, null: true
|
6
|
+
field :user_role, String, null: true
|
7
|
+
field :username, String, null: true
|
8
|
+
argument :token, String, required: false
|
9
|
+
|
10
|
+
def resolve(token:)
|
11
|
+
fb_auth(token: token)
|
12
|
+
begin
|
13
|
+
user = ::User.find_by_uid(@payload["sub"])
|
14
|
+
user.update(icon_url: @payload["picture"], username: @payload["name"])
|
15
|
+
token_base = JsonWebToken.encode(user_id: user.id)
|
16
|
+
{
|
17
|
+
status: "ログイン成功!",
|
18
|
+
username: user.username,
|
19
|
+
token: token_base
|
20
|
+
}
|
21
|
+
rescue StandardError
|
22
|
+
user =
|
23
|
+
::User.new(
|
24
|
+
uid: @payload["sub"],
|
25
|
+
email: @payload["email"],
|
26
|
+
icon_url: @payload["picture"],
|
27
|
+
username: @payload["name"],
|
28
|
+
user_role: 4
|
29
|
+
)
|
30
|
+
if user.save
|
31
|
+
token = JsonWebToken.encode(user_id: user.id)
|
32
|
+
{
|
33
|
+
status: "ユーザー新規登録完了!",
|
34
|
+
username: user.username,
|
35
|
+
token: token,
|
36
|
+
user_role: user.user_role
|
37
|
+
}
|
38
|
+
else
|
39
|
+
{ status: user.errors.full_messages }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Queries
|
2
|
+
class Article < Queries::BaseQuery
|
3
|
+
type Types::ArticleType, null: false
|
4
|
+
argument :id, String, required: true
|
5
|
+
|
6
|
+
def resolve(**args)
|
7
|
+
_, data_id = SoulsApiSchema.from_global_id(args[:id])
|
8
|
+
::Article.find(data_id)
|
9
|
+
rescue StandardError => e
|
10
|
+
GraphQL::ExecutionError.new(e)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Queries
|
2
|
+
class ArticleCategory < Queries::BaseQuery
|
3
|
+
type Types::ArticleCategoryType, null: false
|
4
|
+
argument :id, String, required: true
|
5
|
+
|
6
|
+
def resolve(**args)
|
7
|
+
_, data_id = SoulsApiSchema.from_global_id(args[:id])
|
8
|
+
::ArticleCategory.find(data_id)
|
9
|
+
rescue StandardError => e
|
10
|
+
GraphQL::ExecutionError.new(e)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Queries
|
2
|
+
class User < Queries::BaseQuery
|
3
|
+
type Types::UserType, null: false
|
4
|
+
argument :id, String, required: true
|
5
|
+
|
6
|
+
def resolve(**args)
|
7
|
+
_, data_id = SoulsApiSchema.from_global_id(args[:id])
|
8
|
+
::User.find(data_id)
|
9
|
+
rescue StandardError => e
|
10
|
+
GraphQL::ExecutionError.new(e)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Resolvers
|
2
|
+
class ArticleCategorySearch < Base
|
3
|
+
include SearchObject.module(:graphql)
|
4
|
+
scope { ::ArticleCategory.all }
|
5
|
+
type Types::ArticleCategoryType.connection_type, null: false
|
6
|
+
description "Search ArticleCategory"
|
7
|
+
|
8
|
+
class ArticleCategoryFilter < ::Types::BaseInputObject
|
9
|
+
argument :OR, [self], required: false
|
10
|
+
argument :end_date, String, required: false
|
11
|
+
argument :is_deleted, Boolean, required: false
|
12
|
+
argument :name, String, required: false
|
13
|
+
argument :start_date, String, required: false
|
14
|
+
argument :tags, [String], required: false
|
15
|
+
end
|
16
|
+
|
17
|
+
option :filter, type: ArticleCategoryFilter, with: :apply_filter
|
18
|
+
option :first, type: types.Int, with: :apply_first
|
19
|
+
option :skip, type: types.Int, with: :apply_skip
|
20
|
+
|
21
|
+
def apply_filter(scope, value)
|
22
|
+
branches = normalize_filters(value).inject { |acc, elem| acc.or(elem) }
|
23
|
+
scope.merge(branches)
|
24
|
+
end
|
25
|
+
|
26
|
+
def normalize_filters(value, branches = [])
|
27
|
+
scope = ::ArticleCategory.all
|
28
|
+
scope = scope.where(name: value[:name]) if value[:name]
|
29
|
+
scope = scope.where("tags @> ARRAY[?]::text[]", value[:tags]) if value[:tags]
|
30
|
+
scope = scope.where(is_deleted: value[:is_deleted]) unless value[:is_deleted].nil?
|
31
|
+
scope = scope.where("created_at >= ?", value[:start_date]) if value[:start_date]
|
32
|
+
scope = scope.where("created_at <= ?", value[:end_date]) if value[:end_date]
|
33
|
+
|
34
|
+
branches << scope
|
35
|
+
|
36
|
+
value[:OR].inject(branches) { |acc, elem| normalize_filters(elem, acc) } if value[:OR].present?
|
37
|
+
|
38
|
+
branches
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Resolvers
|
2
|
+
class ArticleSearch < Base
|
3
|
+
include SearchObject.module(:graphql)
|
4
|
+
scope { ::Article.all }
|
5
|
+
type Types::ArticleType.connection_type, null: false
|
6
|
+
description "Search Article"
|
7
|
+
|
8
|
+
class ArticleFilter < ::Types::BaseInputObject
|
9
|
+
argument :OR, [self], required: false
|
10
|
+
argument :article_category_id, String, required: false
|
11
|
+
argument :body, String, required: false
|
12
|
+
argument :end_date, String, required: false
|
13
|
+
argument :is_deleted, Boolean, required: false
|
14
|
+
argument :is_public, Boolean, required: false
|
15
|
+
argument :just_created, Boolean, required: false
|
16
|
+
argument :public_date, GraphQL::Types::ISO8601DateTime, required: false
|
17
|
+
argument :slag, String, required: false
|
18
|
+
argument :start_date, String, required: false
|
19
|
+
argument :tags, [String], required: false
|
20
|
+
argument :thumnail_url, String, required: false
|
21
|
+
argument :title, String, required: false
|
22
|
+
end
|
23
|
+
|
24
|
+
option :filter, type: ArticleFilter, with: :apply_filter
|
25
|
+
option :first, type: types.Int, with: :apply_first
|
26
|
+
option :skip, type: types.Int, with: :apply_skip
|
27
|
+
|
28
|
+
def apply_filter(scope, value)
|
29
|
+
branches = normalize_filters(value).inject { |acc, elem| acc.or(elem) }
|
30
|
+
scope.merge(branches)
|
31
|
+
end
|
32
|
+
|
33
|
+
def normalize_filters(value, branches = [])
|
34
|
+
scope = ::Article.all
|
35
|
+
scope = scope.where(title: value[:title]) if value[:title]
|
36
|
+
scope = scope.where(body: value[:body]) if value[:body]
|
37
|
+
scope = scope.where(thumnail_url: value[:thumnail_url]) if value[:thumnail_url]
|
38
|
+
scope = scope.where(public_date: value[:public_date]) if value[:public_date]
|
39
|
+
if value[:article_category_id]
|
40
|
+
scope = scope.where(article_category_id: decode_global_key(value[:article_category_id]))
|
41
|
+
end
|
42
|
+
scope = scope.where(is_public: value[:is_public]) unless value[:is_public].nil?
|
43
|
+
scope = scope.where(just_created: value[:just_created]) unless value[:just_created].nil?
|
44
|
+
scope = scope.where(slag: value[:slag]) if value[:slag]
|
45
|
+
scope = scope.where("tags @> ARRAY[?]::text[]", value[:tags]) if value[:tags]
|
46
|
+
scope = scope.where(is_deleted: value[:is_deleted]) unless value[:is_deleted].nil?
|
47
|
+
scope = scope.where("created_at >= ?", value[:start_date]) if value[:start_date]
|
48
|
+
scope = scope.where("created_at <= ?", value[:end_date]) if value[:end_date]
|
49
|
+
|
50
|
+
branches << scope
|
51
|
+
|
52
|
+
value[:OR].inject(branches) { |acc, elem| normalize_filters(elem, acc) } if value[:OR].present?
|
53
|
+
|
54
|
+
branches
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Resolvers
|
2
|
+
class Base < GraphQL::Schema::Resolver
|
3
|
+
# argument_class Arguments::Base
|
4
|
+
def decode_global_key(id)
|
5
|
+
_, data_id = SoulsApiSchema.from_global_id(id)
|
6
|
+
data_id
|
7
|
+
end
|
8
|
+
|
9
|
+
def apply_first(scope, value)
|
10
|
+
scope.limit(value)
|
11
|
+
end
|
12
|
+
|
13
|
+
def apply_skip(scope, value)
|
14
|
+
scope.offset(value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Resolvers
|
2
|
+
class UserSearch < Base
|
3
|
+
include SearchObject.module(:graphql)
|
4
|
+
scope { ::User.all }
|
5
|
+
type Types::UserType.connection_type, null: false
|
6
|
+
description "Search User"
|
7
|
+
|
8
|
+
class UserFilter < ::Types::BaseInputObject
|
9
|
+
argument :OR, [self], required: false
|
10
|
+
argument :birthday, String, required: false
|
11
|
+
argument :email, String, required: false
|
12
|
+
argument :end_date, String, required: false
|
13
|
+
argument :first_name, String, required: false
|
14
|
+
argument :first_name_kana, String, required: false
|
15
|
+
argument :first_name_kanji, String, required: false
|
16
|
+
argument :icon_url, String, required: false
|
17
|
+
argument :is_deleted, Boolean, required: false
|
18
|
+
argument :last_name, String, required: false
|
19
|
+
argument :last_name_kana, String, required: false
|
20
|
+
argument :last_name_kanji, String, required: false
|
21
|
+
argument :screen_name, String, required: false
|
22
|
+
argument :start_date, String, required: false
|
23
|
+
argument :tel, String, required: false
|
24
|
+
argument :uid, String, required: false
|
25
|
+
argument :username, String, required: false
|
26
|
+
end
|
27
|
+
|
28
|
+
option :filter, type: UserFilter, with: :apply_filter
|
29
|
+
option :first, type: types.Int, with: :apply_first
|
30
|
+
option :skip, type: types.Int, with: :apply_skip
|
31
|
+
|
32
|
+
def apply_filter(scope, value)
|
33
|
+
branches = normalize_filters(value).inject { |acc, elem| acc.or(elem) }
|
34
|
+
scope.merge(branches)
|
35
|
+
end
|
36
|
+
|
37
|
+
def normalize_filters(value, branches = [])
|
38
|
+
scope = ::User.all
|
39
|
+
scope = scope.where(uid: value[:uid]) if value[:uid]
|
40
|
+
scope = scope.where(username: value[:username]) if value[:username]
|
41
|
+
scope = scope.where(screen_name: value[:screen_name]) if value[:screen_name]
|
42
|
+
scope = scope.where(last_name: value[:last_name]) if value[:last_name]
|
43
|
+
scope = scope.where(first_name: value[:first_name]) if value[:first_name]
|
44
|
+
scope = scope.where(last_name_kanji: value[:last_name_kanji]) if value[:last_name_kanji]
|
45
|
+
scope = scope.where(first_name_kanji: value[:first_name_kanji]) if value[:first_name_kanji]
|
46
|
+
scope = scope.where(last_name_kana: value[:last_name_kana]) if value[:last_name_kana]
|
47
|
+
scope = scope.where(first_name_kana: value[:first_name_kana]) if value[:first_name_kana]
|
48
|
+
scope = scope.where(email: value[:email]) if value[:email]
|
49
|
+
scope = scope.where(tel: value[:tel]) if value[:tel]
|
50
|
+
scope = scope.where(icon_url: value[:icon_url]) if value[:icon_url]
|
51
|
+
scope = scope.where(birthday: value[:birthday]) if value[:birthday]
|
52
|
+
scope = scope.where(is_deleted: value[:is_deleted]) unless value[:is_deleted].nil?
|
53
|
+
scope = scope.where("created_at >= ?", value[:start_date]) if value[:start_date]
|
54
|
+
scope = scope.where("created_at <= ?", value[:end_date]) if value[:end_date]
|
55
|
+
|
56
|
+
branches << scope
|
57
|
+
|
58
|
+
value[:OR].inject(branches) { |acc, elem| normalize_filters(elem, acc) } if value[:OR].present?
|
59
|
+
|
60
|
+
branches
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|