Skip to content

Commit

Permalink
Merge pull request #43 from tilde-lab/edit-colls
Browse files Browse the repository at this point in the history
Support collections editing and new DS type
  • Loading branch information
blokhin authored Jan 12, 2024
2 parents e127de9 + 1a6d321 commit af003bd
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion metis_client/dtos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Data transfer objects"""
"""All data transfer objects"""

from .auth import MetisAuthCredentialsRequestDTO
from .base import MetisTimestampsDTO
Expand Down
6 changes: 4 additions & 2 deletions metis_client/dtos/collection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Collections DTO's"""
"""Collections DTOs"""

import sys
from typing import Literal, Union

Expand Down Expand Up @@ -30,8 +31,9 @@ class MetisCollectionTypeDTO(MetisTimestampsDTO):


class MetisCollectionCommonDTO(TypedDict):
"Common fields of collection's DTOs"
"Common fields of collection DTOs"

id: NotRequired[int]
title: str
typeId: int
dataSources: NotRequired[Sequence[int]]
Expand Down
9 changes: 6 additions & 3 deletions metis_client/dtos/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@


class DataSourceType(int, Enum):
"Data source types"
"""The basic data types supported"""

STRUCTURE = 1
CALCULATION = 2
PROPERTY = 3
WORKFLOW = 4
PATTERN = 5
USER_INPUT = 6


class MetisDataSourceDTO(MetisTimestampsDTO):
"Data source DTO"
"""A basic data item definition"""

id: int
parents: Sequence[int]
Expand All @@ -43,5 +45,6 @@ class MetisDataSourceDTO(MetisTimestampsDTO):


class MetisDataSourceContentOnlyDTO(TypedDict):
"Data source content only DTO"
"""Helper definition"""

content: str
4 changes: 3 additions & 1 deletion metis_client/dtos/event.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Event DTOs"""
"""SSE DTOs"""

import sys
from typing import Literal, Union

Expand All @@ -17,6 +18,7 @@
else: # pragma: no cover
from typing import TypedDict


MetisEventType = Literal["calculations", "collections", "datasources", "errors", "pong"]


Expand Down
2 changes: 1 addition & 1 deletion metis_client/models/event.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Event models"""
"""SSE models"""

import json
from dataclasses import dataclass
Expand Down
9 changes: 7 additions & 2 deletions metis_client/namespaces/v0_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

class MetisCollectionsCreateKwargs(TypedDict):
"MetisV0CollectionsNamespace.create kwargs"
id: NotRequired[int]
description: NotRequired[str]
data_source_ids: NotRequired[Sequence[int]]
user_ids: NotRequired[Sequence[int]]
Expand All @@ -39,7 +40,7 @@ class MetisV0CollectionsNamespace(BaseNamespace):
async def create_event(
self, type_id: int, title: str, **opts: Unpack[MetisCollectionsCreateKwargs]
) -> MetisRequestIdDTO:
"Create collection"
"Create or edit the collection"
payload = MetisCollectionCreateDTO(
title=title,
typeId=type_id,
Expand All @@ -48,6 +49,10 @@ async def create_event(
users=opts.get("user_ids", []),
visibility=opts.get("visibility", "private"),
)

if "id" in opts:
payload["id"] = opts["id"]

async with await self._client.request(
method="PUT",
url=self._base_url,
Expand All @@ -59,7 +64,7 @@ async def create_event(
async def create(
self, type_id: int, title: str, **opts: Unpack[MetisCollectionsCreateKwargs]
) -> Optional[MetisCollectionDTO]:
"Create collection and wait for result"
"Create or edit the collection and wait for the result"
evt = await act_and_get_result_from_stream(
self._root.stream.subscribe,
partial(self.create_event, type_id, title, **opts),
Expand Down

0 comments on commit af003bd

Please sign in to comment.