Added auto role query #162

This commit is contained in:
Sven Heidemann 2023-01-15 16:24:08 +01:00
parent eb7fce140a
commit 8256ebed71
4 changed files with 100 additions and 0 deletions

View File

@ -10,6 +10,8 @@ from bot_graphql.abc.query_abc import QueryABC
from bot_graphql.graphql_service import GraphQLService from bot_graphql.graphql_service import GraphQLService
from bot_graphql.mutation import Mutation from bot_graphql.mutation import Mutation
from bot_graphql.mutations.level_mutation import LevelMutation from bot_graphql.mutations.level_mutation import LevelMutation
from bot_graphql.queries.auto_role_query import AutoRoleQuery
from bot_graphql.queries.auto_role_rule_query import AutoRoleRuleQuery
from bot_graphql.queries.client_query import ClientQuery from bot_graphql.queries.client_query import ClientQuery
from bot_graphql.queries.level_query import LevelQuery from bot_graphql.queries.level_query import LevelQuery
from bot_graphql.queries.server_query import ServerQuery from bot_graphql.queries.server_query import ServerQuery
@ -39,5 +41,7 @@ class GraphQLModule(ModuleABC):
services.add_transient(QueryABC, UserQuery) services.add_transient(QueryABC, UserQuery)
services.add_transient(QueryABC, UserJoinedServerQuery) services.add_transient(QueryABC, UserJoinedServerQuery)
services.add_transient(QueryABC, UserJoinedVoiceChannelQuery) services.add_transient(QueryABC, UserJoinedVoiceChannelQuery)
services.add_transient(QueryABC, AutoRoleQuery)
services.add_transient(QueryABC, AutoRoleRuleQuery)
services.add_transient(SeederService) services.add_transient(SeederService)

View File

@ -62,6 +62,29 @@ type Client implements TableQuery {
modified_at: String modified_at: String
} }
type AutoRole implements TableQuery {
id: ID
channel_id: String
message_id: String
server: Server
rules: [AutoRoleRule]
created_at: String
modified_at: String
}
type AutoRoleRule implements TableQuery {
id: ID
emoji_name: String
role_id: String
auto_role: AutoRole
created_at: String
modified_at: String
}
input UserFilter { input UserFilter {
id: ID id: ID
discord_id: String discord_id: String

View File

@ -0,0 +1,40 @@
from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.model.auto_role import AutoRole
from bot_graphql.abc.data_query_abc import DataQueryABC
class AutoRoleQuery(DataQueryABC):
def __init__(
self,
auto_role_rules: AutoRoleRepositoryABC,
servers: ServerRepositoryABC,
):
DataQueryABC.__init__(self, "AutoRole")
self._auto_role_rules = auto_role_rules
self._servers = servers
self.set_field("id", self.resolve_id)
self.set_field("channel_id", self.resolve_channel_id)
self.set_field("message_id", self.resolve_message_id)
self.set_field("server", self.resolve_server)
self.set_field("rules", self.resolve_rules)
@staticmethod
def resolve_id(x: AutoRole, *_):
return x.auto_role_id
@staticmethod
def resolve_channel_id(x: AutoRole, *_):
return x.discord_channel_id
@staticmethod
def resolve_message_id(x: AutoRole, *_):
return x.discord_message_id
def resolve_server(self, x: AutoRole, *_):
return self._servers.get_server_by_id(x.server_id)
def resolve_rules(self, x: AutoRole, *_):
return self._auto_role_rules.get_auto_role_rules_by_auto_role_id(x.auto_role_id)

View File

@ -0,0 +1,33 @@
from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
from bot_data.model.auto_role_rule import AutoRoleRule
from bot_graphql.abc.data_query_abc import DataQueryABC
class AutoRoleRuleQuery(DataQueryABC):
def __init__(
self,
auto_roles: AutoRoleRepositoryABC,
):
DataQueryABC.__init__(self, "AutoRoleRule")
self._auto_roles = auto_roles
self.set_field("id", self.resolve_id)
self.set_field("emoji_name", self.resolve_emoji_name)
self.set_field("role_id", self.resolve_role_id)
self.set_field("auto_role", self.resolve_auto_role)
@staticmethod
def resolve_id(x: AutoRoleRule, *_):
return x.auto_role_rule_id
@staticmethod
def resolve_emoji_name(x: AutoRoleRule, *_):
return x.emoji_name
@staticmethod
def resolve_role_id(x: AutoRoleRule, *_):
return x.role_id
def resolve_auto_role(self, x: AutoRoleRule, *_):
return self._auto_roles.get_auto_role_by_id(x.auto_role_id)