diff --git a/libreforms_fastapi/app/__init__.py b/libreforms_fastapi/app/__init__.py index e0d1b74..2ea143c 100644 --- a/libreforms_fastapi/app/__init__.py +++ b/libreforms_fastapi/app/__init__.py @@ -422,8 +422,9 @@ async def api_form_create(form_name: str, background_tasks: BackgroundTasks, req metadata[DocumentDatabase.ip_address_field] = request.client.host # Process the validated form submission as needed - background_tasks.add_task( - DocumentDatabase.create_document, + # background_tasks.add_task( + # DocumentDatabase.create_document, + d = DocumentDatabase.create_document( form_name=form_name, json_data=json_data, metadata=metadata @@ -456,7 +457,7 @@ async def api_form_create(form_name: str, background_tasks: BackgroundTasks, req return { "message": "Form submission received and validated", "document_id": document_id, - "data": json_data, + "data": d, } # Read one form @@ -618,7 +619,7 @@ async def api_form_update(form_name: str, document_id: str, background_tasks: Ba try: # Process the validated form submission as needed - success = DocumentDatabase.update_document( + d = DocumentDatabase.update_document( form_name=form_name, document_id=document_id, json_data=json_data, @@ -664,15 +665,15 @@ async def api_form_update(form_name: str, document_id: str, background_tasks: Ba return { "message": "Form updated received and validated", "document_id": document_id, - "data": json_data, + "data": d, } # Delete form - # @app.delete("/api/form/delete/{form_name}", dependencies=[Depends(api_key_auth)]) - # async def api_form_delete(): - +@app.delete("/api/form/delete/{form_name}/{document_id}", dependencies=[Depends(api_key_auth)]) +async def api_form_delete(form_name: str, document_id:str, background_tasks: BackgroundTasks, request: Request, session: SessionLocal = Depends(get_db), key: str = Depends(X_API_KEY)): + pass # Search forms diff --git a/libreforms_fastapi/utils/document_database.py b/libreforms_fastapi/utils/document_database.py index 7528780..03799f7 100644 --- a/libreforms_fastapi/utils/document_database.py +++ b/libreforms_fastapi/utils/document_database.py @@ -363,7 +363,7 @@ def create_document(self, form_name:str, json_data, metadata={}): if self.use_logger: self.logger.info(f"Inserted document for {form_name} with document_id {document_id}") - return document_id + return data_dict def update_document(self, form_name:str, document_id:str, json_data:str, metadata={}, limit_users:Union[bool, str]=False, exclude_deleted:bool=True): """Updates existing form in specified form's database.""" @@ -457,7 +457,7 @@ def update_document(self, form_name:str, document_id:str, json_data:str, metadat if self.use_logger: self.logger.info(f"Updated document for {form_name} with document_id {document_id}") - return document_id + return document def sign_document(self, form_name:str, json_data, metadata={}): """Manage signatures existing form in specified form's database.""" diff --git a/libreforms_fastapi/utils/pydantic_models.py b/libreforms_fastapi/utils/pydantic_models.py index f262b8e..a43b763 100644 --- a/libreforms_fastapi/utils/pydantic_models.py +++ b/libreforms_fastapi/utils/pydantic_models.py @@ -208,6 +208,7 @@ def get_form_names(config_path=config.FORM_CONFIG_PATH): # print("Config file does not exist. Using the default configuration.") return form_config.keys() + def get_form_config(form_name, config_path=config.FORM_CONFIG_PATH, update=False): """ Yields a single config dict for the form name passed, following a factory pattern approach. @@ -267,8 +268,6 @@ def get_form_config(form_name, config_path=config.FORM_CONFIG_PATH, update=False # value and returns a value or raises an exception pass - print(field_definitions) - # Creating the model dynamically, allowing arbitrary types class Config: arbitrary_types_allowed = True