Skip to content

Commit

Permalink
Merge pull request #46 from glrs/feature/couchdb
Browse files Browse the repository at this point in the history
Feature/couchdb
  • Loading branch information
glrs authored Feb 7, 2025
2 parents aeb2cc9 + 7a051bf commit 51a0b53
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 15 deletions.
59 changes: 46 additions & 13 deletions lib/couchdb/yggdrasil_db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,43 +158,76 @@ def check_project_exists(self, project_id: str) -> bool:

@auto_load_and_save
def add_sample(
self, ygg_doc: YggdrasilDocument, sample_id: str, status: str = "pending"
self, _doc_injected: YggdrasilDocument, sample_id: str, status: str = "pending"
):
"""
Adds a sample to the given YggdrasilDocument and
relies on the decorator to fetch & save the doc.
IMPORTANT: This method is decorated by @auto_load_and_save,
so you must call it like:
add_sample(<project_id>, <sample_id>, <status>)
The decorator will fetch the YggdrasilDocument and pass it here as '_doc_injected'.
---
Adds a sample to a project.
Args:
_doc_injected (YggdrasilDocument): The Yggdrasil document (injected by the decorator).
sample_id (str): The sample ID.
status (str): The status of the sample. Defaults to "pending".
"""
ygg_doc.add_sample(sample_id=sample_id, status=status)
_doc_injected.add_sample(sample_id=sample_id, status=status)
logging.info(f"Sample '{sample_id}' added with status '{status}'.")

@auto_load_and_save
def update_sample_status(
self, ygg_doc: YggdrasilDocument, sample_id: str, status: str
self, _doc_injected: YggdrasilDocument, sample_id: str, status: str
) -> None:
"""Updates the status of a sample within a project.
"""
IMPORTANT: This method is decorated by @auto_load_and_save,
so you must call it like:
update_sample_status(<project_id>, <sample_id>, <status>)
The decorator will fetch the YggdrasilDocument and pass it here as '_doc_injected'.
---
Updates the status of a sample within a project.
Args:
project_id (str): The project ID.
_doc_injected (YggdrasilDocument): The Yggdrasil document (injected by the decorator).
sample_id (str): The sample ID.
status (str): The new status for the sample.
"""
ygg_doc.update_sample_status(sample_id=sample_id, status=status)
_doc_injected.update_sample_status(sample_id=sample_id, status=status)
logging.info(f"Sample '{sample_id}' status updated to '{status}'.")

@auto_load_and_save
def add_ngi_report_entry(
self,
ygg_doc: YggdrasilDocument,
_doc_injected: YggdrasilDocument,
report_data: Dict[str, Any],
) -> bool:
"""Adds an NGI report entry to the given YggdrasilDocument.
"""
IMPORTANT: This method is decorated by @auto_load_and_save,
so you must call it like:
add_ngi_report_entry(<project_id>, <report_data>)
The decorator will fetch the YggdrasilDocument and pass it here as '_doc_injected'.
---
Adds an NGI report entry to a project.
Args:
ygg_doc (YggdrasilDocument): The Yggdrasil document.
_doc_injected (YggdrasilDocument): The Yggdrasil document (injected by the decorator).
report_data (Dict[str, Any]): The NGI report data.
"""
if not ygg_doc.add_ngi_report_entry(report_data):
logging.info("NGI report entry failed to be added to the document.")
if not _doc_injected.add_ngi_report_entry(report_data):
logging.warning("NGI report entry failed to be added to the document.")
return False
logging.info("NGI report entry added to the document.")
return True
7 changes: 5 additions & 2 deletions lib/couchdb/yggdrasil_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ def sync_project_metadata(
# Update sensitive
self.delivery_info["sensitive"] = is_sensitive

# NOTE: Hardcoded for now, may be configurable in the future
# self.delivery_info["partial_delivery_allowed"] = False

def update_project_status(self, new_status: str) -> None:
"""Updates the overall project status. If 'completed', set end_date."""
self.project_status = new_status
Expand Down Expand Up @@ -382,7 +385,7 @@ def add_ngi_report_entry(self, report_data: Dict[str, Any]) -> bool:
"date_created": "2025-02-02_10:20:30",
"signee": "",
"date_signed": "",
"approved": False,
"rejected": False,
"samples_included": [...]
}
"""
Expand All @@ -391,7 +394,7 @@ def add_ngi_report_entry(self, report_data: Dict[str, Any]) -> bool:
"date_created",
"signee",
"date_signed",
"approved",
"rejected",
"samples_included",
}
if isinstance(report_data, dict) and required_keys.issubset(report_data.keys()):
Expand Down

0 comments on commit 51a0b53

Please sign in to comment.