Skip to content

Commit

Permalink
Modified: create and update methods return full doc (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
signebedi committed Mar 25, 2024
1 parent b811f54 commit 071693f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
17 changes: 9 additions & 8 deletions libreforms_fastapi/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions libreforms_fastapi/utils/document_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down
3 changes: 1 addition & 2 deletions libreforms_fastapi/utils/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 071693f

Please sign in to comment.