Added technician config queries #127
This commit is contained in:
@@ -42,6 +42,10 @@ from bot_graphql.queries.level_history_query import LevelHistoryQuery
|
||||
from bot_graphql.queries.level_query import LevelQuery
|
||||
from bot_graphql.queries.server_history_query import ServerHistoryQuery
|
||||
from bot_graphql.queries.server_query import ServerQuery
|
||||
from bot_graphql.queries.technician_config_history_query import TechnicianConfigHistoryQuery
|
||||
from bot_graphql.queries.technician_config_query import TechnicianConfigQuery
|
||||
from bot_graphql.queries.technician_id_config_history_query import TechnicianIdConfigHistoryQuery
|
||||
from bot_graphql.queries.technician_ping_url_config_history_query import TechnicianPingUrlConfigHistoryQuery
|
||||
from bot_graphql.queries.user_history_query import UserHistoryQuery
|
||||
from bot_graphql.queries.user_joined_game_server_history_query import UserJoinedGameServerHistoryQuery
|
||||
from bot_graphql.queries.user_joined_game_server_query import UserJoinedGameServerQuery
|
||||
@@ -83,6 +87,10 @@ class GraphQLModule(ModuleABC):
|
||||
services.add_transient(QueryABC, LevelQuery)
|
||||
services.add_transient(QueryABC, ServerHistoryQuery)
|
||||
services.add_transient(QueryABC, ServerQuery)
|
||||
services.add_transient(QueryABC, TechnicianConfigQuery)
|
||||
services.add_transient(QueryABC, TechnicianConfigHistoryQuery)
|
||||
services.add_transient(QueryABC, TechnicianPingUrlConfigHistoryQuery)
|
||||
services.add_transient(QueryABC, TechnicianIdConfigHistoryQuery)
|
||||
services.add_transient(QueryABC, GameServerQuery)
|
||||
services.add_transient(QueryABC, UserHistoryQuery)
|
||||
services.add_transient(QueryABC, UserQuery)
|
||||
|
62
kdb-bot/src/bot_graphql/model/config_technician.gql
Normal file
62
kdb-bot/src/bot_graphql/model/config_technician.gql
Normal file
@@ -0,0 +1,62 @@
|
||||
type TechnicianConfig implements TableWithHistoryQuery {
|
||||
id: ID
|
||||
helpCommandReferenceUrl: String
|
||||
waitForRestart: Int
|
||||
waitForShutdown: Int
|
||||
cacheMaxMessages: Int
|
||||
pingURLs: [String]
|
||||
technicianIds: [String]
|
||||
|
||||
createdAt: String
|
||||
modifiedAt: String
|
||||
|
||||
history: [TechnicianConfigHistory]
|
||||
pingURLHistory: [TechnicianPingUrlConfigHistory]
|
||||
technicianIdHistory: [TechnicianIdConfigHistory]
|
||||
}
|
||||
|
||||
type TechnicianConfigHistory implements HistoryTableQuery {
|
||||
id: ID
|
||||
helpCommandReferenceUrl: String
|
||||
waitForRestart: Int
|
||||
waitForShutdown: Int
|
||||
cacheMaxMessages: Int
|
||||
|
||||
deleted: Boolean
|
||||
dateFrom: String
|
||||
dateTo: String
|
||||
}
|
||||
|
||||
type TechnicianPingUrlConfigHistory implements HistoryTableQuery {
|
||||
id: ID
|
||||
url: String
|
||||
|
||||
deleted: Boolean
|
||||
dateFrom: String
|
||||
dateTo: String
|
||||
}
|
||||
|
||||
type TechnicianIdConfigHistory implements HistoryTableQuery {
|
||||
id: ID
|
||||
technicianId: String
|
||||
|
||||
deleted: Boolean
|
||||
dateFrom: String
|
||||
dateTo: String
|
||||
}
|
||||
|
||||
type TechnicianConfigMutation {
|
||||
createTechnicianConfig(input: TechnicianConfigInput!): TechnicianConfig
|
||||
updateTechnicianConfig(input: TechnicianConfigInput!): TechnicianConfig
|
||||
deleteTechnicianConfig(id: ID): TechnicianConfig
|
||||
}
|
||||
|
||||
input TechnicianConfigInput {
|
||||
id: ID
|
||||
helpCommandReferenceUrl: String
|
||||
waitForRestart: Int
|
||||
waitForShutdown: Int
|
||||
cacheMaxMessages: Int
|
||||
pingURLs: [String]
|
||||
technicianIds: [String]
|
||||
}
|
@@ -37,5 +37,7 @@ type Query {
|
||||
achievementAttributes: [AchievementAttribute]
|
||||
achievementOperators: [String]
|
||||
|
||||
technicianConfig: TechnicianConfig
|
||||
|
||||
guilds(filter: GuildFilter): [Guild]
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
|
||||
from bot_data.model.technician_config import TechnicianConfig
|
||||
from bot_data.model.user_role_enum import UserRoleEnum
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
|
||||
|
||||
class TechnicianConfigMutation(QueryABC):
|
||||
def __init__(
|
||||
self,
|
||||
bot: DiscordBotServiceABC,
|
||||
servers: ServerRepositoryABC,
|
||||
technician_configs: TechnicianConfigRepositoryABC,
|
||||
db: DatabaseContextABC,
|
||||
):
|
||||
QueryABC.__init__(self, "TechnicianConfigMutation")
|
||||
|
||||
self._bot = bot
|
||||
self._servers = servers
|
||||
self._technician_configs = technician_configs
|
||||
self._db = db
|
||||
|
||||
self.set_field("createTechnicianConfig", self.resolve_create_TechnicianConfig)
|
||||
self.set_field("updateTechnicianConfig", self.resolve_update_TechnicianConfig)
|
||||
self.set_field("deleteTechnicianConfig", self.resolve_delete_TechnicianConfig)
|
||||
|
||||
def resolve_create_technician_config(self, *_, input: dict):
|
||||
if self._technician_configs.does_technician_config_exists():
|
||||
return None
|
||||
|
||||
technician_config = TechnicianConfig(
|
||||
input["helpCommandReferenceUrl"],
|
||||
input["waitForRestart"],
|
||||
input["waitForShutdown"],
|
||||
input["cacheMaxMessages"],
|
||||
input["pingURLs"],
|
||||
input["technicianIds"],
|
||||
)
|
||||
self._technician_configs.add_technician_config(technician_config)
|
||||
self._db.save_changes()
|
||||
|
||||
return self._technician_configs.get_technician_config()
|
||||
|
||||
def resolve_update_technician_config(self, *_, input: dict):
|
||||
technician_config = self._technician_configs.get_technician_config()
|
||||
self._can_user_mutate_data(technician_config, UserRoleEnum.admin)
|
||||
|
||||
technician_config.name = input["name"] if "name" in input else technician_config.name
|
||||
|
||||
self._technician_configs.update_TechnicianConfig(technician_config)
|
||||
self._db.save_changes()
|
||||
|
||||
technician_config = self._technician_configs.get_TechnicianConfig_by_id(input["id"])
|
||||
return technician_config
|
||||
|
||||
def resolve_delete_technician_config(self, *_, id: int):
|
||||
technician_config = self._technician_configs.get_TechnicianConfig_by_id(id)
|
||||
self._can_user_mutate_data(technician_config.server, UserRoleEnum.admin)
|
||||
|
||||
self._technician_configs.delete_TechnicianConfig(technician_config)
|
||||
self._db.save_changes()
|
||||
|
||||
return technician_config
|
@@ -0,0 +1,11 @@
|
||||
from bot_graphql.abc.history_query_abc import HistoryQueryABC
|
||||
|
||||
|
||||
class TechnicianConfigHistoryQuery(HistoryQueryABC):
|
||||
def __init__(self):
|
||||
HistoryQueryABC.__init__(self, "TechnicianConfig")
|
||||
|
||||
self.set_field("helpCommandReferenceUrl", lambda config, *_: config.help_command_reference_url)
|
||||
self.set_field("waitForRestart", lambda config, *_: config.wait_for_restart)
|
||||
self.set_field("waitForShutdown", lambda config, *_: config.wait_for_shutdown)
|
||||
self.set_field("cacheMaxMessages", lambda config, *_: config.cache_max_messages)
|
57
kdb-bot/src/bot_graphql/queries/technician_config_query.py
Normal file
57
kdb-bot/src/bot_graphql/queries/technician_config_query.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.abc.table_with_id_abc import TableWithIdABC
|
||||
from bot_data.model.technician_config_history import TechnicianConfigHistory
|
||||
from bot_data.model.technician_id_config_history import TechnicianIdConfigHistory
|
||||
from bot_data.model.technician_ping_url_config_history import TechnicianPingUrlConfigHistory
|
||||
from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC
|
||||
|
||||
|
||||
class TechnicianConfigQuery(DataQueryWithHistoryABC):
|
||||
def __init__(self, db: DatabaseContextABC):
|
||||
DataQueryWithHistoryABC.__init__(self, "TechnicianConfig", "CFG_TechnicianHistory", TechnicianConfigHistory, db)
|
||||
|
||||
self.set_field("helpCommandReferenceUrl", lambda config, *_: config.help_command_reference_url)
|
||||
self.set_field("waitForRestart", lambda config, *_: config.wait_for_restart)
|
||||
self.set_field("waitForShutdown", lambda config, *_: config.wait_for_shutdown)
|
||||
self.set_field("cacheMaxMessages", lambda config, *_: config.cache_max_messages)
|
||||
self.set_field("pingURLs", lambda config, *_: config.ping_urls)
|
||||
self.set_field("technicianIds", lambda config, *_: config.technician_ids)
|
||||
|
||||
self.set_field("pingURLHistory", self.resolve_ping_url_history)
|
||||
self.set_field("technicianIdHistory", self.resolve_technician_id_history)
|
||||
|
||||
def resolve_ping_url_history(self, entry: TableWithIdABC, *_):
|
||||
history = List(TechnicianPingUrlConfigHistory)
|
||||
|
||||
results = self._db.select(
|
||||
f"""
|
||||
SELECT *
|
||||
FROM CFG_TechnicianPingUrlsHistory
|
||||
WHERE Id = {entry.id}
|
||||
ORDER BY DateTo DESC;
|
||||
"""
|
||||
)
|
||||
|
||||
for result in results:
|
||||
history.add(TechnicianPingUrlConfigHistory(*result[1:], result[0]))
|
||||
|
||||
return history
|
||||
|
||||
def resolve_technician_id_history(self, entry: TableWithIdABC, *_):
|
||||
history = List(TechnicianIdConfigHistory)
|
||||
|
||||
results = self._db.select(
|
||||
f"""
|
||||
SELECT *
|
||||
FROM CFG_TechnicianIdsHistory
|
||||
WHERE Id = {entry.id}
|
||||
ORDER BY DateTo DESC;
|
||||
"""
|
||||
)
|
||||
|
||||
for result in results:
|
||||
history.add(TechnicianIdConfigHistory(*result[1:], result[0]))
|
||||
|
||||
return history
|
@@ -0,0 +1,8 @@
|
||||
from bot_graphql.abc.history_query_abc import HistoryQueryABC
|
||||
|
||||
|
||||
class TechnicianIdConfigHistoryQuery(HistoryQueryABC):
|
||||
def __init__(self):
|
||||
HistoryQueryABC.__init__(self, "TechnicianIdConfig")
|
||||
|
||||
self.set_field("technicianId", lambda config, *_: config.technicianId)
|
@@ -0,0 +1,8 @@
|
||||
from bot_graphql.abc.history_query_abc import HistoryQueryABC
|
||||
|
||||
|
||||
class TechnicianPingUrlConfigHistoryQuery(HistoryQueryABC):
|
||||
def __init__(self):
|
||||
HistoryQueryABC.__init__(self, "TechnicianPingUrlConfig")
|
||||
|
||||
self.set_field("url", lambda config, *_: config.ping_url)
|
@@ -7,6 +7,7 @@ from bot_data.abc.game_server_repository_abc import GameServerRepositoryABC
|
||||
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
||||
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
|
||||
from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC
|
||||
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||
from bot_data.abc.user_joined_voice_channel_repository_abc import UserJoinedVoiceChannelRepositoryABC
|
||||
@@ -41,6 +42,7 @@ class Query(QueryABC):
|
||||
users: UserRepositoryABC,
|
||||
achievements: AchievementRepositoryABC,
|
||||
achievement_service: AchievementService,
|
||||
technician_config: TechnicianConfigRepositoryABC,
|
||||
):
|
||||
QueryABC.__init__(self, "Query")
|
||||
|
||||
@@ -68,6 +70,7 @@ class Query(QueryABC):
|
||||
)
|
||||
self.add_collection("user", lambda *_: users.get_users(), UserFilter)
|
||||
self.add_collection("achievement", lambda *_: achievements.get_achievements(), AchievementFilter)
|
||||
self.set_field("technicianConfig", lambda *_: technician_config.get_technician_config())
|
||||
|
||||
self.set_field("guilds", self._resolve_guilds)
|
||||
self.set_field("achievementAttributes", lambda x, *_: achievement_service.get_attributes())
|
||||
|
Reference in New Issue
Block a user