Skip to content

Commit

Permalink
chore(api): refactor the start upload chunk api to remove unnecessary…
Browse files Browse the repository at this point in the history
… fields.

With this change, only the `chunk_index` and `chunk_content` fields are required when using the `start_upload_chunk` api making it more concise.
  • Loading branch information
kennedykori committed Aug 17, 2022
1 parent cfca2d1 commit 4b6c140
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 1 addition & 3 deletions apps/sql_data/apiviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def create(self, request, *args, **kwargs):
def start_chunk_upload(self, request: Request, pk) -> Response:
"""Start a new chunk upload."""
self.check_object_permissions(request, request.user)
request.data["upload_metadata"] = str(pk)
serializer: NewSQLUploadChunkSerializer = self.get_serializer(
data=request.data
)
Expand All @@ -127,6 +126,5 @@ def start_chunk_upload(self, request: Request, pk) -> Response:
serializer.errors, status=status.HTTP_400_BAD_REQUEST
)

serializer.save()

serializer.save(upload_metadata=self.get_object())
return Response(serializer.data, status=status.HTTP_201_CREATED)
3 changes: 2 additions & 1 deletion apps/sql_data/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
class NewSQLUploadChunkSerializer(AuditBaseSerializer):
class Meta:
model = SQLUploadChunk
fields = "__all__"
fields = ("chunk_index", "chunk_content", "upload_metadata")
read_only_fields = ("upload_metadata",)


class SQLDatabaseSerializer(AuditBaseSerializer):
Expand Down

0 comments on commit 4b6c140

Please sign in to comment.