GraphQL Part1 (gql endpoint only) #162 #192

Merged
edraft merged 38 commits from #162 into 1.0.0 2023-02-11 10:30:42 +01:00
2 changed files with 40 additions and 8 deletions
Showing only changes of commit b8484185e9 - Show all commits

View File

@ -16,6 +16,9 @@ class LevelFilter(FilterABC):
if "id" in values:
self._id = values["id"]
if "name" in values:
self._id = values["name"]
def filter(self, query: List[Level]) -> List[Level]:
if self._id is not None:
query = query.where(lambda x: x.id == self._id)
@ -26,7 +29,4 @@ class LevelFilter(FilterABC):
# if self._server_id is not None:
# query = query.where(lambda x: x.server.server_id == self._server_id)
skip = self.page_size * self.page_index
result = query.skip(skip).take(self.page_size)
return result
return self.skip_and_take(query)

View File

@ -1,3 +1,5 @@
from cpl_core.database.context import DatabaseContextABC
from bot_data.abc.level_repository_abc import LevelRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.model.level import Level
@ -5,11 +7,17 @@ from bot_graphql.abc.query_abc import QueryABC
class LevelMutation(QueryABC):
def __init__(self, servers: ServerRepositoryABC, levels: LevelRepositoryABC):
def __init__(
self,
servers: ServerRepositoryABC,
levels: LevelRepositoryABC,
db: DatabaseContextABC,
):
QueryABC.__init__(self, "LevelMutation")
self._servers = servers
self._levels = levels
self._db = db
self.set_field("create_level", self.resolve_create_level)
self.set_field("update_level", self.resolve_create_level)
@ -23,10 +31,34 @@ class LevelMutation(QueryABC):
int(input["permissions"]),
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):
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):
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