Improved level stuff #162
This commit is contained in:
parent
552e686aeb
commit
b8484185e9
@ -16,6 +16,9 @@ class LevelFilter(FilterABC):
|
|||||||
if "id" in values:
|
if "id" in values:
|
||||||
self._id = values["id"]
|
self._id = values["id"]
|
||||||
|
|
||||||
|
if "name" in values:
|
||||||
|
self._id = values["name"]
|
||||||
|
|
||||||
def filter(self, query: List[Level]) -> List[Level]:
|
def filter(self, query: List[Level]) -> List[Level]:
|
||||||
if self._id is not None:
|
if self._id is not None:
|
||||||
query = query.where(lambda x: x.id == self._id)
|
query = query.where(lambda x: x.id == self._id)
|
||||||
@ -26,7 +29,4 @@ class LevelFilter(FilterABC):
|
|||||||
# if self._server_id is not None:
|
# if self._server_id is not None:
|
||||||
# query = query.where(lambda x: x.server.server_id == self._server_id)
|
# query = query.where(lambda x: x.server.server_id == self._server_id)
|
||||||
|
|
||||||
skip = self.page_size * self.page_index
|
return self.skip_and_take(query)
|
||||||
result = query.skip(skip).take(self.page_size)
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from cpl_core.database.context import DatabaseContextABC
|
||||||
|
|
||||||
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
||||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||||
from bot_data.model.level import Level
|
from bot_data.model.level import Level
|
||||||
@ -5,11 +7,17 @@ from bot_graphql.abc.query_abc import QueryABC
|
|||||||
|
|
||||||
|
|
||||||
class LevelMutation(QueryABC):
|
class LevelMutation(QueryABC):
|
||||||
def __init__(self, servers: ServerRepositoryABC, levels: LevelRepositoryABC):
|
def __init__(
|
||||||
|
self,
|
||||||
|
servers: ServerRepositoryABC,
|
||||||
|
levels: LevelRepositoryABC,
|
||||||
|
db: DatabaseContextABC,
|
||||||
|
):
|
||||||
QueryABC.__init__(self, "LevelMutation")
|
QueryABC.__init__(self, "LevelMutation")
|
||||||
|
|
||||||
self._servers = servers
|
self._servers = servers
|
||||||
self._levels = levels
|
self._levels = levels
|
||||||
|
self._db = db
|
||||||
|
|
||||||
self.set_field("create_level", self.resolve_create_level)
|
self.set_field("create_level", self.resolve_create_level)
|
||||||
self.set_field("update_level", self.resolve_create_level)
|
self.set_field("update_level", self.resolve_create_level)
|
||||||
@ -23,10 +31,34 @@ class LevelMutation(QueryABC):
|
|||||||
int(input["permissions"]),
|
int(input["permissions"]),
|
||||||
self._servers.get_server_by_id(input["server_id"]),
|
self._servers.get_server_by_id(input["server_id"]),
|
||||||
)
|
)
|
||||||
return level
|
self._levels.add_level(level)
|
||||||
|
self._db.save_changes()
|
||||||
|
|
||||||
|
def get_new_server(l: Level):
|
||||||
|
return (
|
||||||
|
l.name == level.name
|
||||||
|
and l.color == level.color
|
||||||
|
and l.min_xp == level.min_xp
|
||||||
|
and l.permissions == level.permissions
|
||||||
|
)
|
||||||
|
|
||||||
|
return self._levels.get_levels_by_server_id(level.server.server_id).where(get_new_server)
|
||||||
|
|
||||||
def resolve_update_level(self, *_, input):
|
def resolve_update_level(self, *_, input):
|
||||||
return self._levels.get_level_by_id(input.id)
|
level = self._levels.get_level_by_id(input.id)
|
||||||
|
level.name = input["name"] if "name" in input else level.name
|
||||||
|
level.color = input["color"] if "color" in input else level.color
|
||||||
|
level.min_xp = input["min_xp"] if "min_xp" in input else level.min_xp
|
||||||
|
level.permissions = input["permissions"] if "permissions" in input else level.permissions
|
||||||
|
|
||||||
|
self._levels.update_level(level)
|
||||||
|
self._db.save_changes()
|
||||||
|
|
||||||
|
level = self._levels.get_level_by_id(input.id)
|
||||||
|
return level
|
||||||
|
|
||||||
def resolve_delete_level(self, *_, id: int):
|
def resolve_delete_level(self, *_, id: int):
|
||||||
return self._levels.get_level_by_id(id)
|
level = self._levels.get_level_by_id(id)
|
||||||
|
self._levels.delete_level(level)
|
||||||
|
self._db.save_changes()
|
||||||
|
return level
|
||||||
|
Loading…
Reference in New Issue
Block a user