♻️(backend) return the full document in the duplicate response

The duplicate endpoint used to respond with only `{"id": ...}`. It now
returns the complete duplicated document representation, consistent
with the other document detail endpoints, so the frontend doesn't have
to make a follow-up request to get the new document's data.

This required setting `is_favorite` explicitly on the duplicated
document before serializing it: it is normally set by the
`annotate_is_favorite` queryset method, which the newly created
document never goes through. Being a read-only serializer field, it
was silently dropped from the response instead of raising an error. A
document can't be a favorite right after being created, so it is set
to `False` directly.
This commit is contained in:
Anthony LC
2026-09-18 16:17:31 +02:00
parent d471fd987e
commit d01372fd90
2 changed files with 34 additions and 2 deletions
+8 -2
View File
@@ -1349,10 +1349,16 @@ class DocumentViewSet(
document=duplicated_document,
)
return drf_response.Response(
{"id": str(duplicated_document.id)}, status=status.HTTP_201_CREATED
# Set the `is_favorite` attribute to False for the duplicated document, as it
# cannot be a favorite immediately after creation.
duplicated_document.is_favorite = False
serializer = serializers.DocumentSerializer(
duplicated_document, context=self.get_serializer_context()
)
return drf_response.Response(serializer.data, status=status.HTTP_201_CREATED)
def _duplicate_document(
self,
document_to_duplicate,