Skip to content

Commit

Permalink
Merge pull request #821 from weni-ai/feature/send-user-email-update-p…
Browse files Browse the repository at this point in the history
…roject

update in project update with eda
  • Loading branch information
barbosajackson authored Dec 18, 2023
2 parents 4503008 + 2c00e63 commit 6cc634c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
17 changes: 3 additions & 14 deletions connect/api/v1/project/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
ChatsAuthorization,
)
from connect.internals.event_driven.producer.rabbitmq_publisher import RabbitmqPublisher
from connect.usecases.project.update_project import UpdateProjectUseCase

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -183,21 +184,9 @@ def create(self, validated_data):
return instance

def update(self, instance, validated_data):
name = validated_data.get("name", instance.name)
description = validated_data.get("description", instance.description)
message_body = {
"project_uuid": str(instance.uuid),
"description": description
}
rabbitmq_publisher = RabbitmqPublisher()
rabbitmq_publisher.send_message(message_body, exchange="update-projects.topic", routing_key="")
celery_app.send_task(
"update_project",
args=[instance.uuid, name],
)
updated_instance = super().update(instance, validated_data)
if not settings.TESTING:
ChatsRESTClient().update_chats_project(instance.uuid)
user = self.context["request"].user
UpdateProjectUseCase().send_updated_project(instance, user.email)
return updated_instance

def get_authorizations(self, obj):
Expand Down
15 changes: 3 additions & 12 deletions connect/api/v2/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
)
from connect.internals.event_driven.producer.rabbitmq_publisher import RabbitmqPublisher
from connect.template_projects.models import TemplateType
from connect.usecases.project.update_project import UpdateProjectUseCase


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -535,18 +536,8 @@ def update(self, instance, validated_data): # pragma: no cover

try:
instance = super().update(instance, validated_data)
name = validated_data.get("name", instance.name)
description = validated_data.get("description", instance.description)
message_body = {
"project_uuid": str(instance.uuid),
"description": description
}
rabbitmq_publisher = RabbitmqPublisher()
rabbitmq_publisher.send_message(message_body, exchange="update-projects.topic", routing_key="")
celery_app.send_task(
"update_project",
args=[instance.uuid, name],
)
user = self.context["request"].user
UpdateProjectUseCase().send_updated_project(instance, user.email)
return instance
except Exception as error:
logger.error(f"Update project: {error}")
Expand Down
Empty file added connect/usecases/__init__.py
Empty file.
Empty file.
25 changes: 25 additions & 0 deletions connect/usecases/project/update_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.conf import settings

from connect.api.v1.internal.chats.chats_rest_client import ChatsRESTClient
from connect.celery import app as celery_app
from connect.common.models import Project
from connect.internals.event_driven.producer.rabbitmq_publisher import RabbitmqPublisher

class UpdateProjectUseCase:

def __init__(self):
self.rabbitmq_publisher = RabbitmqPublisher()

def send_updated_project(self, project: Project, user_email: str):
message_body = {
"project_uuid": str(project.uuid),
"description": project.description,
"user_email": user_email
}

celery_app.send_task(
"update_project",
args=[project.uuid, project.name],
)

self.rabbitmq_publisher.send_message(message_body, exchange="update-projects.topic", routing_key="")

0 comments on commit 6cc634c

Please sign in to comment.