From 48461d358b0cec5ecfcc7afe51eeaef68f06eed0 Mon Sep 17 00:00:00 2001 From: Pranshu1902 Date: Wed, 24 Apr 2024 21:51:31 +0530 Subject: [PATCH 1/2] show chats feedbacks filtered --- ayushma/views/chat.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ayushma/views/chat.py b/ayushma/views/chat.py index 42de4ee..58aa73d 100644 --- a/ayushma/views/chat.py +++ b/ayushma/views/chat.py @@ -47,6 +47,7 @@ class ChatViewSet( "list_all": ChatDetailSerializer, "converse": ConverseSerializer, "speech_to_text": SpeechToTextSerializer, + "feedbacks": ChatFeedbackSerializer, } permission_classes = (IsTempTokenOrAuthenticated,) lookup_field = "external_id" @@ -96,6 +97,13 @@ def perform_create(self, serializer): serializer.save(user=self.request.user, project=project) super().perform_create(serializer) + @extend_schema( + tags=("chats",), + ) + @action(detail=True, methods=["get"]) + def feedbacks(self, *args, **kwarg): + return ChatFeedback.objects.filter(chat_message__chat__external_id=kwarg["external_id"]) + @extend_schema( tags=("chats",), ) From da8788cb45f58ea857fa918dfc95c6d4e0c1b858 Mon Sep 17 00:00:00 2001 From: Pranshu1902 Date: Thu, 25 Apr 2024 02:54:40 +0530 Subject: [PATCH 2/2] return queryset as response --- ayushma/views/chat.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ayushma/views/chat.py b/ayushma/views/chat.py index 58aa73d..8373792 100644 --- a/ayushma/views/chat.py +++ b/ayushma/views/chat.py @@ -102,7 +102,12 @@ def perform_create(self, serializer): ) @action(detail=True, methods=["get"]) def feedbacks(self, *args, **kwarg): - return ChatFeedback.objects.filter(chat_message__chat__external_id=kwarg["external_id"]) + q = ChatFeedback.objects.filter(chat_message__chat__external_id=kwarg["external_id"]) + serialized_data = ChatFeedbackSerializer(q, many=True).data + return Response( + {"data": serialized_data}, + status=status.HTTP_200_OK, + ) @extend_schema( tags=("chats",),