Skip to content

Commit

Permalink
add CRUD for component, page, form and section config (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-W1 authored Jul 31, 2024
1 parent abbdfa6 commit 4ff5fb9
Show file tree
Hide file tree
Showing 13 changed files with 1,173 additions and 93 deletions.
30 changes: 23 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,31 @@
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "app.app.py",
"FLASK_DEBUG": "1"
"FLASK_APP": "app.app.py",
"FLASK_DEBUG": "1"
},
"args": [
"run",
"--debug"
],
"args": ["run", "--debug"],
"jinja": true,
"autoStartBrowser": false
}
},
{
"name": "Docker Runner FAB",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5686
},
"pathMappings": [
{
"localRoot": "${workspaceFolder:funding-service-design-fund-application-builder}",
"remoteRoot": "."
}
],
"justMyCode": true
}
]
}

]
}
129 changes: 122 additions & 7 deletions app/blueprints/self_serve/data/data_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from app.blueprints.self_serve.data.not_a_db import LISTS
from app.blueprints.self_serve.data.not_a_db import PAGES
from app.blueprints.self_serve.data.not_a_db import SECTIONS
from app.db.queries.application import insert_new_section

saved_responses = []
saved_sections = {}
Expand Down Expand Up @@ -66,20 +67,134 @@ def get_list_by_id(id: str) -> dict:
return LISTS.get(id, None)


def save_question(question: dict):
# TODO Implement front end journey that can use the section/form/page/component CRUD operations
# from app.db.queries.application import insert_new_section
# from app.db.queries.application import insert_new_form
# from app.db.queries.application import insert_new_page
# from app.db.queries.application import insert_new_component


def save_template_component(component: dict):
"""
TODO:
Save a template component to the database
Parameters:
component: dict The component to save to the database as a template
Returns:
dict The saved component
component_config = {
"page_id": component.get("page_id"),
"theme_id": component.get("theme_id"),
"title": component.get("title"),
"hint_text": component.get("hint"),
"options": component.get("options"),
"type": component.get("question_type"),
"template_name": component.get("template_name"),
"is_template": True,
"audit_info": component.get("audit_info"),
"page_index": component.get("page_index"),
"theme_index": component.get("theme_index"),
"conditions": component.get("conditions"),
"runner_component_name": component.get("runner_component_name"),
"list_id": component.get("list_id"),
}
return insert_new_component(component_config)
"""

# temp in memory solution
COMPONENTS.append(
{
"json_snippet": {
"options": {},
"type": question["question_type"],
"title": question["title"],
"hint": question["hint"],
"type": component["question_type"],
"title": component["title"],
"hint": component["hint"],
},
"id": question["id"],
"builder_display_name": question["builder_display_name"],
"id": component["id"],
"builder_display_name": component["builder_display_name"],
}
)


def save_section(section: dict):
def save_template_page(page: dict):
"""
TODO:
Save a template page to the database
Parameters:
page: dict The page to save to the database as a template
Returns:
dict The saved page
page_config = {
"form_id": page.get("form_id"),
"name_in_apply_json": {
"en": page.get("form_display_name"),
},
"template_name": page.get("builder_display_name"),
"is_template": True,
"audit_info": page.get("audit_info"),
"form_index": page.get("form_index"),
"display_path": page.get("display_path"),
"controller": page.get("controller"),
}
return insert_new_page(page_config)
"""

# Temp in memory solution
PAGES.append(page)


def save_template_form(form: dict):
"""
TODO:
Save a template form to the database
Parameters:
form: dict The form to save to the database as a template
Returns:
dict The saved form
form_config = {
"name_in_apply_json": {
"en": form.get("form_title"),
},
"is_template": True,
"template_name": form.get("builder_display_name"),
"audit_info": form.get("audit_info"),
"section_id": form.get("section_id"),
"section_index": form.get("section_index"),
"runner_publish_name": None # This is a template
}
insert_new_form(form_config)
"""

# Temp in memory solution
FORMS.append(form)


def save_template_section(section: dict):
"""
TODO:
Save a template section to the database
Parameters:
section: dict The section to save to the database as a template
Returns:
dict The saved section
section_config = {
"name_in_apply_json": {
"en": section.get("section_display_name"),
},
"is_template": True, # Assuming this remains a constant value
"template_name": section.get("builder_display_name"),
"description": section.get("description"),
"audit_info": section.get("audit_info"),
}
return insert_new_section(section_config)
"""

# Temp in memory solution
SECTIONS.append(section)
Loading

0 comments on commit 4ff5fb9

Please sign in to comment.