Skip to content

Commit 1b89009

Browse files
authored
Merge pull request #4 from bugout-dev/journals
Journals
2 parents dcd0008 + 6eb71b4 commit 1b89009

4 files changed

Lines changed: 571 additions & 16 deletions

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.0.5"
10+
__version__ = "0.0.6"
1111

1212
__all__ = (
1313
"__author__",

bugout/app.py

Lines changed: 151 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,157 @@ 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 list_scopes(self, token: uuid.UUID, api: str) -> data.BugoutScopes:
158+
return self.journal.list_scopes(token, api)
159+
160+
def get_journal_scopes(
161+
self, token: uuid.UUID, journal_id: uuid.UUID
162+
) -> data.BugoutJournalScopeSpecs:
163+
return self.journal.get_journal_scopes(token, journal_id)
164+
165+
def update_journal_scopes(
166+
self,
167+
token: uuid.UUID,
168+
journal_id: uuid.UUID,
169+
holder_type: data.HolderType,
170+
holder_id: uuid.UUID,
171+
permission_list: List[str],
172+
) -> data.BugoutJournalScopeSpecs:
173+
return self.journal.update_journal_scopes(
174+
token, journal_id, holder_type, holder_id, permission_list
175+
)
176+
177+
def delete_journal_scopes(
178+
self,
179+
token: uuid.UUID,
180+
journal_id: uuid.UUID,
181+
holder_type: data.HolderType,
182+
holder_id: uuid.UUID,
183+
permission_list: List[str],
184+
) -> data.BugoutJournalScopeSpecs:
185+
return self.journal.delete_journal_scopes(
186+
token, journal_id, holder_type, holder_id, permission_list
187+
)
188+
156189
# Journal handlers
190+
def create_journal(self, token: uuid.UUID, name: str) -> data.BugoutJournal:
191+
return self.journal.create_journal(token, name)
192+
193+
def list_journals(self, token: uuid.UUID) -> data.BugoutJournals:
194+
return self.journal.list_journals(token)
195+
157196
def get_journal(
158-
self, journal_id: uuid.UUID, token: uuid.UUID
197+
self, token: uuid.UUID, journal_id: uuid.UUID
198+
) -> data.BugoutJournal:
199+
return self.journal.get_journal(token, journal_id)
200+
201+
def update_journal(
202+
self, token: uuid.UUID, journal_id: uuid.UUID, name: str
203+
) -> data.BugoutJournal:
204+
return self.journal.update_journal(token, journal_id, name)
205+
206+
def delete_journal(
207+
self, token: uuid.UUID, journal_id: uuid.UUID
159208
) -> data.BugoutJournal:
160-
return self.journal.get_journal(journal_id, token)
209+
return self.journal.delete_journal(token, journal_id)
210+
211+
# Journal entries
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+
)
233+
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)
238+
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)
243+
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)
248+
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+
)
260+
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)
268+
269+
# 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)
304+
305+
# Search
306+
def search(
307+
self, token: uuid.UUID, journal_id: uuid.UUID, **queries: Dict[str, Any]
308+
) -> data.BugoutSearchResults:
309+
return self.journal.search(token, journal_id, **queries)

bugout/data.py

Lines changed: 88 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
@@ -27,6 +27,12 @@ class TokenType(Enum):
2727
github = "github"
2828

2929

30+
@unique
31+
class HolderType(Enum):
32+
user = "user"
33+
group = "group"
34+
35+
3036
class BugoutUser(BaseModel):
3137
id: uuid.UUID = Field(alias="user_id")
3238
username: str
@@ -85,10 +91,90 @@ class BugoutGroupMembers(BaseModel):
8591
users: List[BugoutUserShort]
8692

8793

94+
class BugoutScope(BaseModel):
95+
api: str
96+
scope: str
97+
description: str
98+
99+
100+
class BugoutScopes(BaseModel):
101+
scopes: List[BugoutScope]
102+
103+
104+
class BugoutJournalScopeSpec(BaseModel):
105+
journal_id: uuid.UUID
106+
holder_type: HolderType
107+
holder_id: str
108+
permission: str
109+
110+
111+
class BugoutJournalScopeSpecs(BaseModel):
112+
scopes: List[BugoutJournalScopeSpec]
113+
114+
88115
class BugoutJournal(BaseModel):
89116
id: uuid.UUID
90117
bugout_user_id: uuid.UUID
91-
holder_ids: List[uuid.UUID]
118+
holder_ids: Set[uuid.UUID] = Field(default_factory=set)
92119
name: str
93120
created_at: datetime
94121
updated_at: datetime
122+
123+
124+
class BugoutJournals(BaseModel):
125+
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]
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]
154+
155+
156+
class BugoutSearchFields(BaseModel):
157+
query: str = ""
158+
filters: Optional[List[str]] = None
159+
limit: int = 10
160+
offset: int = 0
161+
content: Optional[bool] = True
162+
163+
164+
class BugoutSearchResult(BaseModel):
165+
entry_url: str
166+
content_url: str
167+
title: str
168+
content: Optional[str]
169+
tags: List[str]
170+
created_at: str
171+
updated_at: str
172+
score: float
173+
174+
175+
class BugoutSearchResults(BaseModel):
176+
total_results: int
177+
offset: int
178+
next_offset: Optional[int]
179+
max_score: float
180+
results: List[BugoutSearchResult]

0 commit comments

Comments
 (0)