summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2018-12-13 18:52:34 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2018-12-13 18:52:34 +0100
commit36197b2265fea13237777ce36ce4e9584438f4c8 (patch)
tree4cfa147eb23668bd4836187c788a2901bb8f2a3d
parent645dd65d30b6e97a0a8e194aff2fe9d29fb77862 (diff)
downloadbank-36197b2265fea13237777ce36ce4e9584438f4c8.tar.gz
bank-36197b2265fea13237777ce36ce4e9584438f4c8.tar.bz2
bank-36197b2265fea13237777ce36ce4e9584438f4c8.zip
/history API refactoring.
'start' parameter defaults to MAX_UINT64, as when it's not given the user is likely to want the X youngest records (in descending order).
-rw-r--r--talerbank/app/tests.py10
-rw-r--r--talerbank/app/views.py10
2 files changed, 9 insertions, 11 deletions
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index 61d2639..695ef33 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -411,17 +411,17 @@ class HistoryTestCase(TestCase):
for ctx in (
HistoryContext(
expected_resp={"status": 200},
- delta="4", direction="both"),
+ delta="-4", direction="both"),
HistoryContext(
expected_resp={
- "fields": [("row_id", 6)],
+ "fields": [("row_id", 9)],
"status": 200},
delta="+1", start="5", direction="both"),
HistoryContext(
expected_resp={
"fields": [("wt_subject", "a")],
"status": 200},
- delta="-1", start=9, direction="both"),
+ delta="-1", start=2, direction="both"),
HistoryContext(
expected_resp={"status": 204},
delta="1", start="11", direction="both"),
@@ -442,7 +442,7 @@ class HistoryTestCase(TestCase):
expected_resp={"status": 204},
delta="+1", direction="cancel+"),
HistoryContext(expected_resp={"status": 200},
- delta="+1", direction="debit")):
+ delta="-1", direction="debit")):
response = self.client.get(
reverse("history", urlconf=urls), ctx.urlargs,
**{"HTTP_X_TALER_BANK_USERNAME": "User",
@@ -680,7 +680,7 @@ class BalanceTestCase(TestCase):
response = self.client.get(
reverse("history", urlconf=urls),
{"auth": "basic",
- "delta": 30,
+ "delta": -30,
"direction": "both",
"account_number": 55}, # unused
**{"HTTP_X_TALER_BANK_USERNAME": "U0",
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 9583dff..7a974df 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -44,6 +44,8 @@ from .amount import Amount
from .schemas import validate_data
LOGGER = logging.getLogger(__name__)
+MAX_UINT64 = (2**64) - 1
+
class LoginFailed(Exception):
hint = "Wrong username/password"
http_status_code = 401
@@ -421,7 +423,7 @@ def query_history(bank_account,
delta,
start,
sign,
- descending=False):
+ descending=True):
qs = query_history_raw(bank_account,
direction,
@@ -449,10 +451,6 @@ def query_history_raw(bank_account, direction, start, sign):
"-": Q(id__lt=start),
}
- # Handle special case.
- if start < 0: # return all the records.
- sign = "+"
-
return BankTransaction.objects.filter(
direction_switch.get(direction),
sign_filter.get(sign));
@@ -474,7 +472,7 @@ def serve_history(request, user_account):
qs = query_history(user_account.bankaccount,
request.GET.get("direction"),
int(parsed_delta.group(2)),
- int(request.GET.get("start", -1)),
+ int(request.GET.get("start", MAX_UINT64)),
sign if sign else "+")
history = []