Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding endpoint to edit contacts #413

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions chats/apps/api/v1/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def get_user_email(self, linked_contact: LinkContact) -> str:


class ProjectFlowContactSerializer(serializers.Serializer):
uuid = serializers.CharField(required=False)
name = serializers.CharField()
language = serializers.CharField(required=False, max_length=3)
urns = serializers.ListField(child=serializers.CharField(), max_length=100)
Expand Down
27 changes: 27 additions & 0 deletions chats/apps/api/v1/projects/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,33 @@ def create_contacts(self, request, *args, **kwargs):
)
return Response(contact_response_data, response_status)

@action(detail=True, methods=["PUT"], url_name="edit_contact")
def edit_contact(self, request, *args, **kwargs):
project = self.get_object()
serializer = ProjectFlowContactSerializer(data=request.data)
flows_client = FlowRESTClient()

if serializer.is_valid() is False:
return Response(
{"Detail": "Data not valid."},
status.HTTP_400_BAD_REQUEST,
)

contact_uuid = request.data.get("uuid")
data = serializer.validated_data

contact_response = flows_client.create_contact(
project=project, data=data, contact_id=contact_uuid
)

contact_response_data = contact_response.json()
response_status = (
status.HTTP_200_OK
if contact_response.status_code in [200, 201]
else status.HTTP_400_BAD_REQUEST
)
return Response(contact_response_data, response_status)

@action(detail=True, methods=["GET"], url_name="groups")
def list_groups(self, request, *args, **kwargs):
project = self.get_object()
Expand Down
Loading