Skip to content

Commit 0d6b3d8

Browse files
author
Andrey
committed
Add entries tags support.
1 parent 1bb26c5 commit 0d6b3d8

4 files changed

Lines changed: 91 additions & 1 deletion

File tree

bugout/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
__email__ = "engineering@bugout.dev"
99
__license__ = "MIT"
10-
__version__ = "0.2.6"
10+
__version__ = "0.2.7"
1111

1212
__all__ = (
1313
"__author__",

bugout/app.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,30 @@ def create_tags(
754754
**kwargs,
755755
)
756756

757+
def create_entries_tags(
758+
self,
759+
token: Union[str, uuid.UUID],
760+
journal_id: Union[str, uuid.UUID],
761+
entries_tags: List[Dict[str, Any]],
762+
timeout: float = REQUESTS_TIMEOUT,
763+
auth_type: str = data.AuthType.bearer.name,
764+
**kwargs: Dict[str, Any],
765+
) -> List[Any]:
766+
self.journal.timeout = timeout
767+
entries_tags_obj = data.BugoutJournalEntriesTagsRequest(
768+
entries_tags=[
769+
data.BugoutJournalEntryTagsRequest(**entry_tags)
770+
for entry_tags in entries_tags
771+
]
772+
)
773+
return self.journal.create_entries_tags(
774+
token=token,
775+
journal_id=journal_id,
776+
entries_tags=entries_tags_obj,
777+
auth_type=data.AuthType[auth_type],
778+
**kwargs,
779+
)
780+
757781
def get_tags(
758782
self,
759783
token: Union[str, uuid.UUID],

bugout/data.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ class BugoutJournalEntryTags(BaseModel):
215215
tags: List[str]
216216

217217

218+
class BugoutJournalEntryTagsRequest(BaseModel):
219+
entry_id: uuid.UUID
220+
tags: List[str]
221+
222+
223+
class BugoutJournalEntriesTagsRequest(BaseModel):
224+
entries_tags: List[BugoutJournalEntryTags] = Field(default_factory=list)
225+
226+
218227
class BugoutSearchResult(BaseModel):
219228
entry_url: str
220229
content_url: str

bugout/journal.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
BugoutJournalEntry,
1212
BugoutJournalEntryContent,
1313
BugoutJournalEntryTags,
14+
BugoutJournalEntriesTagsRequest,
1415
BugoutJournalPermissions,
1516
BugoutJournals,
1617
BugoutJournalScopeSpecs,
@@ -464,6 +465,34 @@ def create_tags(
464465
)
465466
return result
466467

468+
def create_entries_tags(
469+
self,
470+
token: Union[str, uuid.UUID],
471+
journal_id: Union[str, uuid.UUID],
472+
entries_tags: BugoutJournalEntriesTagsRequest,
473+
auth_type: AuthType = AuthType.bearer,
474+
**kwargs: Dict[str, Any],
475+
) -> List[Any]:
476+
tags_path = f"journals/{journal_id}/entries_tags"
477+
headers = {
478+
"Authorization": f"{auth_type.value} {token}",
479+
}
480+
json = {
481+
"entries": [
482+
{
483+
"entry_id": entry.entry_id,
484+
"tags": entry.tags,
485+
}
486+
for entry in entries_tags.entries_tags
487+
]
488+
}
489+
if "headers" in kwargs.keys():
490+
headers.update(kwargs["headers"])
491+
result = self._call(
492+
method=Method.post, path=tags_path, headers=headers, json=json
493+
)
494+
return result
495+
467496
def get_tags(
468497
self,
469498
token: Union[str, uuid.UUID],
@@ -523,6 +552,34 @@ def delete_tag(
523552
)
524553
return BugoutJournalEntryTags(**result)
525554

555+
def delete_entries_tags(
556+
self,
557+
token: Union[str, uuid.UUID],
558+
journal_id: Union[str, uuid.UUID],
559+
entries_tags: BugoutJournalEntriesTagsRequest,
560+
auth_type: AuthType = AuthType.bearer,
561+
**kwargs: Dict[str, Any],
562+
) -> List[Any]:
563+
tags_path = f"journals/{journal_id}/entries_tags"
564+
headers = {
565+
"Authorization": f"{auth_type.value} {token}",
566+
}
567+
json = {
568+
"entries": [
569+
{
570+
"entry_id": entry.entry_id,
571+
"tags": entry.tags,
572+
}
573+
for entry in entries_tags.entries_tags
574+
]
575+
}
576+
if "headers" in kwargs.keys():
577+
headers.update(kwargs["headers"])
578+
result = self._call(
579+
method=Method.delete, path=tags_path, headers=headers, json=json
580+
)
581+
return result
582+
526583
# Search module
527584
def search(
528585
self,

0 commit comments

Comments
 (0)