From 8738345d741a3bde1ad6dea35ed855543d2320d0 Mon Sep 17 00:00:00 2001
From: nhertz <nhertz@nrao.edu>
Date: Fri, 19 Feb 2021 16:11:58 -0700
Subject: [PATCH] Went back on my decision to use JSON-formatted strings
 instead of Python dicts for request bodies; dicts play nicer with the front
 end, so I reversed the changes I made before and changed everything to expect
 a dict, not a string

---
 .../workspaces/capability/schema.py           | 35 ++++++++-----------
 .../capability/schema_interfaces.py           |  6 ++--
 2 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/shared/workspaces/workspaces/capability/schema.py b/shared/workspaces/workspaces/capability/schema.py
index 3eff65e99..265e34b4f 100644
--- a/shared/workspaces/workspaces/capability/schema.py
+++ b/shared/workspaces/workspaces/capability/schema.py
@@ -120,22 +120,19 @@ class Capability(Base, CapabilityIF):
         self.requests.append(request)
         return request
 
-    def to_dict(self) -> Dict[str, str]:
-        return {
-            "name": self.name,
-            "max_jobs": self.max_jobs,
-            "steps": str(self.steps),
-            "enabled": self.enabled,
-        }
-
     def __str__(self) -> str:
         return (
             f"Capability: {self.name}, max concurrent jobs of {self.max_jobs}"
             f"\nSequence: {self.steps}"
         )
 
-    def __json__(self) -> str:
-        return json.dumps(self.to_dict())
+    def __json__(self) -> Dict[str, str]:
+        return {
+            "name": self.name,
+            "max_jobs": self.max_jobs,
+            "steps": str(self.steps),
+            "enabled": self.enabled,
+        }
 
 
 class CapabilityRequest(Base, CapabilityRequestIF):
@@ -162,15 +159,13 @@ class CapabilityRequest(Base, CapabilityRequestIF):
     def __str__(self):
         return f"CapabilityRequest object: {self.__dict__}"
 
-    def __json__(self) -> str:
-        return json.dumps(
-            {
-                "id": self.id,
-                "capability_name": self.capability_name,
-                "state": self.state,
-                "parameters": self.parameters,
-            }
-        )
+    def __json__(self) -> Dict[str, str]:
+        return {
+            "id": self.id,
+            "capability_name": self.capability_name,
+            "state": self.state,
+            "parameters": self.parameters,
+        }
 
 
 class CapabilityVersion(Base, CapabilityVersionIF):
@@ -222,7 +217,7 @@ class CapabilityExecution(Base, CapabilityExecutionIF):
         ),
     )
 
-    def __json__(self, request: CapabilityRequest) -> dict:
+    def __json__(self) -> dict:
         return dict(
             id=self.id,
             state=self.state,
diff --git a/shared/workspaces/workspaces/capability/schema_interfaces.py b/shared/workspaces/workspaces/capability/schema_interfaces.py
index 8868fcc59..e56415cfb 100644
--- a/shared/workspaces/workspaces/capability/schema_interfaces.py
+++ b/shared/workspaces/workspaces/capability/schema_interfaces.py
@@ -1,6 +1,6 @@
 from __future__ import annotations
 
-from typing import List
+from typing import Dict, List
 
 from workspaces.capability.helpers_interfaces import CapabilityStepIF, ParameterIF
 from workspaces.products.schema_interfaces import FutureProductIF
@@ -27,7 +27,7 @@ class CapabilityRequestIF:
     future_products: str
     versions: List[CapabilityVersionIF]
 
-    def __json__(self) -> str:
+    def __json__(self) -> Dict[str, str]:
         raise NotImplementedError
 
 
@@ -48,5 +48,5 @@ class CapabilityExecutionIF:
     capability: CapabilityIF
     capability_request: CapabilityRequestIF
 
-    def __json__(self, request: CapabilityRequestIF) -> dict:
+    def __json__(self) -> Dict[str, str]:
         raise NotImplementedError
-- 
GitLab