From f7297ddf789f7a796be13040a36c25e0539e6eeb Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sat, 15 Jul 2023 15:47:40 +0200 Subject: [PATCH] Added history for achievements to frontend #268_achievements --- .../migration/achievements_migration.py | 2 +- .../src/bot_data/model/achievement_history.py | 26 +++++-------------- kdb-bot/src/bot_data/model/user_history.py | 12 +++++++++ kdb-bot/src/bot_graphql/graphql_module.py | 2 ++ kdb-bot/src/bot_graphql/model/achievement.gql | 2 +- .../queries/achievement_history_query.py | 13 ++++++++++ .../bot_graphql/queries/achievement_query.py | 4 +-- kdb-web/src/assets/i18n/de.json | 5 +++- kdb-web/src/assets/i18n/en.json | 5 +++- 9 files changed, 45 insertions(+), 26 deletions(-) create mode 100644 kdb-bot/src/bot_graphql/queries/achievement_history_query.py diff --git a/kdb-bot/src/bot_data/migration/achievements_migration.py b/kdb-bot/src/bot_data/migration/achievements_migration.py index d9851cb5..eb6933ec 100644 --- a/kdb-bot/src/bot_data/migration/achievements_migration.py +++ b/kdb-bot/src/bot_data/migration/achievements_migration.py @@ -40,11 +40,11 @@ class AchievementsMigration(MigrationABC): CREATE TABLE IF NOT EXISTS `AchievementsHistory` ( `Id` BIGINT(20) NOT NULL, - `ServerId` BIGINT, `Name` VARCHAR(255) NOT NULL, `Attribute` VARCHAR(255) NOT NULL, `Operator` VARCHAR(255) NOT NULL, `Value` VARCHAR(255) NOT NULL, + `ServerId` BIGINT, `Deleted` BOOL DEFAULT FALSE, `DateFrom` DATETIME(6) NOT NULL, `DateTo` DATETIME(6) NOT NULL diff --git a/kdb-bot/src/bot_data/model/achievement_history.py b/kdb-bot/src/bot_data/model/achievement_history.py index 74208075..2fd5d218 100644 --- a/kdb-bot/src/bot_data/model/achievement_history.py +++ b/kdb-bot/src/bot_data/model/achievement_history.py @@ -1,20 +1,14 @@ -from datetime import datetime -from typing import Optional - -from cpl_core.database import TableABC - from bot_data.abc.history_table_abc import HistoryTableABC -from bot_data.model.server import Server -class Achievement(HistoryTableABC): +class AchievementHistory(HistoryTableABC): def __init__( self, name: str, attribute: str, operator: str, value: str, - server: Optional[Server], + server: int, deleted: bool, date_from: str, date_to: str, @@ -41,26 +35,18 @@ class Achievement(HistoryTableABC): def name(self) -> str: return self._name - @name.setter - def name(self, value: str): - self._name = value + @property + def attribute(self) -> str: + return self._attribute @property def operator(self) -> str: return self._operator - @operator.setter - def operator(self, value: str): - self._operator = value - @property def value(self) -> str: return self._value - @value.setter - def value(self, value: str): - self._value = value - @property - def server(self) -> Server: + def server(self) -> int: return self._server diff --git a/kdb-bot/src/bot_data/model/user_history.py b/kdb-bot/src/bot_data/model/user_history.py index d3b88ca7..2bf39954 100644 --- a/kdb-bot/src/bot_data/model/user_history.py +++ b/kdb-bot/src/bot_data/model/user_history.py @@ -9,6 +9,8 @@ class UserHistory(HistoryTableABC): self, dc_id: int, xp: int, + message_count: int, + reaction_count: int, server: int, deleted: bool, date_from: str, @@ -20,6 +22,8 @@ class UserHistory(HistoryTableABC): self._user_id = id self._discord_id = dc_id self._xp = xp + self._message_count = message_count + self._reaction_count = reaction_count self._server = server self._deleted = deleted @@ -38,6 +42,14 @@ class UserHistory(HistoryTableABC): def xp(self) -> int: return self._xp + @property + def message_count(self) -> int: + return self._message_count + + @property + def reaction_count(self) -> int: + return self._reaction_count + @property def server(self) -> int: return self._server diff --git a/kdb-bot/src/bot_graphql/graphql_module.py b/kdb-bot/src/bot_graphql/graphql_module.py index 5e54b86d..480b4abc 100644 --- a/kdb-bot/src/bot_graphql/graphql_module.py +++ b/kdb-bot/src/bot_graphql/graphql_module.py @@ -27,6 +27,7 @@ from bot_graphql.mutations.level_mutation import LevelMutation from bot_graphql.mutations.user_joined_game_server_mutation import UserJoinedGameServerMutation from bot_graphql.mutations.user_mutation import UserMutation from bot_graphql.queries.achievement_attribute_query import AchievementAttributeQuery +from bot_graphql.queries.achievement_history_query import AchievementHistoryQuery from bot_graphql.queries.achievement_query import AchievementQuery from bot_graphql.queries.auto_role_history_query import AutoRoleHistoryQuery from bot_graphql.queries.auto_role_query import AutoRoleQuery @@ -69,6 +70,7 @@ class GraphQLModule(ModuleABC): # queries services.add_transient(QueryABC, AchievementAttributeQuery) services.add_transient(QueryABC, AchievementQuery) + services.add_transient(QueryABC, AchievementHistoryQuery) services.add_transient(QueryABC, AutoRoleHistoryQuery) services.add_transient(QueryABC, AutoRoleQuery) services.add_transient(QueryABC, AutoRoleRuleHistoryQuery) diff --git a/kdb-bot/src/bot_graphql/model/achievement.gql b/kdb-bot/src/bot_graphql/model/achievement.gql index 7cd86cf9..a49cdae9 100644 --- a/kdb-bot/src/bot_graphql/model/achievement.gql +++ b/kdb-bot/src/bot_graphql/model/achievement.gql @@ -28,7 +28,7 @@ type AchievementHistory implements HistoryTableQuery { operator: String value: String - server: Server + server: ID deleted: Boolean dateFrom: String diff --git a/kdb-bot/src/bot_graphql/queries/achievement_history_query.py b/kdb-bot/src/bot_graphql/queries/achievement_history_query.py new file mode 100644 index 00000000..f8a8eddf --- /dev/null +++ b/kdb-bot/src/bot_graphql/queries/achievement_history_query.py @@ -0,0 +1,13 @@ +from bot_graphql.abc.history_query_abc import HistoryQueryABC + + +class AchievementHistoryQuery(HistoryQueryABC): + def __init__(self): + HistoryQueryABC.__init__(self, "Achievement") + + self.set_field("id", lambda x, *_: x.id) + self.set_field("name", lambda x, *_: x.name) + self.set_field("attribute", lambda x, *_: x.attribute) + self.set_field("operator", lambda x, *_: x.operator) + self.set_field("value", lambda x, *_: x.value) + self.set_field("server", lambda x, *_: x.server) diff --git a/kdb-bot/src/bot_graphql/queries/achievement_query.py b/kdb-bot/src/bot_graphql/queries/achievement_query.py index 46ee137d..e64ff3db 100644 --- a/kdb-bot/src/bot_graphql/queries/achievement_query.py +++ b/kdb-bot/src/bot_graphql/queries/achievement_query.py @@ -1,6 +1,6 @@ from cpl_core.database.context import DatabaseContextABC -from bot_data.model.user_history import UserHistory +from bot_data.model.achievement_history import AchievementHistory from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC @@ -9,7 +9,7 @@ class AchievementQuery(DataQueryWithHistoryABC): self, db: DatabaseContextABC, ): - DataQueryWithHistoryABC.__init__(self, "Achievement", "AchievementsHistory", UserHistory, db) + DataQueryWithHistoryABC.__init__(self, "Achievement", "AchievementsHistory", AchievementHistory, db) self.set_field("id", lambda x, *_: x.id) self.set_field("name", lambda x, *_: x.name) diff --git a/kdb-web/src/assets/i18n/de.json b/kdb-web/src/assets/i18n/de.json index 6bcc1328..e8d1bde5 100644 --- a/kdb-web/src/assets/i18n/de.json +++ b/kdb-web/src/assets/i18n/de.json @@ -147,7 +147,10 @@ "permissions": "Berechtigung", "roleId": "Rolle", "server": "Server", - "xp": "XP" + "xp": "XP", + "attribute": "Attribut", + "operator": "Operator", + "value": "Wert" }, "id": "Id", "joined_at": "Beigetreten am", diff --git a/kdb-web/src/assets/i18n/en.json b/kdb-web/src/assets/i18n/en.json index 862fcf4a..b4e584ad 100644 --- a/kdb-web/src/assets/i18n/en.json +++ b/kdb-web/src/assets/i18n/en.json @@ -147,7 +147,10 @@ "permissions": "Permissions", "roleId": "Role", "server": "Server", - "xp": "XP" + "xp": "XP", + "attribute": "Attribute", + "operator": "Operator", + "value": "Value" }, "id": "Id", "joined_at": "Joined at",