|
1 | | -from typing import Protocol |
| 1 | +from typing import Any, Callable, Coroutine, TypeVar |
2 | 2 |
|
3 | 3 | from fastapi import Request |
4 | 4 | from returns.maybe import Maybe |
|
9 | 9 | OrderStatus, |
10 | 10 | ) |
11 | 11 |
|
| 12 | +GetOrders = Callable[ |
| 13 | + [str | None, int, Request], |
| 14 | + Coroutine[Any, Any, ResultE[tuple[list[Order], Maybe[str]]]], |
| 15 | +] |
| 16 | +""" |
| 17 | +Type alias for an async function that returns a list of existing Orders. |
12 | 18 |
|
13 | | -class RootBackend[T: OrderStatus](Protocol): # pragma: nocover |
14 | | - async def get_orders( |
15 | | - self, request: Request, next: str | None, limit: int |
16 | | - ) -> ResultE[tuple[list[Order], Maybe[str]]]: |
17 | | - """ |
18 | | - Return a list of existing orders and pagination token if applicable. |
19 | | - """ |
20 | | - ... |
| 19 | +Args: |
| 20 | + next (str | None): A pagination token. |
| 21 | + limit (int): The maximum number of orders to return in a page. |
| 22 | + request (Request): FastAPI's Request object. |
21 | 23 |
|
22 | | - async def get_order(self, order_id: str, request: Request) -> ResultE[Maybe[Order]]: |
23 | | - """ |
24 | | - Get details for order with `order_id`. |
| 24 | +Returns: |
| 25 | + A tuple containing a list of orders and a pagination token. |
25 | 26 |
|
26 | | - Should return returns.results.Success[Order] if order is found. |
| 27 | + - Should return returns.result.Success[tuple[list[Order], returns.maybe.Some[str]]] if including a pagination token |
| 28 | + - Should return returns.result.Success[tuple[list[Order], returns.maybe.Nothing]] if not including a pagination token |
| 29 | + - Returning returns.result.Failure[Exception] will result in a 500. |
| 30 | +""" |
27 | 31 |
|
28 | | - Should return returns.results.Failure[returns.maybe.Nothing] if the |
29 | | - order is not found or if access is denied. |
| 32 | +GetOrder = Callable[[str, Request], Coroutine[Any, Any, ResultE[Maybe[Order]]]] |
| 33 | +""" |
| 34 | +Type alias for an async function that gets details for the order with `order_id`. |
30 | 35 |
|
31 | | - A Failure[Exception] will result in a 500. |
32 | | - """ |
33 | | - ... |
| 36 | +Args: |
| 37 | + order_id (str): The order ID. |
| 38 | + request (Request): FastAPI's Request object. |
34 | 39 |
|
35 | | - async def get_order_statuses( |
36 | | - self, order_id: str, request: Request, next: str | None, limit: int |
37 | | - ) -> ResultE[tuple[list[T], Maybe[str]]]: |
38 | | - """ |
39 | | - Get statuses for order with `order_id` and return pagination token if applicable |
| 40 | +Returns: |
| 41 | + - Should return returns.result.Success[returns.maybe.Some[Order]] if order is found. |
| 42 | + - Should return returns.result.Success[returns.maybe.Nothing] if the order is not |
| 43 | + found or if access is denied. |
| 44 | + - Returning returns.result.Failure[Exception] will result in a 500. |
| 45 | +""" |
40 | 46 |
|
41 | | - Should return returns.results.Success[list[OrderStatus]] if order is found. |
42 | 47 |
|
43 | | - Should return returns.results.Failure[Exception] if the order is |
44 | | - not found or if access is denied. |
| 48 | +T = TypeVar("T", bound=OrderStatus) |
45 | 49 |
|
46 | | - A Failure[Exception] will result in a 500. |
47 | | - """ |
48 | | - ... |
| 50 | + |
| 51 | +GetOrderStatuses = Callable[ |
| 52 | + [str, str | None, int, Request], |
| 53 | + Coroutine[Any, Any, ResultE[tuple[list[T], Maybe[str]]]], |
| 54 | +] |
| 55 | +""" |
| 56 | +Type alias for an async function that gets statuses for the order with `order_id`. |
| 57 | +
|
| 58 | +Args: |
| 59 | + order_id (str): The order ID. |
| 60 | + next (str | None): A pagination token. |
| 61 | + limit (int): The maximum number of statuses to return in a page. |
| 62 | + request (Request): FastAPI's Request object. |
| 63 | +
|
| 64 | +Returns: |
| 65 | + A tuple containing a list of order statuses and a pagination token. |
| 66 | +
|
| 67 | + - Should return returns.result.Success[tuple[list[OrderStatus], returns.maybe.Some[str]] if order is found and including a pagination token. |
| 68 | + - Should return returns.result.Success[tuple[list[OrderStatus], returns.maybe.Nothing]] if order is found and not including a pagination token. |
| 69 | + - Should return returns.result.Failure[Exception] if the order is not found or if access is denied. |
| 70 | + - Returning returns.result.Failure[Exception] will result in a 500. |
| 71 | +""" |
0 commit comments