Skip to content

Commit

Permalink
Add taskdto serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
nathandf committed Jul 11, 2024
1 parent 412f0c9 commit 61db13f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
13 changes: 13 additions & 0 deletions src/api/src/backend/serializers/TaskDTOSerializer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import json

class TaskDTOSerializer:
@staticmethod
def serialize(model):
entity = json.loads(model.json())
entity = {
**entity,
**entity["execution_profile"]
}
del entity["execution_profile"]

return entity
1 change: 1 addition & 0 deletions src/api/src/backend/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
from backend.serializers.PipelineLockAcquisitionResponseSerializer import PipelineLockAcquisitionResponseSerializer
from backend.serializers.BaseTaskSerializer import BaseTaskSerializer
from backend.serializers.TaskSerializer import TaskSerializer
from backend.serializers.TaskDTOSerializer import TaskDTOSerializer
from backend.serializers.FunctionTaskSerializer import FunctionTaskSerializer
11 changes: 2 additions & 9 deletions src/api/src/backend/views/Tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from backend.views.http.responses.models import ModelListResponse, ModelResponse
from backend.services.TaskService import service as task_service
from backend.services.GroupService import service as group_service
from backend.serializers import TaskSerializer
from backend.serializers import TaskSerializer, TaskDTOSerializer
from backend.errors.api import ServerError as APIServerError
from backend.helpers import resource_url_builder
from backend.utils import logger
Expand Down Expand Up @@ -140,17 +140,10 @@ def patch(self, request, group_id, pipeline_id, task_id):
if (task_model.type != task.type):
return BadRequest(f"Updating the type of a task is not allowed. Expected task.type: {task_model.type} - Recieved: {task.type}")

entity_dict = json.loads(task.json())
entity_dict = {
**entity_dict,
**entity_dict["execution_profile"]
}
del entity_dict["execution_profile"]

Task.objects.filter(
pipeline=pipeline,
id=task_id
).update(**entity_dict)
).update(**TaskDTOSerializer.serialize(task))

return ModelResponse(Task.objects.filter(id=task.id, pipeline=pipeline).first())
except (DatabaseError, OperationalError, IntegrityError) as e:
Expand Down

0 comments on commit 61db13f

Please sign in to comment.