Added add dialog #410

This commit is contained in:
2023-11-18 22:15:18 +01:00
parent a3ebd07093
commit 74dba4b981
25 changed files with 504 additions and 278 deletions

View File

@@ -63,7 +63,9 @@ class FilterABC(ABC):
self.__setattr__(f"_{attr}", attr_type(values[attr]))
@staticmethod
def _filter_by_attributes(attrs: list[Callable], values: List[T]) -> List[R]:
def _filter_by_attributes(attrs: list[dict], values: List[T]) -> List[R]:
for attr in attrs:
values = values.where(attr)
if attr["attr"] is None:
continue
values = values.where(attr["func"])
return values

View File

@@ -51,15 +51,15 @@ class ScheduledEventFilter(FilterABC):
query = self._filter_by_attributes(
[
lambda x: x.id == self._id,
lambda x: x.interval == self._interval,
lambda x: x.name == self._name,
lambda x: x.description == self._description,
lambda x: x.channel_id == self._channel_id,
lambda x: x.start_time == self._start_time,
lambda x: x.end_time == self._end_time,
lambda x: x.entity_type == self._entity_type,
lambda x: x.location == self._location,
{"attr": self._id, "func": lambda x: x.id == self._id},
{"attr": self._interval, "func": lambda x: x.interval == self._interval},
{"attr": self._name, "func": lambda x: x.name == self._name},
{"attr": self._description, "func": lambda x: x.description == self._description},
{"attr": self._channel_id, "func": lambda x: x.channel_id == self._channel_id},
{"attr": self._start_time, "func": lambda x: x.start_time == self._start_time},
{"attr": self._end_time, "func": lambda x: x.end_time == self._end_time},
{"attr": self._entity_type, "func": lambda x: x.entity_type == self._entity_type},
{"attr": self._location, "func": lambda x: x.location == self._location},
],
query,
)

View File

@@ -4,6 +4,7 @@ from bot_graphql.mutations.achievement_mutation import AchievementMutation
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.scheduled_event_mutation import ScheduledEventMutation
from bot_graphql.mutations.server_config_mutation import ServerConfigMutation
from bot_graphql.mutations.short_role_name_mutation import ShortRoleNameMutation
from bot_graphql.mutations.technician_config_mutation import TechnicianConfigMutation
@@ -23,6 +24,7 @@ class Mutation(MutationType):
achievement_mutation: AchievementMutation,
user_joined_game_server: UserJoinedGameServerMutation,
technician_config: TechnicianConfigMutation,
scheduled_event: ScheduledEventMutation,
server_config: ServerConfigMutation,
short_role_name_mutation: ShortRoleNameMutation,
):
@@ -36,4 +38,5 @@ class Mutation(MutationType):
self.set_field("userJoinedGameServer", lambda *_: user_joined_game_server)
self.set_field("shortRoleName", lambda *_: short_role_name_mutation)
self.set_field("technicianConfig", lambda *_: technician_config)
self.set_field("scheduledEvent", lambda *_: scheduled_event)
self.set_field("serverConfig", lambda *_: server_config)

View File

@@ -1,9 +1,12 @@
from datetime import datetime
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.scheduled_event_repository_abc import ScheduledEventRepositoryABC
from bot_data.model.scheduled_event import ScheduledEvent
from bot_data.model.scheduled_event_interval_enum import ScheduledEventIntervalEnum
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
@@ -35,14 +38,14 @@ class ScheduledEventMutation(QueryABC):
self._can_user_mutate_data(server, UserRoleEnum.moderator)
scheduled_event = ScheduledEvent(
input["interval"],
ScheduledEventIntervalEnum(input["interval"]),
input["name"],
input["description"],
input["channel_id"],
input["start_time"],
input["end_time"],
input["entity_type"],
input["location"],
input["description"] if "description" in input else None,
input["channelId"] if "channelId" in input else None,
datetime.strptime(input["startTime"], "%Y-%m-%dT%H:%M:%S.%fZ"),
datetime.strptime(input["endTime"], "%Y-%m-%dT%H:%M:%S.%fZ") if "endTime" in input else None,
input["entityType"],
input["location"] if "location" in input else None,
server,
)
@@ -70,10 +73,10 @@ class ScheduledEventMutation(QueryABC):
scheduled_event.interval = input["interval"] if "interval" in input else scheduled_event.interval
scheduled_event.name = input["name"] if "name" in input else scheduled_event.name
scheduled_event.description = input["description"] if "description" in input else scheduled_event.description
scheduled_event.channel_id = input["channel_id"] if "channel_id" in input else scheduled_event.channel_id
scheduled_event.start_time = input["start_time"] if "start_time" in input else scheduled_event.start_time
scheduled_event.end_time = input["end_time"] if "end_time" in input else scheduled_event.end_time
scheduled_event.entity_type = input["entity_type"] if "entity_type" in input else scheduled_event.entity_type
scheduled_event.channel_id = input["channelId"] if "channelId" in input else scheduled_event.channel_id
scheduled_event.start_time = input["startTime"] if "startTime" in input else scheduled_event.start_time
scheduled_event.end_time = input["endTime"] if "endTime" in input else scheduled_event.end_time
scheduled_event.entity_type = input["entityType"] if "entityType" in input else scheduled_event.entity_type
scheduled_event.location = input["location"] if "location" in input else scheduled_event.location
self._scheduled_events.update_scheduled_event(scheduled_event)