From 3aad3f3a231f01375578020135e8b7b858f8509c Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Fri, 20 Aug 2021 13:10:15 -0700 Subject: [PATCH] Added order argument to journal search method The values come from the `bugout.journal.SearchOrder` enum. Bumped version to `0.1.17`. --- bugout/__init__.py | 2 +- bugout/app.py | 5 +++-- bugout/journal.py | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bugout/__init__.py b/bugout/__init__.py index 4c4ba5f..df5ba4b 100644 --- a/bugout/__init__.py +++ b/bugout/__init__.py @@ -7,7 +7,7 @@ __email__ = "engineering@bugout.dev" __license__ = "MIT" -__version__ = "0.1.16" +__version__ = "0.1.17" __all__ = ( "__author__", diff --git a/bugout/app.py b/bugout/app.py index f44982f..91c9efe 100644 --- a/bugout/app.py +++ b/bugout/app.py @@ -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 @@ -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 diff --git a/bugout/journal.py b/bugout/journal.py index f19bf60..125db11 100644 --- a/bugout/journal.py +++ b/bugout/journal.py @@ -1,3 +1,4 @@ +from enum import Enum from typing import Any, List, Optional, Union import uuid @@ -22,6 +23,11 @@ from .settings import REQUESTS_TIMEOUT +class SearchOrder(Enum): + ASCENDING = "asc" + DESCENDING = "desc" + + class Journal: """ Represent a journal from Bugout. @@ -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 = { @@ -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