-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathroot_backend.py
More file actions
136 lines (110 loc) · 5.45 KB
/
root_backend.py
File metadata and controls
136 lines (110 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from abc import abstractmethod
from collections.abc import Callable, Coroutine
from typing import Any, Generic, Protocol
from fastapi import Request
from returns.maybe import Maybe
from returns.result import ResultE
from stapi_pydantic import OpportunitySearchRecord, OpportunitySearchStatus, Order, OrderStatusBound
class GetOrders(Protocol, Generic[OrderStatusBound]):
"""Interface for getting a list of orders or a single order."""
@abstractmethod
async def get_orders(
self,
next: str | None,
limit: int,
request: Request,
) -> ResultE[tuple[list[Order[OrderStatusBound]], Maybe[str], Maybe[int]]]:
"""Get a list of Order objects.
Args:
next (str | None): A pagination token.
limit (int): The maximum number of orders to return in a page.
request (Request): FastAPI's Request object.
Returns:
A tuple containing a list of orders and a pagination token.
- Should return returns.result.Success[tuple[list[Order], returns.maybe.Some[str]]]
if including a pagination token
- Should return returns.result.Success[tuple[list[Order], returns.maybe.Nothing]]
if not including a pagination token
- Returning returns.result.Failure[Exception] will result in a 500.
"""
@abstractmethod
async def get_order(self, order_id: str, request: Request) -> ResultE[Maybe[Order[OrderStatusBound]]]:
"""Get details for the order with `order_id`.
Args:
order_id (str): The order ID.
request (Request): FastAPI's Request object.
Returns:
- Should return returns.result.Success[returns.maybe.Some[Order]] if order is found.
- Should return returns.result.Success[returns.maybe.Nothing] if the order is not found or if access is
denied.
- Returning returns.result.Failure[Exception] will result in a 500.
"""
class GetOrderStatuses(Protocol, Generic[OrderStatusBound]):
"""Callable class wrapping an async method that gets statuses for the order with `order_id`."""
@abstractmethod
async def get_order_statuses(
self, order_id: str, next: str | None, limit: int, request: Request
) -> ResultE[Maybe[tuple[list[OrderStatusBound], Maybe[str]]]]:
"""Method that gets statuses for the order with `order_id`.
Args:
order_id (str): The order ID.
next (str | None): A pagination token.
limit (int): The maximum number of statuses to return in a page.
request (Request): FastAPI's Request object.
Returns:
A tuple containing a list of order statuses and a pagination token.
- Should return returns.result.Success[returns.maybe.Some[tuple[list[OrderStatus], returns.maybe.Some[str]]]
if order is found and including a pagination token.
- Should return returns.result.Success[returns.maybe.Some[tuple[list[OrderStatus], returns.maybe.Nothing]]]
if order is found and not including a pagination token.
- Should return returns.result.Success[returns.maybe.Nothing] if the order is not found or if access is
denied.
- Returning returns.result.Failure[Exception] will result in a 500.
"""
GetOpportunitySearchRecords = Callable[
[str | None, int, Request],
Coroutine[Any, Any, ResultE[tuple[list[OpportunitySearchRecord], Maybe[str]]]],
]
"""
Type alias for an async function that gets OpportunitySearchRecords for all products.
Args:
request (Request): FastAPI's Request object.
next (str | None): A pagination token.
limit (int): The maximum number of search records to return in a page.
Returns:
- Should return returns.result.Success[tuple[list[OpportunitySearchRecord], returns.maybe.Some[str]]]
if including a pagination token
- Should return returns.result.Success[tuple[list[OpportunitySearchRecord], returns.maybe.Nothing]]
if not including a pagination token
- Returning returns.result.Failure[Exception] will result in a 500.
"""
GetOpportunitySearchRecord = Callable[[str, Request], Coroutine[Any, Any, ResultE[Maybe[OpportunitySearchRecord]]]]
"""
Type alias for an async function that gets the OpportunitySearchRecord with
`search_record_id`.
Args:
search_record_id (str): The ID of the OpportunitySearchRecord.
request (Request): FastAPI's Request object.
Returns:
- Should return returns.result.Success[returns.maybe.Some[OpportunitySearchRecord]] if the search record is found.
- Should return returns.result.Success[returns.maybe.Nothing] if the search record is not found or
if access is denied.
- Returning returns.result.Failure[Exception] will result in a 500.
"""
GetOpportunitySearchRecordStatuses = Callable[
[str, Request], Coroutine[Any, Any, ResultE[Maybe[list[OpportunitySearchStatus]]]]
]
"""
Type alias for an async function that gets the statuses of a OpportunitySearchRecord with
`search_record_id`.
Args:
search_record_id (str): The ID of the OpportunitySearchRecord.
request (Request): FastAPI's Request object.
Returns:
- Should return
returns.result.Success[returns.maybe.Some[list[OpportunitySearchStatus]]] if
the search record is found.
- Should return returns.result.Success[returns.maybe.Nothing] if the search record is not found or
if access is denied.
- Returning returns.result.Failure[Exception] will result in a 500.
"""