Added history for achievements to frontend #268_achievements

This commit is contained in:
Sven Heidemann 2023-07-15 15:47:40 +02:00
parent eb3715d00b
commit f7297ddf78
9 changed files with 45 additions and 26 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -28,7 +28,7 @@ type AchievementHistory implements HistoryTableQuery {
operator: String
value: String
server: Server
server: ID
deleted: Boolean
dateFrom: String

View File

@ -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)

View File

@ -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)

View File

@ -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",

View File

@ -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",