aboutsummaryrefslogtreecommitdiffstats
path: root/backend/routes/forms/index.py
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2020-12-05 17:18:18 +0000
committerGravatar GitHub <[email protected]>2020-12-05 17:18:18 +0000
commite1a628bf579d74cbd6923ea42a91dd00ff5e4e05 (patch)
tree888b9b093f825cf8afc25f3494482b2ad61a1db2 /backend/routes/forms/index.py
parentCreate review-policy.yml (diff)
parentCreate route for creating new forms (diff)
Merge pull request #13 from python-discord/ks123/forms-routes
Diffstat (limited to 'backend/routes/forms/index.py')
-rw-r--r--backend/routes/forms/index.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/backend/routes/forms/index.py b/backend/routes/forms/index.py
index 183d5cc..f1df210 100644
--- a/backend/routes/forms/index.py
+++ b/backend/routes/forms/index.py
@@ -1,10 +1,12 @@
"""
Return a list of all forms to authenticated users.
"""
+from starlette.authentication import requires
from starlette.requests import Request
from starlette.responses import JSONResponse
from backend.route import Route
+from backend.models import Form
class FormsList(Route):
@@ -15,11 +17,16 @@ class FormsList(Route):
name = "forms_list"
path = "/"
+ @requires(["authenticated", "admin"])
async def get(self, request: Request) -> JSONResponse:
forms = []
+ cursor = request.state.db.forms.find()
- for form in request.state.db.forms.find():
- forms.append(form)
+ for form in await cursor.to_list(None):
+ forms.append(Form(**form)) # For converting _id to id
+
+ # Covert them back to dictionaries
+ forms = [form.dict() for form in forms]
return JSONResponse(
forms