Skip to content

Commit

Permalink
feature: new publisher for rooms infos
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanJaeger committed Nov 27, 2024
1 parent a7ebf39 commit 367868d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions chats/apps/api/v1/dto/room_dto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from dataclasses import dataclass
from typing import List, Dict


@dataclass
class RoomDTO:
project_uuid: str
external_id: str
created_on: str
17 changes: 17 additions & 0 deletions chats/apps/api/v1/internal/eda_clients/billing_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.conf import settings

from chats.apps.event_driven.base_app import EventDrivenAPP


class RoomsInfoMixin:
base_room_exchange = settings.ROOMS_INFO_EXCHANGE

def request_room(self, content):
"""
Generic function to handle room actions
"""
EventDrivenAPP().backend.basic_publish(
content=content,
exchange=self.base_room_exchange,
headers={"callback_exchange": settings.DEFAULT_DEAD_LETTER_EXCHANGE},
)
5 changes: 5 additions & 0 deletions chats/apps/api/v1/rooms/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
update_custom_fields,
update_flows_custom_fields,
)
from chats.apps.projects.usecases.send_room_info import RoomInfoUseCase


class RoomViewset(
Expand Down Expand Up @@ -161,6 +162,10 @@ def close(
return Response(serialized_data.data, status=status.HTTP_200_OK)

close_room(str(instance.pk))

room_client = RoomInfoUseCase()
room_client.get_room(instance)

return Response(serialized_data.data, status=status.HTTP_200_OK)

def perform_create(self, serializer):
Expand Down
16 changes: 16 additions & 0 deletions chats/apps/projects/usecases/send_room_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from chats.apps.api.v1.internal.eda_clients.billing_client import RoomsInfoMixin
from chats.apps.api.v1.dto.room_dto import RoomDTO
from chats.apps.rooms.models import Room


class RoomInfoUseCase:
def __init__(self):
self._rooms_client = RoomsInfoMixin()

def get_room(self, room: Room):
room_dto = RoomDTO(
project_uuid=room.project.uuid,
external_id=room.contact.external_id,
created_on=room.created_on,
)
self._rooms_client.request_room(content=room_dto)
2 changes: 2 additions & 0 deletions chats/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@

FLOWS_TICKETER_EXCHANGE = env("FLOWS_TICKETER_EXCHANGE", default="sectors.topic")
FLOWS_QUEUE_EXCHANGE = env("FLOWS_QUEUE_EXCHANGE", default="queues.topic")
ROOMS_INFO_EXCHANGE = env("ROOMS_INFO_EXCHANGE", default="rooms.topic")

FLOWS_DEFAULT_DEAD_LETTER_EXCHANGE = env(
"FLOWS_DEFAULT_DEAD_LETTER_EXCHANGE", default="flows.dlx.topic"
)
Expand Down

0 comments on commit 367868d

Please sign in to comment.