Skip to content

Commit

Permalink
Added: get_all_documents doc db logic (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
signebedi committed Mar 24, 2024
1 parent 197ed9a commit 1ef4ed4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion libreforms_fastapi/utils/document_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,20 @@ def delete_document(self, form_name:str, search_query, permanent:bool=False):
def get_all_documents(self, form_name:str, limit_users:Union[bool, str]=False, exclude_deleted=True):

"""Retrieves all entries from the specified form's database."""
pass
self._check_form_exists(form_name)

documents = self.databases[form_name].all()

if not documents or len(documents) == 0:
return None

if isinstance(limit_users, str):
documents = [x for x in documents if x['metadata'][self.created_by_field] == limit_users]

if exclude_deleted:
documents = [x for x in documents if x['metadata'][self.is_deleted_field] == False]

return documents

def get_one_document(self, form_name:str, document_id:str, limit_users:Union[bool, str]=False, exclude_deleted=True):
"""Retrieves a single entry that matches the search query."""
Expand Down

0 comments on commit 1ef4ed4

Please sign in to comment.