summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/opendc/api/v2/prefabs/authorizations/endpoint.py12
-rw-r--r--api/opendc/models/prefab.py9
2 files changed, 11 insertions, 10 deletions
diff --git a/api/opendc/api/v2/prefabs/authorizations/endpoint.py b/api/opendc/api/v2/prefabs/authorizations/endpoint.py
index 7b421662..a6c1aead 100644
--- a/api/opendc/api/v2/prefabs/authorizations/endpoint.py
+++ b/api/opendc/api/v2/prefabs/authorizations/endpoint.py
@@ -1,8 +1,5 @@
-from datetime import datetime
-
-from opendc.models.prefab import Prefab
+from opendc.models.prefab import query_all
from opendc.models.user import User
-from opendc.util.database import Database
from opendc.util.rest import Response
@@ -13,13 +10,12 @@ def GET(request):
user.check_exists()
- own_prefabs = Prefab.get_all({'authorId' : user.get_id()})
- public_prefabs = Prefab.get_all({'visibility' : 'public'})
+ own_prefabs = query_all({'authorId' : user.get_id()})
+ public_prefabs = query_all({'visibility' : 'public'})
- authorizations = { "authorizations" : []}
+ authorizations = {"authorizations": []}
authorizations["authorizations"].append(own_prefabs)
authorizations["authorizations"].append(public_prefabs)
return Response(200, 'Successfully fetched authorizations.', authorizations)
-
diff --git a/api/opendc/models/prefab.py b/api/opendc/models/prefab.py
index 3d5dcf54..e1671dc1 100644
--- a/api/opendc/models/prefab.py
+++ b/api/opendc/models/prefab.py
@@ -28,5 +28,10 @@ class Prefab(Model):
# OpenDC-authored objects don't necessarily have an authorId
# return
- def get_all(query):
- return DB.fetch_all(query, Prefab.collection_name)
+
+def query_all(query):
+ """Returns a list of all prefabs matching the query.
+
+ :param query: the query to execute on the db.
+ """
+ return DB.fetch_all(query, Prefab.collection_name)