Skip to content

Commit a65010b

Browse files
committed
Added main entry handlers
1 parent 74d8435 commit a65010b

3 files changed

Lines changed: 152 additions & 59 deletions

File tree

bugout/app.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,37 @@ def delete_journal(
209209
return self.journal.delete_journal(token, journal_id)
210210

211211
# Journal entries
212-
def create_entry(self):
213-
pass
212+
def create_entry(
213+
self,
214+
token: uuid.UUID,
215+
journal_id: uuid.UUID,
216+
title: str,
217+
content: str,
218+
tags: List[str] = [],
219+
context_url: Optional[str] = None,
220+
context_id: Optional[str] = None,
221+
context_type: Optional[str] = None,
222+
) -> data.BugoutJournalEntry:
223+
return self.journal.create_entry(
224+
token,
225+
journal_id,
226+
title,
227+
content,
228+
tags,
229+
context_url,
230+
context_id,
231+
context_type,
232+
)
214233

215-
def get_entry(self):
216-
pass
234+
def get_entry(
235+
self, token: uuid.UUID, journal_id: uuid.UUID, entry_id: uuid.UUID
236+
) -> data.BugoutJournalEntry:
237+
return self.journal.get_entry(token, journal_id, entry_id)
217238

218-
def get_entries(self):
219-
pass
239+
def get_entries(
240+
self, token: uuid.UUID, journal_id: uuid.UUID
241+
) -> data.BugoutJournalEntries:
242+
return self.journal.get_entries(token, journal_id)
220243

221244
def get_entry_content(self):
222245
pass

bugout/data.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,20 @@ class BugoutJournal(BaseModel):
123123

124124
class BugoutJournals(BaseModel):
125125
journals: List[BugoutJournal]
126+
127+
128+
class BugoutJournalEntry(BaseModel):
129+
id: uuid.UUID
130+
journal_url: str
131+
content_url: Optional[str]
132+
title: Optional[str]
133+
content: Optional[str]
134+
tags: List[str] = Field(default_factory=list)
135+
created_at: datetime
136+
updated_at: datetime
137+
context_url: Optional[str]
138+
context_type: Optional[str]
139+
140+
141+
class BugoutJournalEntries(BaseModel):
142+
entries: List[BugoutJournalEntry]

bugout/journal.py

Lines changed: 106 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
BugoutScope,
99
BugoutScopes,
1010
BugoutJournalScopeSpecs,
11+
BugoutJournalEntry,
12+
BugoutJournalEntries,
1113
HolderType,
1214
Method,
1315
)
@@ -28,59 +30,6 @@ def _call(self, method: Method, path: str, **kwargs):
2830
result = make_request(method=method, url=url, **kwargs)
2931
return result
3032

31-
# Journal module
32-
def create_journal(self, token: uuid.UUID, name: str) -> BugoutJournal:
33-
journal_path = "journals/"
34-
json = {
35-
"name": name,
36-
}
37-
headers = {
38-
"Authorization": f"Bearer {token}",
39-
}
40-
result = self._call(
41-
method=Method.post, path=journal_path, headers=headers, json=json
42-
)
43-
return BugoutJournal(**result)
44-
45-
def list_journals(self, token: uuid.UUID) -> BugoutJournals:
46-
journal_path = "journals/"
47-
headers = {
48-
"Authorization": f"Bearer {token}",
49-
}
50-
result = self._call(method=Method.get, path=journal_path, headers=headers)
51-
return BugoutJournals(**result)
52-
53-
def get_journal(self, token: uuid.UUID, journal_id: uuid.UUID) -> BugoutJournal:
54-
journal_id_path = f"journals/{journal_id}"
55-
headers = {
56-
"Authorization": f"Bearer {token}",
57-
}
58-
result = self._call(method=Method.get, path=journal_id_path, headers=headers)
59-
return BugoutJournal(**result)
60-
61-
def update_journal(
62-
self, token: uuid.UUID, journal_id: uuid.UUID, name: str
63-
) -> BugoutJournal:
64-
journal_id_path = f"journals/{journal_id}"
65-
json = {
66-
"name": name,
67-
}
68-
headers = {
69-
"Authorization": f"Bearer {token}",
70-
}
71-
result = self._call(
72-
method=Method.put, path=journal_id_path, headers=headers, json=json
73-
)
74-
return BugoutJournal(**result)
75-
76-
def delete_journal(self, token: uuid.UUID, journal_id: uuid.UUID) -> BugoutJournal:
77-
journal_id_path = f"journals/{journal_id}"
78-
headers = {
79-
"Authorization": f"Bearer {token}",
80-
}
81-
result = self._call(method=Method.delete, path=journal_id_path, headers=headers)
82-
return BugoutJournal(**result)
83-
8433
# Scope module
8534
def list_scopes(self, token: uuid.UUID, api: str) -> BugoutScopes:
8635
scopes_path = f"journals/scopes"
@@ -151,3 +100,107 @@ def delete_journal_scopes(
151100
method=Method.delete, path=journal_scopes_path, headers=headers, json=json
152101
)
153102
return BugoutJournalScopeSpecs(**result)
103+
104+
# Journal module
105+
def create_journal(self, token: uuid.UUID, name: str) -> BugoutJournal:
106+
journal_path = "journals/"
107+
json = {
108+
"name": name,
109+
}
110+
headers = {
111+
"Authorization": f"Bearer {token}",
112+
}
113+
result = self._call(
114+
method=Method.post, path=journal_path, headers=headers, json=json
115+
)
116+
return BugoutJournal(**result)
117+
118+
def list_journals(self, token: uuid.UUID) -> BugoutJournals:
119+
journal_path = "journals/"
120+
headers = {
121+
"Authorization": f"Bearer {token}",
122+
}
123+
result = self._call(method=Method.get, path=journal_path, headers=headers)
124+
return BugoutJournals(**result)
125+
126+
def get_journal(self, token: uuid.UUID, journal_id: uuid.UUID) -> BugoutJournal:
127+
journal_id_path = f"journals/{journal_id}"
128+
headers = {
129+
"Authorization": f"Bearer {token}",
130+
}
131+
result = self._call(method=Method.get, path=journal_id_path, headers=headers)
132+
return BugoutJournal(**result)
133+
134+
def update_journal(
135+
self, token: uuid.UUID, journal_id: uuid.UUID, name: str
136+
) -> BugoutJournal:
137+
journal_id_path = f"journals/{journal_id}"
138+
json = {
139+
"name": name,
140+
}
141+
headers = {
142+
"Authorization": f"Bearer {token}",
143+
}
144+
result = self._call(
145+
method=Method.put, path=journal_id_path, headers=headers, json=json
146+
)
147+
return BugoutJournal(**result)
148+
149+
def delete_journal(self, token: uuid.UUID, journal_id: uuid.UUID) -> BugoutJournal:
150+
journal_id_path = f"journals/{journal_id}"
151+
headers = {
152+
"Authorization": f"Bearer {token}",
153+
}
154+
result = self._call(method=Method.delete, path=journal_id_path, headers=headers)
155+
return BugoutJournal(**result)
156+
157+
# Entry module
158+
def create_entry(
159+
self,
160+
token: uuid.UUID,
161+
journal_id: uuid.UUID,
162+
title: str,
163+
content: str,
164+
tags: List[str] = [],
165+
context_url: Optional[str] = None,
166+
context_id: Optional[str] = None,
167+
context_type: Optional[str] = None,
168+
) -> BugoutJournalEntry:
169+
journal_entry_path = f"journals/{journal_id}/entries"
170+
json = {
171+
"title": title,
172+
"content": content,
173+
"tags": tags,
174+
"context_url": context_url,
175+
"context_id": context_id,
176+
"context_type": context_type,
177+
}
178+
headers = {
179+
"Authorization": f"Bearer {token}",
180+
}
181+
result = self._call(
182+
method=Method.post, path=journal_entry_path, headers=headers, json=json
183+
)
184+
return BugoutJournalEntry(**result)
185+
186+
def get_entry(
187+
self, token: uuid.UUID, journal_id: uuid.UUID, entry_id: uuid.UUID
188+
) -> BugoutJournalEntry:
189+
journal_entry_id_path = f"journals/{journal_id}/entries/{entry_id}"
190+
headers = {
191+
"Authorization": f"Bearer {token}",
192+
}
193+
result = self._call(
194+
method=Method.get, path=journal_entry_id_path, headers=headers
195+
)
196+
return BugoutJournalEntry(**result)
197+
198+
def get_entries(
199+
self, token: uuid.UUID, journal_id: uuid.UUID
200+
) -> BugoutJournalEntries:
201+
journal_entry_path = f"journals/{journal_id}/entries"
202+
headers = {
203+
"Authorization": f"Bearer {token}",
204+
}
205+
result = self._call(method=Method.get, path=journal_entry_path, headers=headers)
206+
return BugoutJournalEntries(**result)

0 commit comments

Comments
 (0)