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

Commit f965f99

Browse files
parksjrtylandersonjkeifer
committed
Adds OrderCollection type and returns for get_orders
Co-authored-by: Tyler <[email protected]> Co-authored-by: Jarrett Keifer <[email protected]>
1 parent 9355fdf commit f965f99

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

src/stapi_fastapi/backends/root_backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
from fastapi import Request
44

5-
from stapi_fastapi.models.order import Order
5+
from stapi_fastapi.models.order import Order, OrderCollection
66

77

88
class RootBackend(Protocol):
9-
async def get_orders(self, request: Request) -> list[Order]:
9+
async def get_orders(self, request: Request) -> OrderCollection:
1010
"""
1111
Return a list of existing orders.
1212
"""

src/stapi_fastapi/models/order.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
from typing import Literal, TypeVar
1+
from typing import Literal
22

3-
from geojson_pydantic import Feature
3+
from geojson_pydantic import Feature, FeatureCollection
44
from geojson_pydantic.geometries import Geometry
5-
from pydantic import StrictInt, StrictStr
5+
from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr
66

7-
from stapi_fastapi.models.opportunity import OpportunityPropertiesBase
87
from stapi_fastapi.models.shared import Link
8+
from stapi_fastapi.types.datetime_interval import DatetimeInterval
99

10-
G = TypeVar("G", bound=Geometry)
11-
P = TypeVar("P", bound=OpportunityPropertiesBase)
1210

11+
class OrderProperties(BaseModel):
12+
datetime: DatetimeInterval
13+
model_config = ConfigDict(extra="allow")
1314

14-
class Order(Feature[G, P]):
15+
16+
class Order(Feature[Geometry, OrderProperties]):
1517
# We need to enforce that orders have an id defined, as that is required to
1618
# retrieve them via the API
1719
id: StrictInt | StrictStr # type: ignore
1820
type: Literal["Feature"] = "Feature"
1921
links: list[Link]
22+
23+
24+
class OrderCollection(FeatureCollection[Order]):
25+
type: Literal["FeatureCollection"] = "FeatureCollection"

src/stapi_fastapi/routers/root_router.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from stapi_fastapi.backends.root_backend import RootBackend
77
from stapi_fastapi.constants import TYPE_GEOJSON, TYPE_JSON
8-
from stapi_fastapi.models.order import Order
8+
from stapi_fastapi.models.order import Order, OrderCollection
99
from stapi_fastapi.models.product import Product, ProductsCollection
1010
from stapi_fastapi.models.root import RootResponse
1111
from stapi_fastapi.models.shared import Link
@@ -112,7 +112,7 @@ def get_products(self, request: Request) -> ProductsCollection:
112112
],
113113
)
114114

115-
async def get_orders(self, request: Request) -> list[Order]:
115+
async def get_orders(self, request: Request) -> OrderCollection:
116116
orders = await self.backend.get_orders(request)
117117
for order in orders:
118118
order.links.append(

tests/backends.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from stapi_fastapi.backends.product_backend import ProductBackend
55
from stapi_fastapi.exceptions import ConstraintsException, NotFoundException
66
from stapi_fastapi.models.opportunity import Opportunity, OpportunityRequest
7-
from stapi_fastapi.models.order import Order
7+
from stapi_fastapi.models.order import Order, OrderCollection
88
from stapi_fastapi.routers.product_router import ProductRouter
99

1010

@@ -16,7 +16,7 @@ class MockRootBackend:
1616
def __init__(self, orders: MockOrderDB) -> None:
1717
self._orders = orders
1818

19-
async def get_orders(self, request: Request) -> list[Order]:
19+
async def get_orders(self, request: Request) -> OrderCollection:
2020
"""
2121
Show all orders.
2222
"""

0 commit comments

Comments
 (0)