aboutsummaryrefslogtreecommitdiffstats
path: root/backend/routes/forms/discover.py
blob: d06b607fbb5929a390969cdcc0cecc0cc059c884 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
Return a list of all publicly discoverable forms to unauthenticated users.
"""

from starlette.responses import JSONResponse

from backend.route import Route


class DiscoverableFormsList(Route):
    """
    List all discoverable forms that should be shown on the homepage.
    """

    name = "discoverable_forms_list"
    path = "/discoverable"

    async def get(self, request):
        forms = []

        for form in request.state.db.forms.find({
            "discoverable": True
        }):
            form["_id"] = str(form["_id"])
            forms.append(form)

        return JSONResponse(
            forms
        )