Skip to content

Commit d7830ad

Browse files
author
Andrey
committed
Refactor model to use alias.
1 parent b46fb5b commit d7830ad

4 files changed

Lines changed: 12 additions & 23 deletions

File tree

bugout/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ def create_entries_tags(
799799
self.journal.timeout = timeout
800800

801801
entries_tags_obj = data.BugoutJournalEntriesTagsRequest(
802-
entries_tags=[
802+
entries=[
803803
data.BugoutJournalEntryTagsRequest(**entry_tags)
804804
for entry_tags in entries_tags
805805
]
@@ -881,7 +881,7 @@ def delete_entries_tags(
881881
) -> data.BugoutJournalEntries:
882882
self.journal.timeout = timeout
883883
entries_tags_obj = data.BugoutJournalEntriesTagsRequest(
884-
entries_tags=[
884+
entries=[
885885
data.BugoutJournalEntryTagsRequest(**entry_tags)
886886
for entry_tags in entries_tags
887887
]

bugout/calls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict
22

3-
import requests
3+
import requests # type: ignore
44

55
from .data import Method
66
from .exceptions import BugoutResponseException, BugoutUnexpectedResponse

bugout/data.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,17 @@ class BugoutJournalEntryTags(BaseModel):
240240

241241

242242
class BugoutJournalEntryTagsRequest(BaseModel):
243-
entry_id: uuid.UUID
243+
entry_id: uuid.UUID = Field(alias="journal_entry_id")
244244
tags: List[str]
245245

246+
class Config:
247+
# Required configuration because in Spire we use "journal_entry_id" instead of "entry_id"
248+
# during creation and deletion of new tags for journal entry
249+
allow_population_by_field_name = True
250+
246251

247252
class BugoutJournalEntriesTagsRequest(BaseModel):
248-
entries_tags: List[BugoutJournalEntryTagsRequest] = Field(default_factory=list)
253+
entries: List[BugoutJournalEntryTagsRequest] = Field(default_factory=list)
249254

250255

251256
class BugoutSearchResult(BaseModel):

bugout/journal.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -477,15 +477,7 @@ def create_entries_tags(
477477
headers = {
478478
"Authorization": f"{auth_type.value} {token}",
479479
}
480-
json = {
481-
"entries": [
482-
{
483-
"journal_entry_id": str(entry.entry_id),
484-
"tags": entry.tags,
485-
}
486-
for entry in entries_tags.entries_tags
487-
]
488-
}
480+
json = entries_tags.dict()
489481
if "headers" in kwargs.keys():
490482
headers.update(kwargs["headers"])
491483
result = self._call(
@@ -567,15 +559,7 @@ def delete_entries_tags(
567559
headers = {
568560
"Authorization": f"{auth_type.value} {token}",
569561
}
570-
json = {
571-
"entries": [
572-
{
573-
"journal_entry_id": str(entry.entry_id),
574-
"tags": entry.tags,
575-
}
576-
for entry in entries_tags.entries_tags
577-
]
578-
}
562+
json = entries_tags.dict()
579563
if "headers" in kwargs.keys():
580564
headers.update(kwargs["headers"])
581565
result = self._call(

0 commit comments

Comments
 (0)