Skip to content

Commit

Permalink
Addressed PR comments.
Browse files Browse the repository at this point in the history
Replaced ChangeSetSerialiazer to ChangeSerialiazer.
Updated some variables names.
  • Loading branch information
Julio-Oliveira-Encora committed Mar 6, 2024
1 parent 2ab090e commit 8aa4b4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions diode-netbox-plugin/netbox_diode_plugin/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_object(self, instance):
return serializer(object_data, context=context, many=True).data[0]


class ChangeSetSerializer(serializers.Serializer):
class ChangeSerialiazer(serializers.Serializer):
"""ChangeSet Serializer."""

change_id = serializers.UUIDField(required=True)
Expand All @@ -66,5 +66,5 @@ class ApplyChangeSetRequestSerializer(serializers.Serializer):

change_set_id = serializers.UUIDField(required=True)
change_set = serializers.ListField(
child=ChangeSetSerializer(), required=True, allow_empty=False
child=ChangeSerialiazer(), required=True, allow_empty=False
)
18 changes: 10 additions & 8 deletions diode-netbox-plugin/netbox_diode_plugin/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,29 +149,31 @@ def post(self, request, *args, **kwargs):
serializer_list = []
serializer_errors = []

serializer = ApplyChangeSetRequestSerializer(data=request.data)
request_serializer = ApplyChangeSetRequestSerializer(data=request.data)

change_set_id = self.request.data.get("change_set_id", None)

if not serializer.is_valid():
for error in serializer.errors:
if isinstance(serializer.errors[error], dict):
for _, error_values in serializer.errors[error].items():
if not request_serializer.is_valid():
for field_error_name in request_serializer.errors:
if isinstance(request_serializer.errors[field_error_name], dict):
for _, error_values in request_serializer.errors[
field_error_name
].items():
for field_name, field_errors in error_values.items():
serializer_errors.append(
{field_name: f"{str(field_errors[0])}"}
)
else:
errors_dict = {
error: f"{str(field_errors)}"
for field_errors in serializer.errors[error]
field_error_name: f"{str(field_errors)}"
for field_errors in request_serializer.errors[field_error_name]
}

serializer_errors.append(errors_dict)

return self._get_error_response(change_set_id, serializer_errors)

change_set = self.request.data.get("change_set", None)
change_set = request_serializer.data.get("change_set", None)

for change in change_set:
change_id = change.get("change_id", None)
Expand Down

0 comments on commit 8aa4b4d

Please sign in to comment.