-
-
- - {{server.name}} - -
+
diff --git a/kdb-bot/src/bot_api/model/discord/server_dto.py b/kdb-bot/src/bot_api/model/discord/server_dto.py index e7115dd231..07cd4365c4 100644 --- a/kdb-bot/src/bot_api/model/discord/server_dto.py +++ b/kdb-bot/src/bot_api/model/discord/server_dto.py @@ -1,3 +1,5 @@ +from typing import Optional + from bot_api.abc.dto_abc import DtoABC @@ -8,7 +10,8 @@ class ServerDTO(DtoABC): server_id: int, discord_id: int, name: str, - member_count: int + member_count: int, + icon_url: Optional[str] ): DtoABC.__init__(self) @@ -17,6 +20,7 @@ class ServerDTO(DtoABC): self._discord_id = discord_id self._name = name self._member_count = member_count + self._icon_url = icon_url @property def server_id(self) -> int: @@ -34,11 +38,15 @@ class ServerDTO(DtoABC): def member_count(self) -> int: return self._member_count + @property + def icon_url(self) -> Optional[str]: + return self._icon_url + def from_dict(self, values: dict): self._server_id = int(values['serverId']) self._discord_id = int(values['discordId']) self._name = values['name'] - self._member_count = int(values['memberCount']) + self._icon_url = int(values['iconURL']) def to_dict(self) -> dict: return { @@ -46,4 +54,5 @@ class ServerDTO(DtoABC): 'discordId': self._discord_id, 'name': self._name, 'memberCount': self._member_count, + 'iconURL': self._icon_url, } diff --git a/kdb-bot/src/bot_api/service/discord_service.py b/kdb-bot/src/bot_api/service/discord_service.py index 6f8e5f13bb..a0163dcc9e 100644 --- a/kdb-bot/src/bot_api/service/discord_service.py +++ b/kdb-bot/src/bot_api/service/discord_service.py @@ -33,9 +33,12 @@ class DiscordService: async def get_all_servers(self) -> List[ServerDTO]: servers = self._servers.get_servers() - return servers.select( - lambda x: ServerTransformer.to_dto(x, self._bot.get_guild(x.discord_server_id).name, self._bot.get_guild(x.discord_server_id).member_count) - ) + return servers.select(lambda x: ServerTransformer.to_dto( + x, + self._bot.get_guild(x.discord_server_id).name, + self._bot.get_guild(x.discord_server_id).member_count, + self._bot.get_guild(x.discord_server_id).icon + )) async def get_all_servers_by_user(self) -> List[ServerDTO]: token = self._auth.get_decoded_token_from_request() @@ -50,9 +53,12 @@ class DiscordService: user_from_db = self._users.find_user_by_id(0 if user.user_id is None else user.user_id) servers = self._servers.get_servers().where(lambda x: user_from_db is not None and x.server_id == user_from_db.server.server_id) - return servers.select( - lambda x: ServerTransformer.to_dto(x, self._bot.get_guild(x.discord_server_id).name, self._bot.get_guild(x.discord_server_id).member_count) - ) + return servers.select(lambda x: ServerTransformer.to_dto( + x, + self._bot.get_guild(x.discord_server_id).name, + self._bot.get_guild(x.discord_server_id).member_count, + self._bot.get_guild(x.discord_server_id).icon + )) async def get_filtered_servers_async(self, criteria: ServerSelectCriteria) -> ServerFilteredResultDTO: token = self._auth.get_decoded_token_from_request() @@ -68,9 +74,17 @@ class DiscordService: servers = servers.where(lambda x: user_from_db is not None and x.server_id == user_from_db.server.server_id) result = servers.select( - lambda x: ServerTransformer.to_dto(x, self._bot.get_guild(x.discord_server_id).name, self._bot.get_guild(x.discord_server_id).member_count) + lambda x: ServerTransformer.to_dto( + x, + self._bot.get_guild(x.discord_server_id).name, + self._bot.get_guild(x.discord_server_id).member_count, + self._bot.get_guild(x.discord_server_id).icon + ) ) + if criteria.name is not None and criteria.name != '': + result = result.where(lambda x: criteria.name.lower() in x.name.lower() or x.name.lower() == criteria.name.lower()) + return ServerFilteredResultDTO( List(ServerDTO, result), filtered_result.total_count diff --git a/kdb-bot/src/bot_api/transformer/server_transformer.py b/kdb-bot/src/bot_api/transformer/server_transformer.py index 920fd506d0..d883c42d5d 100644 --- a/kdb-bot/src/bot_api/transformer/server_transformer.py +++ b/kdb-bot/src/bot_api/transformer/server_transformer.py @@ -1,3 +1,7 @@ +from typing import Optional + +import discord + from bot_api.abc.transformer_abc import TransformerABC from bot_api.model.discord.server_dto import ServerDTO from bot_data.model.server import Server @@ -10,10 +14,11 @@ class ServerTransformer(TransformerABC): return Server(dto.discord_id) @staticmethod - def to_dto(db: Server, name: str, member_count: int) -> ServerDTO: + def to_dto(db: Server, name: str, member_count: int, icon_url: Optional[discord.Asset]) -> ServerDTO: return ServerDTO( db.server_id, db.discord_server_id, name, member_count, + icon_url.url if icon_url is not None else None, ) diff --git a/kdb-bot/src/bot_data/service/server_repository_service.py b/kdb-bot/src/bot_data/service/server_repository_service.py index 37b2918e2c..210a6dee95 100644 --- a/kdb-bot/src/bot_data/service/server_repository_service.py +++ b/kdb-bot/src/bot_data/service/server_repository_service.py @@ -35,9 +35,6 @@ class ServerRepositoryService(ServerRepositoryABC): self._logger.trace(__name__, f'Send SQL command: {Server.get_select_all_string()}') query = servers - if criteria.name is not None and criteria.name != '': - query = query.where(lambda x: criteria.name in x.first_name or x.first_name == criteria.name) - # sort if criteria.sort_column is not None and criteria.sort_column != '' and criteria.sort_direction is not None and criteria.sort_direction: crit_sort_direction = criteria.sort_direction.lower() diff --git a/kdb-web/src/app/models/discord/server.dto.ts b/kdb-web/src/app/models/discord/server.dto.ts index 4cba26ac6a..a97625b50a 100644 --- a/kdb-web/src/app/models/discord/server.dto.ts +++ b/kdb-web/src/app/models/discord/server.dto.ts @@ -3,4 +3,5 @@ export interface ServerDTO { discordId: number; name: string; memberCount: number; + iconURL: string | null; } \ No newline at end of file diff --git a/kdb-web/src/app/modules/view/dashboard/components/dashboard/dashboard.component.html b/kdb-web/src/app/modules/view/dashboard/components/dashboard/dashboard.component.html index e4139bace0..c7dd5fdfbe 100644 --- a/kdb-web/src/app/modules/view/dashboard/components/dashboard/dashboard.component.html +++ b/kdb-web/src/app/modules/view/dashboard/components/dashboard/dashboard.component.html @@ -2,11 +2,49 @@ {{'view.dashboard.header' | translate}}