Skip to content

Commit 255273d

Browse files
committed
Added journal tags handlers and finished with entries
1 parent a65010b commit 255273d

3 files changed

Lines changed: 194 additions & 15 deletions

File tree

bugout/app.py

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,63 @@ def get_entries(
241241
) -> data.BugoutJournalEntries:
242242
return self.journal.get_entries(token, journal_id)
243243

244-
def get_entry_content(self):
245-
pass
244+
def get_entry_content(
245+
self, token: uuid.UUID, journal_id: uuid.UUID, entry_id: uuid.UUID
246+
) -> data.BugoutJournalEntryContent:
247+
return self.journal.get_entry_content(token, journal_id, entry_id)
246248

247-
def update_entry_content(self):
248-
pass
249+
def update_entry_content(
250+
self,
251+
token: uuid.UUID,
252+
journal_id: uuid.UUID,
253+
entry_id: uuid.UUID,
254+
title: str,
255+
content: str,
256+
) -> data.BugoutJournalEntryContent:
257+
return self.journal.update_entry_content(
258+
token, journal_id, entry_id, title, content
259+
)
249260

250-
def delete_entry(self):
251-
pass
261+
def delete_entry(
262+
self,
263+
token: uuid.UUID,
264+
journal_id: uuid.UUID,
265+
entry_id: uuid.UUID,
266+
) -> data.BugoutJournalEntry:
267+
return self.journal.delete_entry(token, journal_id, entry_id)
252268

253269
# Tags
270+
def get_most_used_tags(self, token: uuid.UUID, journal_id: uuid.UUID) -> List[Any]:
271+
return self.journal.get_most_used_tags(token, journal_id)
272+
273+
def create_tags(
274+
self,
275+
token: uuid.UUID,
276+
journal_id: uuid.UUID,
277+
entry_id: uuid.UUID,
278+
tags: List[str],
279+
) -> List[Any]:
280+
return self.journal.create_tags(token, journal_id, entry_id, tags)
281+
282+
def get_tags(
283+
self, token: uuid.UUID, journal_id: uuid.UUID, entry_id: uuid.UUID
284+
) -> data.BugoutJournalEntryTags:
285+
return self.journal.get_tags(token, journal_id, entry_id)
286+
287+
def update_tags(
288+
self,
289+
token: uuid.UUID,
290+
journal_id: uuid.UUID,
291+
entry_id: uuid.UUID,
292+
tags: List[str],
293+
) -> List[Any]:
294+
return self.journal.update_tags(token, journal_id, entry_id, tags)
295+
296+
def delete_tag(
297+
self,
298+
token: uuid.UUID,
299+
journal_id: uuid.UUID,
300+
entry_id: uuid.UUID,
301+
tag: str,
302+
) -> data.BugoutJournalEntryTags:
303+
return self.journal.delete_tag(token, journal_id, entry_id, tag)

bugout/data.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,14 @@ class BugoutJournalEntry(BaseModel):
140140

141141
class BugoutJournalEntries(BaseModel):
142142
entries: List[BugoutJournalEntry]
143+
144+
145+
class BugoutJournalEntryContent(BaseModel):
146+
title: str
147+
content: str
148+
149+
150+
class BugoutJournalEntryTags(BaseModel):
151+
journal_id: uuid.UUID
152+
entry_id: uuid.UUID
153+
tags: List[str]

bugout/journal.py

Lines changed: 127 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
from .data import (
66
BugoutJournal,
77
BugoutJournals,
8-
BugoutScope,
98
BugoutScopes,
109
BugoutJournalScopeSpecs,
1110
BugoutJournalEntry,
1211
BugoutJournalEntries,
12+
BugoutJournalEntryContent,
13+
BugoutJournalEntryTags,
1314
HolderType,
1415
Method,
1516
)
@@ -166,7 +167,7 @@ def create_entry(
166167
context_id: Optional[str] = None,
167168
context_type: Optional[str] = None,
168169
) -> BugoutJournalEntry:
169-
journal_entry_path = f"journals/{journal_id}/entries"
170+
entry_path = f"journals/{journal_id}/entries"
170171
json = {
171172
"title": title,
172173
"content": content,
@@ -179,28 +180,145 @@ def create_entry(
179180
"Authorization": f"Bearer {token}",
180181
}
181182
result = self._call(
182-
method=Method.post, path=journal_entry_path, headers=headers, json=json
183+
method=Method.post, path=entry_path, headers=headers, json=json
183184
)
184185
return BugoutJournalEntry(**result)
185186

186187
def get_entry(
187188
self, token: uuid.UUID, journal_id: uuid.UUID, entry_id: uuid.UUID
188189
) -> BugoutJournalEntry:
189-
journal_entry_id_path = f"journals/{journal_id}/entries/{entry_id}"
190+
entry_id_path = f"journals/{journal_id}/entries/{entry_id}"
190191
headers = {
191192
"Authorization": f"Bearer {token}",
192193
}
193-
result = self._call(
194-
method=Method.get, path=journal_entry_id_path, headers=headers
195-
)
194+
result = self._call(method=Method.get, path=entry_id_path, headers=headers)
196195
return BugoutJournalEntry(**result)
197196

198197
def get_entries(
199198
self, token: uuid.UUID, journal_id: uuid.UUID
200199
) -> BugoutJournalEntries:
201-
journal_entry_path = f"journals/{journal_id}/entries"
200+
entry_path = f"journals/{journal_id}/entries"
202201
headers = {
203202
"Authorization": f"Bearer {token}",
204203
}
205-
result = self._call(method=Method.get, path=journal_entry_path, headers=headers)
204+
result = self._call(method=Method.get, path=entry_path, headers=headers)
206205
return BugoutJournalEntries(**result)
206+
207+
def get_entry_content(
208+
self, token: uuid.UUID, journal_id: uuid.UUID, entry_id: uuid.UUID
209+
) -> BugoutJournalEntryContent:
210+
entry_id_content_path = f"journals/{journal_id}/entries/{entry_id}/content"
211+
headers = {
212+
"Authorization": f"Bearer {token}",
213+
}
214+
result = self._call(
215+
method=Method.get, path=entry_id_content_path, headers=headers
216+
)
217+
return BugoutJournalEntryContent(**result)
218+
219+
def update_entry_content(
220+
self,
221+
token: uuid.UUID,
222+
journal_id: uuid.UUID,
223+
entry_id: uuid.UUID,
224+
title: str,
225+
content: str,
226+
) -> BugoutJournalEntryContent:
227+
entry_id_content_path = f"journals/{journal_id}/entries/{entry_id}/content"
228+
json = {
229+
"title": title,
230+
"content": content,
231+
}
232+
headers = {
233+
"Authorization": f"Bearer {token}",
234+
}
235+
result = self._call(
236+
method=Method.put,
237+
path=entry_id_content_path,
238+
headers=headers,
239+
json=json,
240+
)
241+
return BugoutJournalEntryContent(**result)
242+
243+
def delete_entry(
244+
self,
245+
token: uuid.UUID,
246+
journal_id: uuid.UUID,
247+
entry_id: uuid.UUID,
248+
) -> BugoutJournalEntry:
249+
entry_id_path = f"journals/{journal_id}/entries/{entry_id}"
250+
headers = {
251+
"Authorization": f"Bearer {token}",
252+
}
253+
result = self._call(method=Method.delete, path=entry_id_path, headers=headers)
254+
return BugoutJournalEntry(**result)
255+
256+
# Tags modules
257+
def get_most_used_tags(self, token: uuid.UUID, journal_id: uuid.UUID) -> List[Any]:
258+
tags_path = f"journals/{journal_id}/tags"
259+
headers = {
260+
"Authorization": f"Bearer {token}",
261+
}
262+
result = self._call(method=Method.get, path=tags_path, headers=headers)
263+
return result
264+
265+
def create_tags(
266+
self,
267+
token: uuid.UUID,
268+
journal_id: uuid.UUID,
269+
entry_id: uuid.UUID,
270+
tags: List[str],
271+
) -> List[Any]:
272+
tags_path = f"journals/{journal_id}/entries/{entry_id}/tags"
273+
json = {"tags": tags}
274+
headers = {
275+
"Authorization": f"Bearer {token}",
276+
}
277+
result = self._call(
278+
method=Method.post, path=tags_path, headers=headers, json=json
279+
)
280+
return result
281+
282+
def get_tags(
283+
self, token: uuid.UUID, journal_id: uuid.UUID, entry_id: uuid.UUID
284+
) -> BugoutJournalEntryTags:
285+
tags_path = f"journals/{journal_id}/entries/{entry_id}/tags"
286+
headers = {
287+
"Authorization": f"Bearer {token}",
288+
}
289+
result = self._call(method=Method.get, path=tags_path, headers=headers)
290+
return BugoutJournalEntryTags(**result)
291+
292+
def update_tags(
293+
self,
294+
token: uuid.UUID,
295+
journal_id: uuid.UUID,
296+
entry_id: uuid.UUID,
297+
tags: List[str],
298+
) -> List[Any]:
299+
tags_path = f"journals/{journal_id}/entries/{entry_id}/tags"
300+
json = {"tags": tags}
301+
headers = {
302+
"Authorization": f"Bearer {token}",
303+
}
304+
result = self._call(
305+
method=Method.put, path=tags_path, headers=headers, json=json
306+
)
307+
return result
308+
309+
def delete_tag(
310+
self,
311+
token: uuid.UUID,
312+
journal_id: uuid.UUID,
313+
entry_id: uuid.UUID,
314+
tag: str,
315+
) -> BugoutJournalEntryTags:
316+
tags_path = f"journals/{journal_id}/entries/{entry_id}/tags"
317+
json = {"tag": tag}
318+
headers = {
319+
"Authorization": f"Bearer {token}",
320+
}
321+
result = self._call(
322+
method=Method.delete, path=tags_path, headers=headers, json=json
323+
)
324+
return BugoutJournalEntryTags(**result)

0 commit comments

Comments
 (0)