Ensure template exists before all CRUD operations - Add ensure_default_template_exists to all endpoints - Template auto-created on any operation - Fixes 404 errors when template doesn't exist
Browse files
main.py
CHANGED
|
@@ -1026,7 +1026,10 @@ async def add_template_item(item_data: dict):
|
|
| 1026 |
try:
|
| 1027 |
logger.info(f"Adding new item to shared template")
|
| 1028 |
|
| 1029 |
-
#
|
|
|
|
|
|
|
|
|
|
| 1030 |
template = await db.checklist_templates.find_one({"templateId": "default"})
|
| 1031 |
|
| 1032 |
if not template:
|
|
@@ -1096,6 +1099,9 @@ async def update_template_item(item_id: str, item_data: dict):
|
|
| 1096 |
try:
|
| 1097 |
logger.info(f"Updating item {item_id} in shared template")
|
| 1098 |
|
|
|
|
|
|
|
|
|
|
| 1099 |
# Prepare update fields
|
| 1100 |
update_fields = {}
|
| 1101 |
if 'requirement' in item_data:
|
|
@@ -1153,6 +1159,9 @@ async def delete_template_item(item_id: str):
|
|
| 1153 |
try:
|
| 1154 |
logger.info(f"Deleting item {item_id} from shared template")
|
| 1155 |
|
|
|
|
|
|
|
|
|
|
| 1156 |
# Remove the item from the template
|
| 1157 |
result = await db.checklist_templates.update_one(
|
| 1158 |
{"templateId": "default"},
|
|
@@ -1197,6 +1206,9 @@ async def add_template_section(section_data: dict):
|
|
| 1197 |
try:
|
| 1198 |
logger.info(f"Adding new section to shared template")
|
| 1199 |
|
|
|
|
|
|
|
|
|
|
| 1200 |
# Get the template
|
| 1201 |
template = await db.checklist_templates.find_one({"templateId": "default"})
|
| 1202 |
|
|
@@ -1259,6 +1271,9 @@ async def delete_template_section(section_id: str):
|
|
| 1259 |
try:
|
| 1260 |
logger.info(f"Deleting section {section_id} from shared template")
|
| 1261 |
|
|
|
|
|
|
|
|
|
|
| 1262 |
# Remove the section from the template
|
| 1263 |
result = await db.checklist_templates.update_one(
|
| 1264 |
{"templateId": "default"},
|
|
|
|
| 1026 |
try:
|
| 1027 |
logger.info(f"Adding new item to shared template")
|
| 1028 |
|
| 1029 |
+
# Ensure template exists first
|
| 1030 |
+
await ensure_default_template_exists()
|
| 1031 |
+
|
| 1032 |
+
# Get the template
|
| 1033 |
template = await db.checklist_templates.find_one({"templateId": "default"})
|
| 1034 |
|
| 1035 |
if not template:
|
|
|
|
| 1099 |
try:
|
| 1100 |
logger.info(f"Updating item {item_id} in shared template")
|
| 1101 |
|
| 1102 |
+
# Ensure template exists first
|
| 1103 |
+
await ensure_default_template_exists()
|
| 1104 |
+
|
| 1105 |
# Prepare update fields
|
| 1106 |
update_fields = {}
|
| 1107 |
if 'requirement' in item_data:
|
|
|
|
| 1159 |
try:
|
| 1160 |
logger.info(f"Deleting item {item_id} from shared template")
|
| 1161 |
|
| 1162 |
+
# Ensure template exists first
|
| 1163 |
+
await ensure_default_template_exists()
|
| 1164 |
+
|
| 1165 |
# Remove the item from the template
|
| 1166 |
result = await db.checklist_templates.update_one(
|
| 1167 |
{"templateId": "default"},
|
|
|
|
| 1206 |
try:
|
| 1207 |
logger.info(f"Adding new section to shared template")
|
| 1208 |
|
| 1209 |
+
# Ensure template exists first
|
| 1210 |
+
await ensure_default_template_exists()
|
| 1211 |
+
|
| 1212 |
# Get the template
|
| 1213 |
template = await db.checklist_templates.find_one({"templateId": "default"})
|
| 1214 |
|
|
|
|
| 1271 |
try:
|
| 1272 |
logger.info(f"Deleting section {section_id} from shared template")
|
| 1273 |
|
| 1274 |
+
# Ensure template exists first
|
| 1275 |
+
await ensure_default_template_exists()
|
| 1276 |
+
|
| 1277 |
# Remove the section from the template
|
| 1278 |
result = await db.checklist_templates.update_one(
|
| 1279 |
{"templateId": "default"},
|