aboutsummaryrefslogtreecommitdiffstats
path: root/backend/routes/forms/index.py
diff options
context:
space:
mode:
Diffstat (limited to 'backend/routes/forms/index.py')
-rw-r--r--backend/routes/forms/index.py26
1 files changed, 7 insertions, 19 deletions
diff --git a/backend/routes/forms/index.py b/backend/routes/forms/index.py
index 38be693..1fdfc48 100644
--- a/backend/routes/forms/index.py
+++ b/backend/routes/forms/index.py
@@ -1,6 +1,5 @@
-"""
-Return a list of all forms to authenticated users.
-"""
+"""Return a list of all forms to authenticated users."""
+
from spectree.response import Response
from starlette.authentication import requires
from starlette.requests import Request
@@ -14,9 +13,7 @@ from backend.validation import ErrorMessage, OkayResponse, api
class FormsList(Route):
- """
- List all available forms for authorized viewers.
- """
+ """List all available forms for authorized viewers."""
name = "forms_list_create"
path = "/"
@@ -25,24 +22,17 @@ class FormsList(Route):
@api.validate(resp=Response(HTTP_200=FormList), tags=["forms"])
async def get(self, request: Request) -> JSONResponse:
"""Return a list of all forms to authenticated users."""
- forms = []
cursor = request.state.db.forms.find()
- 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]
+ forms = [Form(**form).dict() for form in await cursor.to_list(None)]
- return JSONResponse(
- forms
- )
+ return JSONResponse(forms)
@requires(["authenticated", "Helpers"])
@api.validate(
json=Form,
resp=Response(HTTP_200=OkayResponse, HTTP_400=ErrorMessage),
- tags=["forms"]
+ tags=["forms"],
)
async def post(self, request: Request) -> JSONResponse:
"""Create a new form."""
@@ -66,9 +56,7 @@ class FormsList(Route):
form = Form(**form_data)
if await request.state.db.forms.find_one({"_id": form.id}):
- return JSONResponse({
- "error": "id_taken"
- }, status_code=400)
+ return JSONResponse({"error": "id_taken"}, status_code=400)
await request.state.db.forms.insert_one(form.dict(by_alias=True))
return JSONResponse(form.dict())