Skip to content

Commit

Permalink
Merge pull request #33 from bugout-dev/fix-search-add-order
Browse files Browse the repository at this point in the history
Added order argument to journal search method
  • Loading branch information
kompotkot authored Aug 20, 2021
2 parents 9e84da9 + 3aad3f3 commit 4629eb4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bugout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

__email__ = "[email protected]"
__license__ = "MIT"
__version__ = "0.1.16"
__version__ = "0.1.17"

__all__ = (
"__author__",
Expand Down
5 changes: 3 additions & 2 deletions bugout/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .calls import ping
from .group import Group
from .humbug import Humbug
from .journal import Journal
from .journal import Journal, SearchOrder
from .resource import Resource
from .user import User
from .settings import BUGOUT_BROOD_URL, BUGOUT_SPIRE_URL, REQUESTS_TIMEOUT
Expand Down Expand Up @@ -685,10 +685,11 @@ def search(
offset: int = 0,
content: bool = True,
timeout: float = REQUESTS_TIMEOUT,
order: SearchOrder = SearchOrder.DESCENDING,
) -> data.BugoutSearchResults:
self.journal.timeout = timeout
return self.journal.search(
token, journal_id, query, filters, limit, offset, content
token, journal_id, query, filters, limit, offset, content, order=order
)

# Public
Expand Down
8 changes: 8 additions & 0 deletions bugout/journal.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from enum import Enum
from typing import Any, List, Optional, Union
import uuid

Expand All @@ -22,6 +23,11 @@
from .settings import REQUESTS_TIMEOUT


class SearchOrder(Enum):
ASCENDING = "asc"
DESCENDING = "desc"


class Journal:
"""
Represent a journal from Bugout.
Expand Down Expand Up @@ -410,6 +416,7 @@ def search(
limit: int = 10,
offset: int = 0,
content: bool = True,
order: SearchOrder = SearchOrder.DESCENDING,
) -> BugoutSearchResults:
search_path = f"journals/{journal_id}/search"
headers = {
Expand All @@ -421,6 +428,7 @@ def search(
"limit": limit,
"offset": offset,
"content": content,
"order": order.value,
}
result = self._call(
method=Method.get, path=search_path, params=query_params, headers=headers
Expand Down

0 comments on commit 4629eb4

Please sign in to comment.