Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit e0fa4e7

Browse files
poetry.lock
1 parent 16f4dc2 commit e0fa4e7

File tree

2 files changed

+9
-28
lines changed

2 files changed

+9
-28
lines changed

src/stapi_fastapi/routers/root_router.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ async def get_orders(
176176
type=TYPE_JSON,
177177
)
178178
)
179-
if token: # only return pagination link if backend returns token
179+
if token: # pagination link if backend returns token
180180
query = request.url.components.query
181181
params = {
182182
param.split("=")[0]: param.split("=")[1]
183183
for param in query.split("&")
184184
}
185-
params["next"] = token # replace/add token
185+
params["next"] = token
186186
updated_url = request.url.replace_query_params(**params)
187187
collections.links.append(
188188
Link(href=str(updated_url), rel="next", type=TYPE_JSON)

tests/application.py

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,13 @@ async def get_orders(
4747
self, request: Request, next: str | None = None, limit: int | None = None
4848
) -> ResultE[tuple[OrderCollection, str]]:
4949
"""
50-
Show all orders.
50+
Return orders from backend. Handle pagination/limit if applicable
5151
"""
52-
# it limit does NOT reach the last index in the db list THEN we return token
52+
features = list(self._orders_db._orders.values())
53+
if limit and not next:
54+
return Success((OrderCollection(features=features[:limit]), ""))
55+
if next:
5356

54-
# if no limit - no token since getting all records - return no token
55-
# backend determines if we return a token
56-
if next: # initial implementation - if given a token, assume we continue pagination and return a new token
57-
features = list(self._orders_db._orders.values())
58-
59-
# get records based on limit
6057
def token_processor(next: str) -> tuple[str, int]:
6158
"""process token to return new token and start loc"""
6259
return "new_token", 0
@@ -68,28 +65,12 @@ def token_processor(next: str) -> tuple[str, int]:
6865
else:
6966
features = features[start:limit]
7067
return Success((OrderCollection(features=features), token))
71-
else: # if no limit with token
68+
else: # token and no limit
7269
return Success((OrderCollection(features=features[start:]), ""))
73-
else: # no input token means give us everything and return no token
70+
else:
7471
return Success(
7572
(OrderCollection(features=list(self._orders_db._orders.values())), "")
7673
)
77-
# need to be agnostic to token here. If we have MORE records we COULD return - i.e. final index found by limit, then we return a token. If we return the last record THEN return EMPTY token.
78-
# token = ''
79-
# if not limit:
80-
# limit = 0
81-
# # parse token here and do stuff to get starting index
82-
# start_index = 0
83-
# end_index = start_index + limit
84-
# if not limit:
85-
# collection = OrderCollection(features=list(self._orders_db._orders.values()))
86-
# else:
87-
# all_orders = list(self._orders_db._orders.values())
88-
# features = [all_orders[i] for i in indicies if 0 <= i < len(lst)]
89-
# collection =
90-
return Success(
91-
(OrderCollection(features=list(self._orders_db._orders.values())), "")
92-
)
9374

9475
async def get_order(self, order_id: str, request: Request) -> ResultE[Maybe[Order]]:
9576
"""

0 commit comments

Comments
 (0)