Skip to content

Commit c258e57

Browse files
authored
Merge pull request #18 from bugout-dev/fix-journal-search
Fixed broken journal search
2 parents 1c58b6a + fc81ecd commit c258e57

File tree

7 files changed

+47
-52
lines changed

7 files changed

+47
-52
lines changed

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.1.4"
10+
__version__ = "0.1.5"
1111

1212
__all__ = (
1313
"__author__",

bugout/app.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ def get_group(
192192

193193
def find_group(
194194
self,
195+
token: Union[str, uuid.UUID],
195196
group_id: Optional[Union[str, uuid.UUID]] = None,
196197
name: Optional[str] = None,
197-
token: Union[str, uuid.UUID] = None,
198198
timeout: float = REQUESTS_TIMEOUT,
199199
) -> data.BugoutGroup:
200200
self.user.timeout = timeout
201-
return self.group.find_group(group_id=group_id, name=name, token=token)
201+
return self.group.find_group(token=token, group_id=group_id, name=name)
202202

203203
def get_user_groups(
204204
self, token: Union[str, uuid.UUID], timeout: float = REQUESTS_TIMEOUT
@@ -525,8 +525,11 @@ def search(
525525
self,
526526
token: Union[str, uuid.UUID],
527527
journal_id: Union[str, uuid.UUID],
528+
query: str,
529+
limit: int = 10,
530+
offset: int = 0,
531+
content: bool = True,
528532
timeout: float = REQUESTS_TIMEOUT,
529-
**queries: Dict[str, Any],
530533
) -> data.BugoutSearchResults:
531534
self.journal.timeout = timeout
532-
return self.journal.search(token=token, journal_id=journal_id, **queries)
535+
return self.journal.search(token, journal_id, query, limit, offset, content)

bugout/data.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,6 @@ class BugoutJournalEntryTags(BaseModel):
153153
tags: List[str]
154154

155155

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-
164156
class BugoutSearchResult(BaseModel):
165157
entry_url: str
166158
content_url: str

bugout/group.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,29 @@ def get_group(
4949

5050
def find_group(
5151
self,
52+
token: Union[str, uuid.UUID],
5253
group_id: Optional[Union[str, uuid.UUID]] = None,
5354
name: Optional[str] = None,
54-
token: Union[str, uuid.UUID] = None,
5555
) -> BugoutGroup:
5656
find_group_path = f"group/find"
57-
if group_id is not None and name is None:
58-
find_group_path += f"?group_id={group_id}"
59-
elif group_id is None and name is not None:
60-
find_group_path += f"?name={name}"
61-
elif group_id is not None and name is not None:
62-
find_group_path += f"?group_id={group_id}&name={name}"
57+
if group_id is None and name is None:
58+
raise GroupInvalidParameters(
59+
"In order to find group, at least one of name, or id must be specified"
60+
)
61+
query_params = {}
62+
if group_id is not None:
63+
query_params.update({"group_id": group_id})
64+
if name is not None:
65+
query_params.update({"name": name})
6366
headers = {
6467
"Authorization": f"Bearer {token}",
6568
}
66-
result = self._call(method=Method.get, path=find_group_path, headers=headers)
69+
result = self._call(
70+
method=Method.get,
71+
path=find_group_path,
72+
params=query_params,
73+
headers=headers,
74+
)
6775
return BugoutGroup(**result)
6876

6977
def get_user_groups(self, token: Union[str, uuid.UUID]) -> BugoutUserGroups:

bugout/journal.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
BugoutJournalEntries,
1212
BugoutJournalEntryContent,
1313
BugoutJournalEntryTags,
14-
BugoutSearchFields,
1514
BugoutSearchResults,
1615
HolderType,
1716
Method,
@@ -344,34 +343,26 @@ def delete_tag(
344343
return BugoutJournalEntryTags(**result)
345344

346345
# Search module
347-
def _search_query(self, search_path: str, **queries: Dict[str, Any]) -> str:
348-
"""
349-
Validate search arguments with pydantic model BugoutSearchFields and
350-
generate search_path with queries.
351-
"""
352-
field_queries = BugoutSearchFields(**queries)
353-
fields_list = list(BugoutSearchFields.schema().get("properties").keys()) # type: ignore
354-
355-
search_path += f"?{fields_list[0]}={getattr(field_queries, fields_list[0])}"
356-
for field in fields_list[1:]:
357-
attr = getattr(field_queries, field)
358-
if type(attr) is list:
359-
attr = ",".join(attr)
360-
search_path += f"&{field}={attr}"
361-
362-
return search_path
363-
364346
def search(
365347
self,
366348
token: Union[str, uuid.UUID],
367349
journal_id: Union[str, uuid.UUID],
368-
**queries: Dict[str, Any],
350+
query: str,
351+
limit: int = 10,
352+
offset: int = 0,
353+
content: bool = True,
369354
) -> BugoutSearchResults:
370-
search_path_org = f"journals/{journal_id}/search"
371-
search_path = self._search_query(search_path=search_path_org, **queries)
372-
355+
search_path = f"journals/{journal_id}/search"
373356
headers = {
374357
"Authorization": f"Bearer {token}",
375358
}
376-
result = self._call(method=Method.get, path=search_path, headers=headers)
359+
query_params = {
360+
"q": query,
361+
"limit": limit,
362+
"offset": offset,
363+
"content": content,
364+
}
365+
result = self._call(
366+
method=Method.get, path=search_path, params=query_params, headers=headers
367+
)
377368
return BugoutSearchResults(**result)

bugout/user.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,15 @@ def get_user_tokens(
222222
headers = {
223223
"Authorization": f"Bearer {token}",
224224
}
225-
if active is not None and token_type is None:
226-
get_user_tokens_path += f"?active={active}"
227-
elif active is None and token_type is not None:
228-
get_user_tokens_path += f"?token_type={token_type.value}"
229-
elif active is not None and token_type is not None:
230-
get_user_tokens_path += f"?active={active}&token_type={token_type.value}"
225+
query_params = {}
226+
if active is not None:
227+
query_params.update({"active": str(int(active))})
228+
if token_type is not None:
229+
query_params.update({"token_type": token_type.value})
231230
result = self._call(
232-
method=Method.get, path=get_user_tokens_path, headers=headers
231+
method=Method.get,
232+
path=get_user_tokens_path,
233+
params=query_params,
234+
headers=headers,
233235
)
234236
return BugoutUserTokens(**result)

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
from importlib.machinery import SourceFileLoader
3-
from pkg_resources import parse_requirements
43
from setuptools import find_packages, setup
54

65
MODULE_NAME = "bugout"

0 commit comments

Comments
 (0)