Skip to content

Commit

Permalink
[PY-560][external] Changes to core API methods to improve consistency (
Browse files Browse the repository at this point in the history
…#712)

* Changes to core API methods to improve consistency

* Update darwin/future/core/items/archive_items.py

Co-authored-by: Owen Jones <[email protected]>

* Update darwin/future/core/items/delete_items.py

Co-authored-by: Owen Jones <[email protected]>

* Update darwin/future/core/items/move_items.py

Co-authored-by: Owen Jones <[email protected]>

* Update stage.py

More descriptive variable names

* Update darwin/future/core/items/move_items_to_folder.py

Co-authored-by: Owen Jones <[email protected]>

* Update darwin/future/core/items/restore_items.py

Co-authored-by: Owen Jones <[email protected]>

* Update darwin/future/core/items/set_item_priority.py

Co-authored-by: Owen Jones <[email protected]>

* Formatting fix

---------

Co-authored-by: Owen Jones <[email protected]>
  • Loading branch information
JBWilkie and owencjones authored Nov 10, 2023
1 parent 9a6d191 commit f1b8f3c
Show file tree
Hide file tree
Showing 13 changed files with 517 additions and 319 deletions.
31 changes: 17 additions & 14 deletions darwin/future/core/items/archive_items.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from __future__ import annotations

from typing import Dict, List
from uuid import UUID

from darwin.future.core.client import ClientCore
from darwin.future.core.types.common import JSONType
from darwin.future.data_objects.typing import UnknownType


def archive_list_of_items(
api_client: ClientCore,
client: ClientCore,
team_slug: str,
dataset_id: int,
item_ids: List[UUID],
dataset_ids: int | List[int],
filters: Dict[str, UnknownType] = {},
) -> JSONType:
"""
Expand All @@ -19,26 +19,29 @@ def archive_list_of_items(
Parameters
----------
client: Client
The client to use for the request
The client to use for the request.
team_slug: str
The slug of the team containing the items
dataset_id: int
The ID of the dataset containing the items
item_ids: List[UUID]
The IDs of the items to be archived
The slug of the team containing the items.
dataset_ids: int | List[int]
The ID(s) of the dataset(s) containing the items.
filters: Dict[str, UnknownType]
Dataset filter parameters
Filter parameters.
Returns
-------
JSONType
The response data.
"""
assert (
filters
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"filters": {
"dataset_ids": [dataset_id],
"item_ids": [str(item_id) for item_id in item_ids],
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
**filters,
}
}

return api_client.post(f"/v2/teams/{team_slug}/items/archive", data=payload)
return client.post(f"/v2/teams/{team_slug}/items/archive", data=payload)
32 changes: 17 additions & 15 deletions darwin/future/core/items/delete_items.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from __future__ import annotations

from typing import Dict, List
from uuid import UUID

from darwin.future.core.client import ClientCore
from darwin.future.core.types.common import JSONType
from darwin.future.data_objects.typing import UnknownType


def delete_list_of_items(
api_client: ClientCore,
client: ClientCore,
team_slug: str,
dataset_id: int,
item_ids: List[UUID],
dataset_ids: int | List[int],
filters: Dict[str, UnknownType] = {},
) -> JSONType:
"""
Expand All @@ -19,26 +19,28 @@ def delete_list_of_items(
Parameters
----------
client: Client
The client to use for the request
The client to use for the request.
team_slug: str
The slug of the team containing the items
dataset_id: int
The ID of the dataset containing the items
item_ids: List[UUID]
The IDs of the items to be deleted
The slug of the team containing the items.
dataset_ids: int | List[int]
The ID(s) of the dataset(s) containing the items.
filters: Dict[str, UnknownType]
Dataset filter parameters
Filter parameters
Returns
-------
JSONType
The response data.
"""
assert (
filters
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"filters": {
"dataset_ids": [dataset_id],
"item_ids": [str(item_id) for item_id in item_ids],
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
**filters,
}
}

return api_client.delete(f"/v2/teams/{team_slug}/items", data=payload)
return client.delete(f"/v2/teams/{team_slug}/items", data=payload)
55 changes: 32 additions & 23 deletions darwin/future/core/items/move_items.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,56 @@
from typing import List
from __future__ import annotations

from typing import Dict, List
from uuid import UUID

from darwin.future.core.client import ClientCore
from darwin.future.core.types.common import JSONType
from darwin.future.data_objects.typing import UnknownType


def move_items_to_stage(
api_client: ClientCore,
client: ClientCore,
team_slug: str,
workflow_id: UUID,
dataset_id: int,
dataset_ids: int | List[int],
stage_id: UUID,
item_ids: List[UUID],
filters: Dict[str, UnknownType] = {},
) -> JSONType:
"""
Moves a list of items to a stage
Parameters
----------
client: Client
The client to use for the request
The client to use for the request.
team_slug: str
The slug of the team to move items for
dataset_id: str
The id or slug of the dataset to move items for
stage_id: str
The id or slug of the stage to move items to
item_ids: List[UUID]
A list of item ids to move to the stage
The slug of the team to move items for.
workflow_id: UUID
The id of the workflow to move items for.
dataset_ids: int | List[int]
The ID(s) of the dataset(s) containing the items.
stage_id: UUID
The id of the workflow to move items for.
filters: Dict[str, UnknownType]
Filter parameters.
Returns
-------
JSONType
The response data.
"""

return api_client.post(
f"/v2/teams/{team_slug}/items/stage",
{
"filters": {
"dataset_ids": [dataset_id],
"item_ids": [str(id) for id in item_ids],
},
"stage_id": str(stage_id),
"workflow_id": str(workflow_id),
assert (
filters
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"filters": {
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
**filters,
},
)
"stage_id": str(stage_id),
"workflow_id": str(workflow_id),
}

return client.post(f"/v2/teams/{team_slug}/items/stage", data=payload)
36 changes: 19 additions & 17 deletions darwin/future/core/items/move_items_to_folder.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from __future__ import annotations

from typing import Dict, List
from uuid import UUID

from darwin.future.core.client import ClientCore
from darwin.future.core.types.common import JSONType
from darwin.future.data_objects.typing import UnknownType


def move_list_of_items_to_folder(
api_client: ClientCore,
client: ClientCore,
team_slug: str,
dataset_id: int,
item_ids: List[UUID],
dataset_ids: int | List[int],
path: str,
filters: Dict[str, UnknownType] = {},
) -> JSONType:
Expand All @@ -20,29 +20,31 @@ def move_list_of_items_to_folder(
Parameters
----------
client: Client
The client to use for the request
The client to use for the request.
team_slug: str
The slug of the team containing the items
dataset_id: int
The ID of the dataset containing the items
item_ids: List[UUID]
The IDs of the items to be moved
The slug of the team containing the items.
dataset_ids: int | List[int]
The ID(s) of the dataset(s) containing the items.
path: str
The path to the folder to move the items to
The path to the folder to move the items to.
filters: Dict[str, UnknownType]
Dataset filter parameters
Filter parameters.
Returns
-------
JSONType
The response data.
"""
assert (
filters
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"filters": {
"dataset_ids": [dataset_id],
"item_ids": [str(item_id) for item_id in item_ids],
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
**filters,
},
"path": path,
}
}

return api_client.post(f"/v2/teams/{team_slug}/items/path", data=payload)
return client.post(f"/v2/teams/{team_slug}/items/path", data=payload)
31 changes: 17 additions & 14 deletions darwin/future/core/items/restore_items.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from __future__ import annotations

from typing import Dict, List
from uuid import UUID

from darwin.future.core.client import ClientCore
from darwin.future.core.types.common import JSONType
from darwin.future.data_objects.typing import UnknownType


def restore_list_of_items(
api_client: ClientCore,
client: ClientCore,
team_slug: str,
dataset_id: int,
item_ids: List[UUID],
dataset_ids: int | List[int],
filters: Dict[str, UnknownType] = {},
) -> JSONType:
"""
Expand All @@ -19,26 +19,29 @@ def restore_list_of_items(
Parameters
----------
client: Client
The client to use for the request
The client to use for the request.
team_slug: str
The slug of the team containing the items
dataset_id: int
The ID of the dataset containing the items
item_ids: List[UUID]
The IDs of the items to be restored
The slug of the team containing the items.
dataset_ids: int | List[int]
The ID(s) of the dataset(s) containing the items.
filters: Dict[str, UnknownType]
Dataset filter parameters
Filter parameters.
Returns
-------
JSONType
The response data.
"""
assert (
filters
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"filters": {
"dataset_ids": [dataset_id],
"item_ids": [str(item_id) for item_id in item_ids],
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
**filters,
}
}

return api_client.post(f"/v2/teams/{team_slug}/items/restore", data=payload)
return client.post(f"/v2/teams/{team_slug}/items/restore", data=payload)
36 changes: 19 additions & 17 deletions darwin/future/core/items/set_item_priority.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from __future__ import annotations

from typing import Dict, List
from uuid import UUID

from darwin.future.core.client import ClientCore
from darwin.future.core.types.common import JSONType
from darwin.future.data_objects.typing import UnknownType


def set_item_priority(
api_client: ClientCore,
client: ClientCore,
team_slug: str,
dataset_id: int,
item_ids: List[UUID],
dataset_ids: int | List[int],
priority: int,
filters: Dict[str, UnknownType] = {},
) -> JSONType:
Expand All @@ -20,30 +20,32 @@ def set_item_priority(
Parameters
----------
client: Client
The client to use for the request
The client to use for the request.
team_slug: str
The slug of the team to set the priority for
dataset_id: int
The dataset to set the priority for
item_ids: List[UUID]
The item ids to set the priority for
The slug of the team containing the items.
dataset_id: int | List[int]
The ID(s) of the dataset(s) containing the items.
priority: int
The priority to set
The priority to set.
Returns
-------
JSONType
The response data.
"""
assert (
filters
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"priority": priority,
"filters": {
"item_ids": [str(item_id) for item_id in item_ids],
"dataset_ids": [dataset_id],
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
**filters,
},
}
}

return api_client.post(
endpoint=f"/v2/teams/{team_slug}/items/priority",
return client.post(
f"/v2/teams/{team_slug}/items/priority",
data=payload,
)
Loading

0 comments on commit f1b8f3c

Please sign in to comment.