1.0.0 #253

Merged
edraft merged 262 commits from 1.0.0 into master 2023-03-27 09:30:50 +02:00
6 changed files with 91 additions and 23 deletions
Showing only changes of commit bd4e088032 - Show all commits

View File

@ -101,7 +101,7 @@ class UserJoinedGameServer(TableABC):
`UserId`, `GameServer`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
) VALUES (
{self._user.user_id},
{self._game_server},
'{self._game_server}',
'{self._joined_on}',
'{self._leaved_on}',
'{self._created_at}',
@ -116,7 +116,7 @@ class UserJoinedGameServer(TableABC):
`UserId`, `GameServer`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
) VALUES (
{self._user.user_id},
{self._game_server},
'{self._game_server}',
'{self._joined_on}',
'{self._created_at}',
'{self._modified_at}'

View File

@ -22,6 +22,7 @@ from bot_graphql.mutation import Mutation
from bot_graphql.mutations.auto_role_mutation import AutoRoleMutation
from bot_graphql.mutations.auto_role_rule_mutation import AutoRoleRuleMutation
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.auto_role_query import AutoRoleQuery
from bot_graphql.queries.auto_role_rule_query import AutoRoleRuleQuery
@ -78,5 +79,6 @@ class GraphQLModule(ModuleABC):
services.add_transient(QueryABC, AutoRoleRuleMutation)
services.add_transient(QueryABC, LevelMutation)
services.add_transient(QueryABC, UserMutation)
services.add_transient(QueryABC, UserJoinedGameServerMutation)
services.add_transient(SeederService)

View File

@ -3,4 +3,5 @@ type Mutation {
autoRoleRule: AutoRoleRuleMutation
level: LevelMutation
user: UserMutation
userJoinedGameServer: UserJoinedGameServerMutation
}

View File

@ -15,4 +15,16 @@ input UserJoinedGameServerFilter {
user: UserFilter
joinedOn: String
leavedOn: String
}
type UserJoinedGameServerMutation {
userJoined(input: UserJoinedGameServerInput!): UserJoinedGameServer
userLeaved(input: UserJoinedGameServerInput!): UserJoinedGameServer
}
input UserJoinedGameServerInput {
gameServer: String!
userId: ID!
joinedOn: String
leavedOn: String
}

View File

@ -1,8 +1,10 @@
from ariadne import MutationType
from bot_data.model.user_joined_game_server import UserJoinedGameServer
from bot_graphql.mutations.auto_role_mutation import AutoRoleMutation
from bot_graphql.mutations.auto_role_rule_mutation import AutoRoleRuleMutation
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
@ -13,27 +15,12 @@ class Mutation(MutationType):
auto_role_rule_mutation: AutoRoleRuleMutation,
level_mutation: LevelMutation,
user_mutation: UserMutation,
user_joined_game_server: UserJoinedGameServerMutation,
):
MutationType.__init__(self)
self._auto_role_mutation = auto_role_mutation
self._auto_role_rule_mutation = auto_role_rule_mutation
self._level_mutation = level_mutation
self._user_mutation = user_mutation
self.set_field("autoRole", self.resolve_auto_role)
self.set_field("autoRoleRule", self.resolve_auto_role_rule)
self.set_field("level", self.resolve_level)
self.set_field("user", self.resolve_user)
def resolve_auto_role(self, *_):
return self._auto_role_mutation
def resolve_auto_role_rule(self, *_):
return self._auto_role_rule_mutation
def resolve_level(self, *_):
return self._level_mutation
def resolve_user(self, *_):
return self._user_mutation
self.set_field("autoRole", lambda *_: auto_role_mutation)
self.set_field("autoRoleRule", lambda *_: auto_role_rule_mutation)
self.set_field("level", lambda *_: level_mutation)
self.set_field("user", lambda *_: user_mutation)
self.set_field("userJoinedGameServer", lambda *_: user_joined_game_server)

View File

@ -0,0 +1,66 @@
from cpl_core.database.context import DatabaseContextABC
from cpl_core.logging import LoggerABC
from cpl_discord.service import DiscordBotServiceABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC
from bot_data.abc.user_repository_abc import UserRepositoryABC
from bot_data.model.user_joined_game_server import UserJoinedGameServer
from bot_data.model.user_role_enum import UserRoleEnum
from bot_graphql.abc.query_abc import QueryABC
from modules.permission.service.permission_service import PermissionService
class UserJoinedGameServerMutation(QueryABC):
def __init__(
self,
logger: LoggerABC,
servers: ServerRepositoryABC,
users: UserRepositoryABC,
user_joined_game_servers: UserJoinedGameServerRepositoryABC,
bot: DiscordBotServiceABC,
db: DatabaseContextABC,
permissions: PermissionService,
):
QueryABC.__init__(self, "UserJoinedGameServerMutation")
self._logger = logger
self._servers = servers
self._users = users
self._user_joined_game_servers = user_joined_game_servers
self._bot = bot
self._db = db
self._permissions = permissions
self.set_field("userJoined", self.resolve_user_joined)
self.set_field("userLeaved", self.resolve_user_leaved)
def resolve_user_joined(self, *_, input: dict):
user = self._users.get_user_by_id(input["userId"])
self._can_user_mutate_data(user.server, UserRoleEnum.admin)
active = self._user_joined_game_servers.find_active_user_joined_game_server_by_user_id(user.user_id)
if active is not None:
self._logger.debug(
__name__,
f"Skip UserJoinedGameServer for user {user.user_id}. User already plays on {active.game_server}.",
)
return
new = UserJoinedGameServer(user, input["gameServer"], input["joinedOn"])
self._user_joined_game_servers.add_user_joined_game_server(new)
self._db.save_changes()
return self._user_joined_game_servers.get_active_user_joined_game_server_by_user_id(user.user_id)
def resolve_user_leaved(self, *_, input: dict):
user = self._users.get_user_by_id(input["userId"])
self._can_user_mutate_data(user.server, UserRoleEnum.admin)
active = self._user_joined_game_servers.get_active_user_joined_game_server_by_user_id(user.user_id)
active.leaved_on = input["leavedOn"]
self._user_joined_game_servers.update_user_joined_game_server(active)
self._db.save_changes()
return active