Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
authors: decouple validation func from endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalEgn committed Sep 24, 2024
1 parent d3a38c1 commit bd3295b
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions backoffice/backoffice/workflows/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,15 @@ def create(self, request):
serializer = self.serializer_class(data=request.data)
if serializer.is_valid(raise_exception=True):
logger.info("Validating data against given schema: %s", request.data)
# Create request object to pass to schema validation
validation_request = request._request
validation_request.data = request.data.get("data")
validation_response = self.validate(validation_request)
if validation_response.status_code != status.HTTP_200_OK:
return validation_response
logger.info("Data passed schema validation, creating workflow.")
workflow = Workflow.objects.create(
data=serializer.validated_data["data"],
workflow_type=serializer.validated_data["workflow_type"],
)
validation_errors = list(get_validation_errors(request.data.get("data")))
if validation_errors:
raise ValidationError(validation_errors)
else:
logger.info("Data passed schema validation, creating workflow.")
workflow = Workflow.objects.create(
data=serializer.validated_data["data"],
workflow_type=serializer.validated_data["workflow_type"],
)
logger.info(
"Trigger Airflow DAG: %s for %s",
WORKFLOW_DAGS[workflow.workflow_type].initialize,
Expand Down

0 comments on commit bd3295b

Please sign in to comment.