Compare commits
No commits in common. "75500076a7c03a26b43bd0d994e927bf74fe4841" and "9c466733fb76842df57149dafb58267704133ff1" have entirely different histories.
75500076a7
...
9c466733fb
@ -28,9 +28,7 @@
|
||||
"Flask-SocketIO==5.3.2",
|
||||
"eventlet==0.33.2",
|
||||
"requests-oauthlib==1.3.1",
|
||||
"icmplib==3.0.3",
|
||||
"graphene==3.2.1",
|
||||
"graphql-server==3.0.0b5"
|
||||
"icmplib==3.0.3"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli==2022.12.0"
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 64a551bcee7fbfb06ee724355b48baec1c8e8e3e
|
||||
Subproject commit f15e3ff82709bbd274b0645c2b13a482f67f75ff
|
@ -12,7 +12,6 @@ from eventlet import wsgi
|
||||
from flask import Flask, request, jsonify, Response
|
||||
from flask_cors import CORS
|
||||
from flask_socketio import SocketIO
|
||||
from graphql_server.flask import GraphQLView
|
||||
from werkzeug.exceptions import NotFound
|
||||
|
||||
from bot_api.configuration.api_settings import ApiSettings
|
||||
@ -23,7 +22,6 @@ from bot_api.exception.service_exception import ServiceException
|
||||
from bot_api.logging.api_logger import ApiLogger
|
||||
from bot_api.model.error_dto import ErrorDTO
|
||||
from bot_api.route.route import Route
|
||||
from bot_data.graphql.graphql import GraphQL
|
||||
|
||||
|
||||
class Api(Flask):
|
||||
@ -64,16 +62,6 @@ class Api(Flask):
|
||||
|
||||
self._requests = {}
|
||||
|
||||
gql = GraphQL()
|
||||
self.add_url_rule(
|
||||
'/api/graphql',
|
||||
view_func=GraphQLView.as_view(
|
||||
'graphql',
|
||||
schema=gql.schema,
|
||||
graphiql=True # for having the GraphiQL interface
|
||||
)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _get_methods_from_registered_route() -> Union[list[str], str]:
|
||||
methods = ['Unknown']
|
||||
|
@ -1,53 +0,0 @@
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_query.extension import List
|
||||
from graphene import ObjectType
|
||||
|
||||
from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
|
||||
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
||||
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
||||
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||
from bot_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.model.auto_role import AutoRole
|
||||
from bot_data.model.client import Client
|
||||
from bot_data.model.known_user import KnownUser
|
||||
from bot_data.model.level import Level
|
||||
from bot_data.model.server import Server
|
||||
from bot_data.model.user import User
|
||||
from bot_data.model.user_joined_server import UserJoinedServer
|
||||
from bot_data.model.user_joined_voice_channel import UserJoinedVoiceChannel
|
||||
|
||||
|
||||
class QueryABC(ObjectType):
|
||||
_auto_roles: List[AutoRole]
|
||||
_clients: List[Client]
|
||||
_known_users: List[KnownUser]
|
||||
_levels: List[Level]
|
||||
_servers: List[Server]
|
||||
_user_joined_servers: List[UserJoinedServer]
|
||||
_user_joined_voice_channel: List[UserJoinedVoiceChannel]
|
||||
_users: List[User]
|
||||
|
||||
@classmethod
|
||||
@ServiceProviderABC.inject
|
||||
def init(
|
||||
cls,
|
||||
auto_roles: AutoRoleRepositoryABC,
|
||||
clients: ClientRepositoryABC,
|
||||
known_users: KnownUserRepositoryABC,
|
||||
levels: LevelRepositoryABC,
|
||||
servers: ServerRepositoryABC,
|
||||
user_joined_servers: UserJoinedServerRepositoryABC,
|
||||
user_joined_voice_channel: UserJoinedVoiceChannelRepositoryABC,
|
||||
users: UserRepositoryABC,
|
||||
):
|
||||
cls._auto_roles = auto_roles.get_auto_roles()
|
||||
cls._clients = clients.get_clients()
|
||||
cls._known_users = known_users.get_users()
|
||||
cls._levels = levels.get_levels()
|
||||
cls._servers = servers.get_servers()
|
||||
cls._user_joined_servers = user_joined_servers.get_user_joined_servers()
|
||||
cls._user_joined_voice_channel = user_joined_voice_channel.get_user_joined_voice_channels()
|
||||
cls._users = users.get_users()
|
@ -1,16 +0,0 @@
|
||||
import graphene
|
||||
from graphene import Schema
|
||||
|
||||
from bot_data.abc.queryABC import QueryABC
|
||||
from bot_data.graphql.root_query import RootQuery
|
||||
|
||||
|
||||
class GraphQL:
|
||||
|
||||
def __init__(self):
|
||||
QueryABC.init()
|
||||
self._schema = graphene.Schema(query=RootQuery)
|
||||
|
||||
@property
|
||||
def schema(self) -> Schema:
|
||||
return self._schema
|
@ -1,12 +0,0 @@
|
||||
import graphene
|
||||
|
||||
from bot_data.abc.queryABC import QueryABC
|
||||
from bot_data.graphql.types.client_query_type import ClientQueryType
|
||||
|
||||
|
||||
class ClientQuery(QueryABC):
|
||||
clients = graphene.List(ClientQueryType)
|
||||
|
||||
@classmethod
|
||||
def resolve_clients(cls, root, info):
|
||||
return cls._clients
|
@ -1,19 +0,0 @@
|
||||
import graphene
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
|
||||
from bot_data.abc.queryABC import QueryABC
|
||||
from bot_data.graphql.types.server_query_type import ServerQueryType
|
||||
from bot_data.service.server_repository_service import ServerRepositoryService
|
||||
|
||||
|
||||
class ServerQuery(QueryABC):
|
||||
servers = graphene.List(ServerQueryType)
|
||||
|
||||
@staticmethod
|
||||
@ServiceProviderABC.inject
|
||||
def _get_servers(servers: ServerRepositoryService):
|
||||
return servers.get_servers()
|
||||
|
||||
@classmethod
|
||||
def resolve_servers(cls, root, info):
|
||||
return cls._servers
|
@ -1,10 +0,0 @@
|
||||
from graphene import ObjectType, relay
|
||||
|
||||
from bot_data.graphql.queries.server_query import ServerQuery
|
||||
|
||||
|
||||
class RootQuery(
|
||||
ServerQuery,
|
||||
ObjectType
|
||||
):
|
||||
node = relay.Node.Field()
|
@ -1,18 +0,0 @@
|
||||
from graphene import Int, String
|
||||
|
||||
from bot_data.abc.queryABC import QueryABC
|
||||
from bot_data.model.client import Client
|
||||
|
||||
|
||||
class ClientQueryType(QueryABC):
|
||||
id = Int()
|
||||
discord_id = String()
|
||||
sent_message_count = Int()
|
||||
received_message_count = Int()
|
||||
deleted_message_count = Int()
|
||||
received_command_count = Int()
|
||||
moved_users_count = Int()
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(client: Client, info):
|
||||
return client.client_id
|
@ -1,23 +0,0 @@
|
||||
from graphene import Int, DateTime, String, List
|
||||
|
||||
from bot_data.abc.queryABC import QueryABC
|
||||
from bot_data.graphql.types.client_query_type import ClientQueryType
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
class ServerQueryType(QueryABC):
|
||||
id = Int()
|
||||
discord_server_id = String()
|
||||
|
||||
created_at = DateTime()
|
||||
modified_at = DateTime()
|
||||
|
||||
clients = List(ClientQueryType)
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(server: Server, info):
|
||||
return server.server_id
|
||||
|
||||
@classmethod
|
||||
def resolve_clients(cls, server: Server, info):
|
||||
return cls._clients.where(lambda c: c.server.server_id == server.server_id)
|
@ -33,8 +33,6 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result[5],
|
||||
result[6],
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
result[8],
|
||||
result[9],
|
||||
id=result[0]
|
||||
))
|
||||
|
||||
@ -51,8 +49,6 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result[5],
|
||||
result[6],
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
result[8],
|
||||
result[9],
|
||||
id=result[0]
|
||||
)
|
||||
|
||||
@ -67,8 +63,6 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result[5],
|
||||
result[6],
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
result[8],
|
||||
result[9],
|
||||
id=result[0]
|
||||
)
|
||||
|
||||
@ -77,9 +71,9 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result = self._context.select(Client.get_select_by_discord_id_string(discord_id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
|
||||
result = result[0]
|
||||
|
||||
|
||||
return Client(
|
||||
result[1],
|
||||
result[2],
|
||||
@ -88,8 +82,6 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result[5],
|
||||
result[6],
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
result[8],
|
||||
result[9],
|
||||
id=result[0]
|
||||
)
|
||||
|
||||
@ -98,9 +90,9 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result = self._context.select(Client.get_select_by_server_id_string(discord_id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
|
||||
result = result[0]
|
||||
|
||||
|
||||
return Client(
|
||||
result[1],
|
||||
result[2],
|
||||
@ -109,8 +101,6 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result[5],
|
||||
result[6],
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
result[8],
|
||||
result[9],
|
||||
id=result[0]
|
||||
)
|
||||
|
||||
@ -119,9 +109,9 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result = self._context.select(Client.get_select_by_discord_id_and_server_id_string(discord_id, server_id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
|
||||
result = result[0]
|
||||
|
||||
|
||||
return Client(
|
||||
result[1],
|
||||
result[2],
|
||||
@ -130,19 +120,17 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result[5],
|
||||
result[6],
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
result[8],
|
||||
result[9],
|
||||
id=result[0]
|
||||
)
|
||||
|
||||
|
||||
def add_client(self, client: Client):
|
||||
self._logger.trace(__name__, f'Send SQL command: {client.insert_string}')
|
||||
self._context.cursor.execute(client.insert_string)
|
||||
|
||||
|
||||
def update_client(self, client: Client):
|
||||
self._logger.trace(__name__, f'Send SQL command: {client.udpate_string}')
|
||||
self._context.cursor.execute(client.udpate_string)
|
||||
|
||||
|
||||
def delete_client(self, client: Client):
|
||||
self._logger.trace(__name__, f'Send SQL command: {client.delete_string}')
|
||||
self._context.cursor.execute(client.delete_string)
|
||||
@ -152,12 +140,12 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
if server is None:
|
||||
self._logger.warn(__name__, f'Cannot find server by id {server_id}')
|
||||
raise Exception('Value not found')
|
||||
|
||||
|
||||
client = self.find_client_by_discord_id_and_server_id(id, server.server_id)
|
||||
if client is None:
|
||||
self._logger.warn(__name__, f'Cannot find client by ids {id}@{server.server_id}')
|
||||
raise Exception('Value not found')
|
||||
|
||||
|
||||
return client
|
||||
|
||||
def append_sent_message_count(self, client_id: int, server_id: int, value: int):
|
||||
|
@ -25,8 +25,6 @@ class ServerRepositoryService(ServerRepositoryABC):
|
||||
for result in results:
|
||||
servers.append(Server(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
id=result[0]
|
||||
))
|
||||
|
||||
@ -57,8 +55,6 @@ class ServerRepositoryService(ServerRepositoryABC):
|
||||
result = self._context.select(Server.get_select_by_id_string(server_id))[0]
|
||||
return Server(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
id=result[0]
|
||||
)
|
||||
|
||||
@ -67,8 +63,6 @@ class ServerRepositoryService(ServerRepositoryABC):
|
||||
result = self._context.select(Server.get_select_by_discord_id_string(discord_id))[0]
|
||||
return Server(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
id=result[0]
|
||||
)
|
||||
|
||||
@ -77,24 +71,24 @@ class ServerRepositoryService(ServerRepositoryABC):
|
||||
result = self._context.select(Server.get_select_by_discord_id_string(discord_id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
|
||||
result = result[0]
|
||||
|
||||
|
||||
return Server(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
id=result[0]
|
||||
)
|
||||
|
||||
|
||||
def add_server(self, server: Server):
|
||||
self._logger.trace(__name__, f'Send SQL command: {server.insert_string}')
|
||||
self._context.cursor.execute(server.insert_string)
|
||||
|
||||
|
||||
def update_server(self, server: Server):
|
||||
self._logger.trace(__name__, f'Send SQL command: {server.udpate_string}')
|
||||
self._context.cursor.execute(server.udpate_string)
|
||||
|
||||
|
||||
def delete_server(self, server: Server):
|
||||
self._logger.trace(__name__, f'Send SQL command: {server.delete_string}')
|
||||
self._context.cursor.execute(server.delete_string)
|
||||
|
Loading…
Reference in New Issue
Block a user