Skip to content

Commit fee1404

Browse files
committed
Added main journal handlers
1 parent dcd0008 commit fee1404

3 files changed

Lines changed: 107 additions & 15 deletions

File tree

bugout/app.py

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,58 @@ def update_group(
153153
def delete_group(self, token: uuid.UUID, group_id: uuid.UUID) -> data.BugoutGroup:
154154
return self.group.delete_group(token, group_id)
155155

156+
# Journal scopes handlers
157+
def get_scopes(self):
158+
pass
159+
160+
def get_journal_scopes(self):
161+
pass
162+
163+
def update_journal_scopes(self):
164+
pass
165+
166+
def delete_journal_scopes(self):
167+
pass
168+
156169
# Journal handlers
170+
def create_journal(self, token: uuid.UUID, name: str) -> data.BugoutJournal:
171+
return self.journal.create_journal(token, name)
172+
173+
def list_journals(self, token: uuid.UUID) -> data.BugoutJournals:
174+
return self.journal.list_journals(token)
175+
157176
def get_journal(
158-
self, journal_id: uuid.UUID, token: uuid.UUID
177+
self, token: uuid.UUID, journal_id: uuid.UUID
178+
) -> data.BugoutJournal:
179+
return self.journal.get_journal(token, journal_id)
180+
181+
def update_journal(
182+
self, token: uuid.UUID, journal_id: uuid.UUID, name: str
159183
) -> data.BugoutJournal:
160-
return self.journal.get_journal(journal_id, token)
184+
return self.journal.update_journal(token, journal_id, name)
185+
186+
def delete_journal(
187+
self, token: uuid.UUID, journal_id: uuid.UUID
188+
) -> data.BugoutJournal:
189+
return self.journal.delete_journal(token, journal_id)
190+
191+
# Journal entries
192+
def create_entry(self):
193+
pass
194+
195+
def get_entry(self):
196+
pass
197+
198+
def get_entries(self):
199+
pass
200+
201+
def get_entry_content(self):
202+
pass
203+
204+
def update_entry_content(self):
205+
pass
206+
207+
def delete_entry(self):
208+
pass
209+
210+
# Tags

bugout/data.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime
22
from enum import Enum, unique
3-
from typing import Any, Dict, List, Optional
3+
from typing import Any, Dict, List, Optional, Set
44
import uuid
55

66
from pydantic import BaseModel, Field
@@ -88,7 +88,11 @@ class BugoutGroupMembers(BaseModel):
8888
class BugoutJournal(BaseModel):
8989
id: uuid.UUID
9090
bugout_user_id: uuid.UUID
91-
holder_ids: List[uuid.UUID]
91+
holder_ids: Set[uuid.UUID] = Field(default_factory=set)
9292
name: str
9393
created_at: datetime
9494
updated_at: datetime
95+
96+
97+
class BugoutJournals(BaseModel):
98+
journals: List[BugoutJournal]

bugout/journal.py

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import uuid
33

44
from .calls import make_request, InvalidUrlSpec
5-
from .data import BugoutJournal, Method
5+
from .data import BugoutJournal, BugoutJournals, Method
66

77

88
class Journal:
@@ -20,17 +20,55 @@ def _call(self, method: Method, path: str, **kwargs):
2020
result = make_request(method=method, url=url, **kwargs)
2121
return result
2222

23-
def get_journal(self, journal_id: uuid.UUID, token: uuid.UUID) -> BugoutJournal:
24-
get_group_path = f"journals/{journal_id}"
23+
# Journal module
24+
def create_journal(self, token: uuid.UUID, name: str) -> BugoutJournal:
25+
journal_path = "journals/"
26+
json = {
27+
"name": name,
28+
}
2529
headers = {
2630
"Authorization": f"Bearer {token}",
2731
}
28-
result = self._call(method=Method.get, path=get_group_path, headers=headers)
29-
return BugoutJournal(
30-
id=result.get("id"),
31-
bugout_user_id=result.get("bugout_user_id"),
32-
holder_ids=result.get("holder_ids"),
33-
name=result.get("name"),
34-
created_at=result.get("created_at"),
35-
updated_at=result.get("updated_at"),
32+
result = self._call(
33+
method=Method.post, path=journal_path, headers=headers, json=json
3634
)
35+
return BugoutJournal(**result)
36+
37+
def list_journals(self, token: uuid.UUID) -> BugoutJournals:
38+
journal_path = "journals/"
39+
headers = {
40+
"Authorization": f"Bearer {token}",
41+
}
42+
result = self._call(method=Method.get, path=journal_path, headers=headers)
43+
return BugoutJournals(**result)
44+
45+
def get_journal(self, token: uuid.UUID, journal_id: uuid.UUID) -> BugoutJournal:
46+
journal_id_path = f"journals/{journal_id}"
47+
headers = {
48+
"Authorization": f"Bearer {token}",
49+
}
50+
result = self._call(method=Method.get, path=journal_id_path, headers=headers)
51+
return BugoutJournal(**result)
52+
53+
def update_journal(
54+
self, token: uuid.UUID, journal_id: uuid.UUID, name: str
55+
) -> BugoutJournal:
56+
journal_id_path = f"journals/{journal_id}"
57+
json = {
58+
"name": name,
59+
}
60+
headers = {
61+
"Authorization": f"Bearer {token}",
62+
}
63+
result = self._call(
64+
method=Method.put, path=journal_id_path, headers=headers, json=json
65+
)
66+
return BugoutJournal(**result)
67+
68+
def delete_journal(self, token: uuid.UUID, journal_id: uuid.UUID) -> BugoutJournal:
69+
journal_id_path = f"journals/{journal_id}"
70+
headers = {
71+
"Authorization": f"Bearer {token}",
72+
}
73+
result = self._call(method=Method.delete, path=journal_id_path, headers=headers)
74+
return BugoutJournal(**result)

0 commit comments

Comments
 (0)