Fixed models #268_achievements

This commit is contained in:
Sven Heidemann 2023-06-14 19:56:38 +02:00
parent 7f197a0ea7
commit fdbba1b89c
3 changed files with 48 additions and 15 deletions

View File

@ -37,20 +37,26 @@ class AchievementsMigration(MigrationABC):
self._cursor.execute( self._cursor.execute(
str( str(
f""" f"""
ALTER TABLE Users ADD MessageCount BIGINT NOT NULL DEFAULT 0 AFTER XP; CREATE TABLE IF NOT EXISTS `AchievementsHistory`
ALTER TABLE Users ADD ReactionCount BIGINT NOT NULL DEFAULT 0 AFTER XP; (
`Id` BIGINT(20) NOT NULL,
`ServerId` BIGINT,
`Name` VARCHAR(255) NOT NULL,
`Attribute` VARCHAR(255) NOT NULL,
`Operator` VARCHAR(2) NOT NULL,
`Value` VARCHAR(255) NOT NULL,
`Deleted` BOOL DEFAULT FALSE,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
""" """
) )
) )
self._cursor.execute( self._cursor.execute(str(f"""ALTER TABLE Users ADD MessageCount BIGINT NOT NULL DEFAULT 0 AFTER XP;"""))
str( self._cursor.execute(str(f"""ALTER TABLE Users ADD ReactionCount BIGINT NOT NULL DEFAULT 0 AFTER XP;"""))
f""" self._cursor.execute(str(f"""ALTER TABLE UsersHistory ADD MessageCount BIGINT NOT NULL DEFAULT 0 AFTER XP;"""))
ALTER TABLE UsersHistory ADD MessageCount BIGINT NOT NULL DEFAULT 0 AFTER XP; self._cursor.execute(str(f"""ALTER TABLE UsersHistory ADD ReactionCount BIGINT NOT NULL DEFAULT 0 AFTER XP;"""))
ALTER TABLE UsersHistory ADD ReactionCount BIGINT NOT NULL DEFAULT 0 AFTER XP;
"""
)
)
self._cursor.execute( self._cursor.execute(
str( str(
@ -85,7 +91,8 @@ class AchievementsMigration(MigrationABC):
); );
END; END;
""" """
) ),
multi=True,
) )
def downgrade(self): def downgrade(self):

View File

@ -15,6 +15,8 @@ class User(TableABC):
self, self,
dc_id: int, dc_id: int,
xp: int, xp: int,
message_count: int,
reaction_count: int,
server: Optional[Server], server: Optional[Server],
created_at: datetime = None, created_at: datetime = None,
modified_at: datetime = None, modified_at: datetime = None,
@ -23,6 +25,8 @@ class User(TableABC):
self._user_id = id self._user_id = id
self._discord_id = dc_id self._discord_id = dc_id
self._xp = xp self._xp = xp
self._message_count = message_count
self._reaction_count = reaction_count
self._server = server self._server = server
TableABC.__init__(self) TableABC.__init__(self)
@ -59,6 +63,22 @@ class User(TableABC):
def xp(self, value: int): def xp(self, value: int):
self._xp = value self._xp = value
@property
def message_count(self) -> int:
return self._message_count
@message_count.setter
def message_count(self, value: int):
self._message_count = value
@property
def reaction_count(self) -> int:
return self._reaction_count
@reaction_count.setter
def reaction_count(self, value: int):
self._reaction_count = value
@property @property
@ServiceProviderABC.inject @ServiceProviderABC.inject
def ontime(self, services: ServiceProviderABC) -> float: def ontime(self, services: ServiceProviderABC) -> float:
@ -151,10 +171,12 @@ class User(TableABC):
return str( return str(
f""" f"""
INSERT INTO `Users` ( INSERT INTO `Users` (
`DiscordId`, `XP`, `ServerId` `DiscordId`, `XP`, `MessageCount`, `ReactionCount`, `ServerId`
) VALUES ( ) VALUES (
{self._discord_id}, {self._discord_id},
{self._xp}, {self._xp},
{self._message_count},
{self._reaction_count},
{self._server.id} {self._server.id}
); );
""" """
@ -165,7 +187,9 @@ class User(TableABC):
return str( return str(
f""" f"""
UPDATE `Users` UPDATE `Users`
SET `XP` = {self._xp} SET `XP` = {self._xp},
`MessageCount` = {self._message_count},
`ReactionCount` = {self._reaction_count}
WHERE `UserId` = {self._user_id}; WHERE `UserId` = {self._user_id};
""" """
) )

View File

@ -27,9 +27,11 @@ class UserRepositoryService(UserRepositoryABC):
return User( return User(
result[1], result[1],
result[2], result[2],
self._servers.get_server_by_id(result[3]), result[3],
result[4], result[4],
result[5], self._servers.get_server_by_id(result[5]),
result[6],
result[7],
id=result[0], id=result[0],
) )