souls 0.24.1 → 0.24.5
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/exe/souls +12 -1
- data/lib/souls.rb +181 -123
- data/lib/souls/gcloud/iam.rb +30 -16
- data/lib/souls/init.rb +22 -16
- data/lib/souls/version.rb +1 -1
- metadata +16 -193
- data/.gitignore +0 -15
- data/.irbrc +0 -2
- data/.rspec +0 -3
- data/.rubocop.yml +0 -152
- data/.ruby-version +0 -1
- data/.travis.yml +0 -6
- data/Gemfile +0 -13
- data/Gemfile.lock +0 -98
- data/Rakefile +0 -23
- data/Steepfile +0 -8
- data/api_v0.0.1.tar.gz +0 -0
- data/apps/api/.env.sample +0 -7
- data/apps/api/.gitignore +0 -32
- data/apps/api/.irbrc +0 -1
- data/apps/api/.rspec +0 -3
- data/apps/api/.rubocop.yml +0 -132
- data/apps/api/.ruby-version +0 -1
- data/apps/api/CODE_OF_CONDUCT.md +0 -74
- data/apps/api/Dockerfile +0 -16
- data/apps/api/Dockerfile.dev +0 -17
- data/apps/api/Gemfile +0 -50
- data/apps/api/Gemfile.lock +0 -412
- data/apps/api/LICENSE.txt +0 -67
- data/apps/api/Procfile +0 -2
- data/apps/api/Procfile.dev +0 -2
- data/apps/api/README.md +0 -37
- data/apps/api/Rakefile +0 -5
- data/apps/api/app.rb +0 -114
- data/apps/api/app/engines/notification_engine.rb +0 -5
- data/apps/api/app/graphql/mutations/.keep +0 -0
- data/apps/api/app/graphql/mutations/base/article/create_article.rb +0 -30
- data/apps/api/app/graphql/mutations/base/article/delete_article.rb +0 -17
- data/apps/api/app/graphql/mutations/base/article/destroy_delete_article.rb +0 -17
- data/apps/api/app/graphql/mutations/base/article/update_article.rb +0 -30
- data/apps/api/app/graphql/mutations/base/article_category/create_article_category.rb +0 -21
- data/apps/api/app/graphql/mutations/base/article_category/delete_article_category.rb +0 -17
- data/apps/api/app/graphql/mutations/base/article_category/destroy_delete_article_category.rb +0 -17
- data/apps/api/app/graphql/mutations/base/article_category/update_article_category.rb +0 -21
- data/apps/api/app/graphql/mutations/base/user/create_user.rb +0 -31
- data/apps/api/app/graphql/mutations/base/user/delete_user.rb +0 -17
- data/apps/api/app/graphql/mutations/base/user/destroy_delete_user.rb +0 -17
- data/apps/api/app/graphql/mutations/base/user/update_user.rb +0 -31
- data/apps/api/app/graphql/mutations/base_mutation.rb +0 -65
- data/apps/api/app/graphql/mutations/managers/user_manager/add_user_role.rb +0 -22
- data/apps/api/app/graphql/mutations/managers/user_manager/remove_user_role.rb +0 -22
- data/apps/api/app/graphql/mutations/managers/user_manager/sign_in_user.rb +0 -45
- data/apps/api/app/graphql/queries/article.rb +0 -13
- data/apps/api/app/graphql/queries/article_categories.rb +0 -11
- data/apps/api/app/graphql/queries/article_category.rb +0 -13
- data/apps/api/app/graphql/queries/articles.rb +0 -11
- data/apps/api/app/graphql/queries/base_query.rb +0 -12
- data/apps/api/app/graphql/queries/me.rb +0 -11
- data/apps/api/app/graphql/queries/user.rb +0 -13
- data/apps/api/app/graphql/queries/users.rb +0 -11
- data/apps/api/app/graphql/resolvers/article_category_search.rb +0 -41
- data/apps/api/app/graphql/resolvers/article_search.rb +0 -57
- data/apps/api/app/graphql/resolvers/base.rb +0 -17
- data/apps/api/app/graphql/resolvers/user_search.rb +0 -63
- data/apps/api/app/graphql/souls_api_schema.rb +0 -43
- data/apps/api/app/graphql/types/.keep +0 -0
- data/apps/api/app/graphql/types/article_category_type.rb +0 -12
- data/apps/api/app/graphql/types/article_type.rb +0 -30
- data/apps/api/app/graphql/types/base/base_argument.rb +0 -4
- data/apps/api/app/graphql/types/base/base_enum.rb +0 -4
- data/apps/api/app/graphql/types/base/base_field.rb +0 -5
- data/apps/api/app/graphql/types/base/base_input_object.rb +0 -5
- data/apps/api/app/graphql/types/base/base_interface.rb +0 -7
- data/apps/api/app/graphql/types/base/base_object.rb +0 -6
- data/apps/api/app/graphql/types/base/base_scalar.rb +0 -4
- data/apps/api/app/graphql/types/base/base_union.rb +0 -4
- data/apps/api/app/graphql/types/base/mutation_type.rb +0 -26
- data/apps/api/app/graphql/types/base/query_type.rb +0 -18
- data/apps/api/app/graphql/types/connections/article_category_connection.rb +0 -3
- data/apps/api/app/graphql/types/connections/article_connection.rb +0 -3
- data/apps/api/app/graphql/types/connections/base_connection.rb +0 -14
- data/apps/api/app/graphql/types/connections/user_connection.rb +0 -3
- data/apps/api/app/graphql/types/edges/article_category_edge.rb +0 -5
- data/apps/api/app/graphql/types/edges/article_edge.rb +0 -5
- data/apps/api/app/graphql/types/edges/base_edge.rb +0 -4
- data/apps/api/app/graphql/types/edges/user_edge.rb +0 -5
- data/apps/api/app/graphql/types/user_type.rb +0 -24
- data/apps/api/app/models/article.rb +0 -4
- data/apps/api/app/models/article_category.rb +0 -3
- data/apps/api/app/models/user.rb +0 -19
- data/apps/api/app/policies/application_policy.rb +0 -40
- data/apps/api/app/policies/article_category_policy.rb +0 -31
- data/apps/api/app/policies/article_policy.rb +0 -31
- data/apps/api/app/policies/user_policy.rb +0 -35
- data/apps/api/app/utils/association_loader.rb +0 -50
- data/apps/api/app/utils/fire_store.rb +0 -9
- data/apps/api/app/utils/firebase_id_token.rb +0 -4
- data/apps/api/app/utils/json_web_token.rb +0 -13
- data/apps/api/app/utils/record_loader.rb +0 -10
- data/apps/api/app/utils/souls_helper.rb +0 -18
- data/apps/api/cloudbuild.yml +0 -32
- data/apps/api/config.ru +0 -17
- data/apps/api/config/database.yml +0 -33
- data/apps/api/config/souls.rb +0 -10
- data/apps/api/constants/areas.rb +0 -71
- data/apps/api/constants/column_name_ja.rb +0 -27
- data/apps/api/db/migrate/20200006095538_create_users.rb +0 -30
- data/apps/api/db/migrate/20200712180236_create_article_categories.rb +0 -12
- data/apps/api/db/migrate/20200714215521_create_articles.rb +0 -22
- data/apps/api/db/schema.rb +0 -78
- data/apps/api/db/seeds.rb +0 -44
- data/apps/api/github/workflows/delivery.yml +0 -81
- data/apps/api/log/.keep +0 -0
- data/apps/api/spec/factories/article_categories.rb +0 -9
- data/apps/api/spec/factories/articles.rb +0 -17
- data/apps/api/spec/factories/users.rb +0 -23
- data/apps/api/spec/models/article_category_spec.rb +0 -7
- data/apps/api/spec/models/article_spec.rb +0 -7
- data/apps/api/spec/models/user_spec.rb +0 -7
- data/apps/api/spec/mutations/base/article_category_spec.rb +0 -46
- data/apps/api/spec/mutations/base/article_spec.rb +0 -70
- data/apps/api/spec/mutations/base/user_spec.rb +0 -76
- data/apps/api/spec/policies/article_category_policy_spec.rb +0 -25
- data/apps/api/spec/policies/article_policy_spec.rb +0 -25
- data/apps/api/spec/policies/user_policy_spec.rb +0 -5
- data/apps/api/spec/queries/article_category_spec.rb +0 -39
- data/apps/api/spec/queries/article_spec.rb +0 -53
- data/apps/api/spec/queries/user_spec.rb +0 -59
- data/apps/api/spec/resolvers/article_category_search_spec.rb +0 -54
- data/apps/api/spec/resolvers/article_search_spec.rb +0 -68
- data/apps/api/spec/resolvers/user_search_spec.rb +0 -74
- data/apps/api/spec/spec_helper.rb +0 -110
- data/apps/api/tmp/.keep +0 -0
- data/apps/worker/.env.sample +0 -9
- data/apps/worker/.gitignore +0 -32
- data/apps/worker/.irbrc +0 -1
- data/apps/worker/.rspec +0 -3
- data/apps/worker/.rubocop.yml +0 -132
- data/apps/worker/.ruby-version +0 -1
- data/apps/worker/CODE_OF_CONDUCT.md +0 -74
- data/apps/worker/Dockerfile +0 -16
- data/apps/worker/Dockerfile.dev +0 -17
- data/apps/worker/Gemfile +0 -49
- data/apps/worker/Gemfile.lock +0 -396
- data/apps/worker/LICENSE.txt +0 -67
- data/apps/worker/Procfile +0 -1
- data/apps/worker/Procfile.dev +0 -1
- data/apps/worker/README.md +0 -37
- data/apps/worker/Rakefile +0 -5
- data/apps/worker/app.rb +0 -101
- data/apps/worker/app/engines/notification_engine.rb +0 -5
- data/apps/worker/app/graphql/mutations/.keep +0 -0
- data/apps/worker/app/graphql/mutations/base_mutation.rb +0 -16
- data/apps/worker/app/graphql/mutations/workers/send_user_mail_job.rb +0 -31
- data/apps/worker/app/graphql/souls_api_schema.rb +0 -43
- data/apps/worker/app/graphql/types/.keep +0 -0
- data/apps/worker/app/graphql/types/base/base_argument.rb +0 -4
- data/apps/worker/app/graphql/types/base/base_enum.rb +0 -4
- data/apps/worker/app/graphql/types/base/base_field.rb +0 -5
- data/apps/worker/app/graphql/types/base/base_input_object.rb +0 -5
- data/apps/worker/app/graphql/types/base/base_interface.rb +0 -7
- data/apps/worker/app/graphql/types/base/base_object.rb +0 -5
- data/apps/worker/app/graphql/types/base/base_scalar.rb +0 -4
- data/apps/worker/app/graphql/types/base/base_union.rb +0 -4
- data/apps/worker/app/graphql/types/base/mutation_type.rb +0 -12
- data/apps/worker/app/graphql/types/base/query_type.rb +0 -6
- data/apps/worker/app/models/article.rb +0 -4
- data/apps/worker/app/models/article_category.rb +0 -3
- data/apps/worker/app/models/user.rb +0 -19
- data/apps/worker/app/utils/fire_store.rb +0 -9
- data/apps/worker/app/utils/souls_helper.rb +0 -96
- data/apps/worker/cloudbuild.yml +0 -32
- data/apps/worker/config.ru +0 -17
- data/apps/worker/config/database.yml +0 -33
- data/apps/worker/config/souls.rb +0 -10
- data/apps/worker/db/migrate/20200006095538_create_users.rb +0 -30
- data/apps/worker/db/migrate/20200712180236_create_article_categories.rb +0 -12
- data/apps/worker/db/migrate/20200714215521_create_articles.rb +0 -22
- data/apps/worker/db/schema.rb +0 -78
- data/apps/worker/db/seeds.rb +0 -44
- data/apps/worker/github/workflows/delivery.yml +0 -81
- data/apps/worker/log/.keep +0 -0
- data/apps/worker/spec/factories/article_categories.rb +0 -9
- data/apps/worker/spec/factories/articles.rb +0 -17
- data/apps/worker/spec/factories/users.rb +0 -23
- data/apps/worker/spec/models/article_category_spec.rb +0 -7
- data/apps/worker/spec/models/article_spec.rb +0 -7
- data/apps/worker/spec/models/user_spec.rb +0 -7
- data/apps/worker/spec/spec_helper.rb +0 -110
- data/apps/worker/tmp/.keep +0 -0
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/config/souls.rb +0 -9
- data/db/schema.rb +0 -67
- data/rbs/init.rbs +0 -2
- data/souls.gemspec +0 -34
- data/souls_api2.tar.gz +0 -0
@@ -1,65 +0,0 @@
|
|
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 graphql_query(mutation: "SendUserMailJob", args: {})
|
18
|
-
if args.blank?
|
19
|
-
%(mutation { #{mutation}(input: {}) {
|
20
|
-
response
|
21
|
-
}
|
22
|
-
})
|
23
|
-
else
|
24
|
-
inputs = ""
|
25
|
-
args.each do |key, value|
|
26
|
-
inputs +=
|
27
|
-
if value.instance_of?(String)
|
28
|
-
"#{key.to_s.underscore.camelize(:lower)}: \"#{value}\" "
|
29
|
-
else
|
30
|
-
"#{key.to_s.underscore.camelize(:lower)}: #{value} "
|
31
|
-
end
|
32
|
-
end
|
33
|
-
%(mutation { #{mutation.to_s.underscore.camelize(:lower)}(input: {#{inputs}}) {
|
34
|
-
response
|
35
|
-
}
|
36
|
-
})
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def check_user_permissions(user, obj, method)
|
41
|
-
raise(StandardError, "Invalid or Missing Token") unless user
|
42
|
-
|
43
|
-
policy_class = obj.class.name + "Policy"
|
44
|
-
policy_clazz = policy_class.constantize.new(user, obj)
|
45
|
-
permission = policy_clazz.public_send(method)
|
46
|
-
raise(Pundit::NotAuthorizedError, "permission error!") unless permission
|
47
|
-
end
|
48
|
-
|
49
|
-
def auth_check(context)
|
50
|
-
raise(GraphQL::ExecutionError, "You need to sign in!!") if context[:user].nil?
|
51
|
-
end
|
52
|
-
|
53
|
-
def get_token(token)
|
54
|
-
JsonWebToken.decode(token)
|
55
|
-
end
|
56
|
-
|
57
|
-
def production?
|
58
|
-
ENV["RACK_ENV"] == "production"
|
59
|
-
end
|
60
|
-
|
61
|
-
def get_instance_id
|
62
|
-
`curl http://metadata.google.internal/computeMetadata/v1/instance/id -H Metadata-Flavor:Google`
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Mutations
|
2
|
-
module Managers::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
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Mutations
|
2
|
-
module Managers::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
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module Mutations
|
2
|
-
module Managers::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
|
@@ -1,13 +0,0 @@
|
|
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
|
@@ -1,13 +0,0 @@
|
|
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
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module Queries
|
2
|
-
class BaseQuery < GraphQL::Schema::Resolver
|
3
|
-
def check_user_permissions(user, obj, method)
|
4
|
-
raise(StandardError, "Invalid or Missing Token") unless user
|
5
|
-
|
6
|
-
policy_class = obj.class.name + "Policy"
|
7
|
-
policy_clazz = policy_class.constantize.new(user, obj)
|
8
|
-
permission = policy_clazz.public_send(method)
|
9
|
-
raise(Pundit::NotAuthorizedError, "permission error!") unless permission
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,13 +0,0 @@
|
|
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
|
@@ -1,41 +0,0 @@
|
|
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
|
@@ -1,57 +0,0 @@
|
|
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
|
@@ -1,17 +0,0 @@
|
|
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
|
@@ -1,63 +0,0 @@
|
|
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
|