diff --git a/apps/notification/backend/application/email_sender_hub.py b/apps/notification/backend/application/email_sender_hub.py index 507928b..1c3d623 100644 --- a/apps/notification/backend/application/email_sender_hub.py +++ b/apps/notification/backend/application/email_sender_hub.py @@ -4,15 +4,14 @@ from backend.business.email_sender_manager import EmailSenderManager class EmailSenderHub: def __init__(self): - pass + self.email_sender_manager = EmailSenderManager() async def get_email_senders(self, tenant_id: str): """get email senders for tenant""" if not tenant_id: raise ValueError("tenant_id is required") - email_sender_manager = EmailSenderManager() - return await email_sender_manager.get_email_senders(tenant_id) + return await self.email_sender_manager.get_email_senders(tenant_id) async def set_email_senders(self, tenant_id: str, email_senders: List[str]): """set email senders for tenant""" @@ -22,8 +21,7 @@ class EmailSenderHub: if not email_senders or not isinstance(email_senders, list): raise ValueError("email_senders must be a non-empty list") - email_sender_manager = EmailSenderManager() - return await email_sender_manager.set_email_senders(tenant_id, email_senders) + return await self.email_sender_manager.set_email_senders(tenant_id, email_senders) async def add_email_senders(self, tenant_id: str, new_senders: List[str]): """add email senders to tenant""" @@ -33,8 +31,7 @@ class EmailSenderHub: if not new_senders or not isinstance(new_senders, list): raise ValueError("new_senders must be a non-empty list") - email_sender_manager = EmailSenderManager() - return await email_sender_manager.add_email_senders(tenant_id, new_senders) + return await self.email_sender_manager.add_email_senders(tenant_id, new_senders) async def remove_email_senders(self, tenant_id: str, emails_to_remove: List[str]): """remove email senders from tenant""" @@ -44,22 +41,19 @@ class EmailSenderHub: if not emails_to_remove or not isinstance(emails_to_remove, list): raise ValueError("emails_to_remove must be a non-empty list") - email_sender_manager = EmailSenderManager() - return await email_sender_manager.remove_email_senders(tenant_id, emails_to_remove) + return await self.email_sender_manager.remove_email_senders(tenant_id, emails_to_remove) async def clear_email_senders(self, tenant_id: str): """clear email senders for tenant""" if not tenant_id: raise ValueError("tenant_id is required") - email_sender_manager = EmailSenderManager() - return await email_sender_manager.clear_email_senders(tenant_id) + return await self.email_sender_manager.clear_email_senders(tenant_id) async def delete_email_sender(self, tenant_id: str): """delete email sender for tenant""" if not tenant_id: raise ValueError("tenant_id is required") - email_sender_manager = EmailSenderManager() - return await email_sender_manager.delete_email_sender(tenant_id) + return await self.email_sender_manager.delete_email_sender(tenant_id) \ No newline at end of file diff --git a/apps/notification/backend/application/notification_hub.py b/apps/notification/backend/application/notification_hub.py index 9f9c274..cd5e474 100644 --- a/apps/notification/backend/application/notification_hub.py +++ b/apps/notification/backend/application/notification_hub.py @@ -4,8 +4,8 @@ from backend.models.constants import NotificationChannel class NotificationHub: - # def __init__(self): - # pass + def __init__(self): + self.notification_manager = NotificationManager() async def enqueue_notification( self, @@ -25,10 +25,8 @@ class NotificationHub: raise ValueError(f"Unsupported notification channel: {channel_int}") # Initialize NotificationManager with sender_id - notification_manager = NotificationManager() - # Call the enqueue_notification method in NotificationManager - return await notification_manager.enqueue_notification( + return await self.notification_manager.enqueue_notification( channels=notification_channels, receiver_id=receiver_id, subject=subject, diff --git a/apps/notification/backend/application/template_message_hub.py b/apps/notification/backend/application/template_message_hub.py index 1847f53..44da4e3 100644 --- a/apps/notification/backend/application/template_message_hub.py +++ b/apps/notification/backend/application/template_message_hub.py @@ -5,15 +5,14 @@ from common.constants.region import UserRegion class TemplateMessageHub: def __init__(self): - pass + self.template_message_manager = TemplateMessageManager() async def verify_tenant_access(self, template_id: str, tenant_id: str, region: int): """get template by tenant and template ids with region""" if not template_id or not tenant_id: raise ValueError("template_id and tenant_id are required") - template_message_manager = TemplateMessageManager() - return await template_message_manager.verify_tenant_access(template_id, tenant_id, region) + return await self.template_message_manager.verify_tenant_access(template_id, tenant_id, region) # ==================== global templates ==================== async def create_global_template( @@ -28,8 +27,7 @@ class TemplateMessageHub: if not template_id or not subject or not body: raise ValueError("template_id, subject, and body are required") - template_message_manager = TemplateMessageManager() - return await template_message_manager.create_global_template_from_data( + return await self.template_message_manager.create_global_template_from_data( template_id=template_id, region=region, subject=subject, @@ -50,28 +48,24 @@ class TemplateMessageHub: if invalid_fields: raise ValueError(f"Invalid update fields: {invalid_fields}") - template_message_manager = TemplateMessageManager() - return await template_message_manager.update_global_template(template_id, data, region) + return await self.template_message_manager.update_global_template(template_id, data, region) async def delete_global_template(self, template_id: str): """delete global template""" if not template_id: raise ValueError("template_id is required") - template_message_manager = TemplateMessageManager() - return await template_message_manager.delete_global_template(template_id) + return await self.template_message_manager.delete_global_template(template_id) async def list_global_templates(self, region: int): """list global templates""" - template_message_manager = TemplateMessageManager() - return await template_message_manager.list_global_templates(region) + return await self.template_message_manager.list_global_templates(region) # ==================== TENANT templates ==================== async def list_tenant_templates(self, tenant_id: str, region: int): """list tenant templates""" - template_message_manager = TemplateMessageManager() - return await template_message_manager.list_tenant_templates(tenant_id, region) + return await self.template_message_manager.list_tenant_templates(tenant_id, region) async def assign_templates_to_tenant(self, tenant_id: str, template_ids: List[str], region: int): """assign templates to tenant""" @@ -81,8 +75,7 @@ class TemplateMessageHub: if not tenant_id: raise ValueError("tenant_id is required") - template_message_manager = TemplateMessageManager() - return await template_message_manager.assign_templates_to_tenant(tenant_id, template_ids, region) + return await self.template_message_manager.assign_templates_to_tenant(tenant_id, template_ids, region) async def create_tenant_template( self, @@ -97,8 +90,7 @@ class TemplateMessageHub: if not template_id or not subject or not body or not tenant_id: raise ValueError("template_id, subject, body, and tenant_id are required") - template_message_manager = TemplateMessageManager() - return await template_message_manager.create_tenant_template_from_data( + return await self.template_message_manager.create_tenant_template_from_data( template_id=template_id, region=region, subject=subject, @@ -121,16 +113,14 @@ class TemplateMessageHub: if invalid_fields: raise ValueError(f"Invalid update fields: {invalid_fields}") - template_message_manager = TemplateMessageManager() - return await template_message_manager.update_tenant_template(tenant_id, template_id, data, region) + return await self.template_message_manager.update_tenant_template(tenant_id, template_id, data, region) async def delete_tenant_template(self, tenant_id: str, template_id: str, region: int): """delete tenant template""" if not template_id or not tenant_id: raise ValueError("template_id and tenant_id are required") - template_message_manager = TemplateMessageManager() - return await template_message_manager.delete_tenant_template(tenant_id, template_id, region) + return await self.template_message_manager.delete_tenant_template(tenant_id, template_id, region) async def render_template( self, @@ -139,12 +129,11 @@ class TemplateMessageHub: properties: dict, region: int ): - """render template""" + """Given the content of properties, render template with tenant_id, template_id and region""" if not template_id or not tenant_id: raise ValueError("template_id and tenant_id are required") if not properties: raise ValueError("properties cannot be empty") - template_message_manager = TemplateMessageManager() - return await template_message_manager.render_template(tenant_id, template_id, properties, region) + return await self.template_message_manager.render_template(tenant_id, template_id, properties, region)