diff options
author | Frederick Muriuki Muriithi | 2023-09-14 12:06:23 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-09-26 03:44:30 +0300 |
commit | e19b01571ce61e01f482a1dadeeb2fd835fda939 (patch) | |
tree | 27b8c7f86313a86bc1e6705ac65ff5996403eace /gn_auth/auth/authorisation/resources/mrna_resource.py | |
parent | 345e33fc8e1b12dda6626307ebac7e1206200974 (diff) | |
download | gn-auth-e19b01571ce61e01f482a1dadeeb2fd835fda939.tar.gz |
Move `groups` package under `resources` package
With user groups being resources that users can act on (with the
recent changes), this commit moves the `groups` module to under the
`resources` module.
It also renames the `*_resources.py` modules by dropping the
`_resources` part since the code is under the `resources` module
anyway.
Diffstat (limited to 'gn_auth/auth/authorisation/resources/mrna_resource.py')
-rw-r--r-- | gn_auth/auth/authorisation/resources/mrna_resource.py | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/gn_auth/auth/authorisation/resources/mrna_resource.py b/gn_auth/auth/authorisation/resources/mrna_resource.py deleted file mode 100644 index 7fce227..0000000 --- a/gn_auth/auth/authorisation/resources/mrna_resource.py +++ /dev/null @@ -1,66 +0,0 @@ -"""mRNA data resources functions and utilities""" -import uuid -from typing import Optional, Sequence - -import sqlite3 - -import gn_auth.auth.db.sqlite3 as db - -from .base import Resource -from .data import __attach_data__ - -def resource_data(cursor: db.DbCursor, - resource_id: uuid.UUID, - offset: int = 0, - limit: Optional[int] = None) -> Sequence[sqlite3.Row]: - """Fetch data linked to a mRNA resource""" - cursor.execute( - (("SELECT * FROM mrna_resources AS mr " - "INNER JOIN linked_mrna_data AS lmr " - "ON mr.data_link_id=lmr.data_link_id " - "WHERE mr.resource_id=?") + ( - f" LIMIT {limit} OFFSET {offset}" if bool(limit) else "")), - (str(resource_id),)) - return cursor.fetchall() - -def link_data_to_resource( - conn: db.DbConnection, - resource: Resource, - data_link_id: uuid.UUID) -> dict: - """Link mRNA Assay data with a resource.""" - with db.cursor(conn) as cursor: - params = { - "resource_id": str(resource.resource_id), - "data_link_id": str(data_link_id) - } - cursor.execute( - "INSERT INTO mrna_resources VALUES" - "(:resource_id, :data_link_id)", - params) - return params - -def unlink_data_from_resource( - conn: db.DbConnection, - resource: Resource, - data_link_id: uuid.UUID) -> dict: - """Unlink data from mRNA Assay resources""" - with db.cursor(conn) as cursor: - cursor.execute("DELETE FROM mrna_resources " - "WHERE resource_id=? AND data_link_id=?", - (str(resource.resource_id), str(data_link_id))) - return { - "resource_id": str(resource.resource_id), - "dataset_type": resource.resource_category.resource_category_key, - "data_link_id": data_link_id - } - -def attach_resources_data( - cursor, resources: Sequence[Resource]) -> Sequence[Resource]: - """Attach linked data to mRNA Assay resources""" - placeholders = ", ".join(["?"] * len(resources)) - cursor.execute( - "SELECT * FROM mrna_resources AS mr INNER JOIN linked_mrna_data AS lmd" - " ON mr.data_link_id=lmd.data_link_id " - f"WHERE mr.resource_id IN ({placeholders})", - tuple(str(resource.resource_id) for resource in resources)) - return __attach_data__(cursor.fetchall(), resources) |