Compare commits
No commits in common. "9f8b723f64550cef5f43649f06d7fdf189644382" and "fee3a6ccb03601ac49c4aae6e55070fd7189970d" have entirely different histories.
9f8b723f64
...
fee3a6ccb0
6 changed files with 2 additions and 55 deletions
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 5.1.4 on 2026-08-17 11:01
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('chat', '0005_conversation_title'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='conversation',
|
|
||||||
name='details',
|
|
||||||
field=models.JSONField(blank=True, null=True),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -28,7 +28,6 @@ class Conversation(models.Model):
|
||||||
default=ConversationStatus.OPEN,
|
default=ConversationStatus.OPEN,
|
||||||
)
|
)
|
||||||
title = models.CharField(max_length=255, null=True, blank=True)
|
title = models.CharField(max_length=255, null=True, blank=True)
|
||||||
details = models.JSONField(null=True, blank=True)
|
|
||||||
# Set only while status is CLOSED; identifies who is allowed to reopen it.
|
# Set only while status is CLOSED; identifies who is allowed to reopen it.
|
||||||
closed_by_uuid = models.UUIDField(null=True, blank=True)
|
closed_by_uuid = models.UUIDField(null=True, blank=True)
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,6 @@ class CreateConversationSerializer(serializers.Serializer):
|
||||||
title = serializers.CharField(
|
title = serializers.CharField(
|
||||||
max_length=255, required=False, allow_null=True, allow_blank=True
|
max_length=255, required=False, allow_null=True, allow_blank=True
|
||||||
)
|
)
|
||||||
details = serializers.JSONField(required=False, allow_null=True)
|
|
||||||
|
|
||||||
|
|
||||||
class ConversationUserActionSerializer(serializers.Serializer):
|
class ConversationUserActionSerializer(serializers.Serializer):
|
||||||
|
|
@ -62,7 +61,6 @@ class ConversationSerializer(serializers.ModelSerializer):
|
||||||
"type",
|
"type",
|
||||||
"status",
|
"status",
|
||||||
"title",
|
"title",
|
||||||
"details",
|
|
||||||
"closed_by_uuid",
|
"closed_by_uuid",
|
||||||
"created_at",
|
"created_at",
|
||||||
"participants",
|
"participants",
|
||||||
|
|
@ -90,7 +88,6 @@ class ConversationListSerializer(serializers.Serializer):
|
||||||
type = serializers.CharField()
|
type = serializers.CharField()
|
||||||
status = serializers.CharField()
|
status = serializers.CharField()
|
||||||
title = serializers.CharField(allow_null=True)
|
title = serializers.CharField(allow_null=True)
|
||||||
details = serializers.JSONField(allow_null=True)
|
|
||||||
closed_by_uuid = serializers.UUIDField(allow_null=True)
|
closed_by_uuid = serializers.UUIDField(allow_null=True)
|
||||||
created_at = serializers.DateTimeField()
|
created_at = serializers.DateTimeField()
|
||||||
participants = serializers.ListField(child=serializers.UUIDField())
|
participants = serializers.ListField(child=serializers.UUIDField())
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,7 @@ class ConversationService:
|
||||||
self._mm = mattermost_client or MattermostClient()
|
self._mm = mattermost_client or MattermostClient()
|
||||||
|
|
||||||
def create(
|
def create(
|
||||||
self,
|
self, user_1_uuid: UUID, user_2_uuid: UUID, title: str | None = None
|
||||||
user_1_uuid: UUID,
|
|
||||||
user_2_uuid: UUID,
|
|
||||||
title: str | None = None,
|
|
||||||
details: dict | None = None,
|
|
||||||
) -> Conversation:
|
) -> Conversation:
|
||||||
if not self._account.validate_user(user_1_uuid):
|
if not self._account.validate_user(user_1_uuid):
|
||||||
raise ValueError(f"User {user_1_uuid} is not valid")
|
raise ValueError(f"User {user_1_uuid} is not valid")
|
||||||
|
|
@ -49,7 +45,7 @@ class ConversationService:
|
||||||
|
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
conversation = Conversation.objects.create(
|
conversation = Conversation.objects.create(
|
||||||
mattermost_channel_id=channel_id, title=title, details=details
|
mattermost_channel_id=channel_id, title=title
|
||||||
)
|
)
|
||||||
ConversationParticipant.objects.create(
|
ConversationParticipant.objects.create(
|
||||||
conversation=conversation, user_uuid=user_1_uuid
|
conversation=conversation, user_uuid=user_1_uuid
|
||||||
|
|
|
||||||
|
|
@ -57,31 +57,6 @@ def test_create_conversation_without_title_defaults_to_none():
|
||||||
assert Conversation.objects.get(uuid=conv.uuid).title is None
|
assert Conversation.objects.get(uuid=conv.uuid).title is None
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_create_conversation_stores_details():
|
|
||||||
user_1 = uuid.uuid4()
|
|
||||||
user_2 = uuid.uuid4()
|
|
||||||
|
|
||||||
svc = ConversationService(mattermost_client=_make_mm_client())
|
|
||||||
conv = svc.create(user_1, user_2, details={"source": "mobile_app", "order_id": 123})
|
|
||||||
|
|
||||||
assert Conversation.objects.get(uuid=conv.uuid).details == {
|
|
||||||
"source": "mobile_app",
|
|
||||||
"order_id": 123,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_create_conversation_without_details_defaults_to_none():
|
|
||||||
user_1 = uuid.uuid4()
|
|
||||||
user_2 = uuid.uuid4()
|
|
||||||
|
|
||||||
svc = ConversationService(mattermost_client=_make_mm_client())
|
|
||||||
conv = svc.create(user_1, user_2)
|
|
||||||
|
|
||||||
assert Conversation.objects.get(uuid=conv.uuid).details is None
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_create_conversation_creates_mattermost_mapping():
|
def test_create_conversation_creates_mattermost_mapping():
|
||||||
user_1 = uuid.uuid4()
|
user_1 = uuid.uuid4()
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@ class ConversationCreateView(APIView):
|
||||||
serializer.validated_data["user_1_uuid"],
|
serializer.validated_data["user_1_uuid"],
|
||||||
serializer.validated_data["user_2_uuid"],
|
serializer.validated_data["user_2_uuid"],
|
||||||
title=serializer.validated_data.get("title"),
|
title=serializer.validated_data.get("title"),
|
||||||
details=serializer.validated_data.get("details"),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return Response(
|
return Response(
|
||||||
|
|
@ -103,7 +102,6 @@ class UserConversationListView(APIView):
|
||||||
"type": conv.type,
|
"type": conv.type,
|
||||||
"status": conv.status,
|
"status": conv.status,
|
||||||
"title": conv.title,
|
"title": conv.title,
|
||||||
"details": conv.details,
|
|
||||||
"closed_by_uuid": conv.closed_by_uuid,
|
"closed_by_uuid": conv.closed_by_uuid,
|
||||||
"created_at": conv.created_at,
|
"created_at": conv.created_at,
|
||||||
"participants": participants,
|
"participants": participants,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue