init: Initial commit

This commit is contained in:
Björn Benouarets
2026-01-14 08:54:04 +01:00
parent a1eca7baef
commit 44ea07000b
18 changed files with 170 additions and 217 deletions

View File

@@ -59,24 +59,19 @@ class DatabaseManager:
def get_webhooks(self) -> list[Webhook]:
return self.__session.query(Webhook).all()
def count_webhooks(self) -> int:
return len(self.get_webhooks())
def get_webhook_by_id(self, id: str) -> Webhook:
webhook = self.__session.query(Webhook).filter(Webhook.id == id).first()
if webhook is None:
raise ValueError(f"Webhook with id {id} not found")
return webhook
def get_services(self) -> list[Service]:
return self.__session.query(Service).all()
def get_service_by_id(self, id: str) -> Service:
service = self.__session.query(Service).filter(Service.id == id).first()
if service is None:
raise ValueError(f"Service with id {id} not found")
return service
def count_webhooks_by_channel_id(self, channel_id: str | UUID) -> int | None:
try:
channel_uuid = UUID(channel_id) if isinstance(channel_id, str) else channel_id
return len(self.__session.query(Webhook).filter(Webhook.channel_id == channel_uuid).all())
except (ValueError, TypeError):
return None
def get_channels(self) -> list[Channel]:
return self.__session.query(Channel).all()
@@ -86,22 +81,17 @@ class DatabaseManager:
raise ValueError(f"Channel with id {id} not found")
return channel
def get_channel_by_microsoft_channel_id(self, microsoft_channel_id: str) -> Channel | None:
"""Get channel by Microsoft Teams channel ID. Returns None if not found."""
try:
# Convert string to UUID if needed
channel_uuid = UUID(microsoft_channel_id) if isinstance(microsoft_channel_id, str) else microsoft_channel_id
channel = self.__session.query(Channel).filter(Channel.microsoft_channel_id == channel_uuid).first()
return channel
except (ValueError, TypeError):
return None
def get_channel_by_microsoft_channel_id(self, microsoft_channel_id: str) -> Channel:
channel = self.__session.query(Channel).filter(Channel.microsoft_channel_id == microsoft_channel_id).first()
if channel is None:
raise ValueError(f"Channel with microsoft channel id {microsoft_channel_id} not found")
return channel
def count_webhooks_by_channel_id(self, channel_id: str | UUID) -> int:
"""Count webhooks by channel ID. Accepts UUID string or UUID object."""
try:
# Convert string to UUID if needed
channel_uuid = UUID(channel_id) if isinstance(channel_id, str) else channel_id
return len(self.__session.query(Webhook).filter(Webhook.channel_id == channel_uuid).all())
except (ValueError, TypeError):
# If channel_id is not a valid UUID, return 0
return 0
def get_services(self) -> list[Service]:
return self.__session.query(Service).all()
def get_service_by_id(self, id: str) -> Service:
service = self.__session.query(Service).filter(Service.id == id).first()
if service is None:
raise ValueError(f"Service with id {id} not found")
return service