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

Commit df2e78f

Browse files
author
Phil Varner
authored
remove endpoint POST /orders/{order_id}/statuses (#126)
1 parent 74a5d01 commit df2e78f

File tree

6 files changed

+5
-105
lines changed

6 files changed

+5
-105
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212

1313
- Endpoint `/orders/{order_id}/statuses` supporting `GET` for retrieving statuses. The entity returned by this conforms
1414
to the change proposed in [stapi-spec#239](https://github.com/stapi-spec/stapi-spec/pull/239).
15-
- Endpoint `/orders/{order_id}/statuses` supporting `POST` for updating current status
1615
- RootBackend has new methods `get_order_statuses` and `set_order_status`
1716

1817
### Changed
@@ -25,7 +24,8 @@ none
2524

2625
### Removed
2726

28-
none
27+
- Endpoint `/orders/{order_id}/statuses` supporting `POST` for updating current status was added and then
28+
removed prior to release
2929

3030
### Fixed
3131

src/stapi_fastapi/backends/root_backend.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
Order,
99
OrderCollection,
1010
OrderStatus,
11-
OrderStatusPayload,
1211
)
1312

1413

15-
class RootBackend[T: OrderStatusPayload, U: OrderStatus](Protocol): # pragma: nocover
14+
class RootBackend[T: OrderStatus](Protocol): # pragma: nocover
1615
async def get_orders(self, request: Request) -> ResultE[OrderCollection]:
1716
"""
1817
Return a list of existing orders.
@@ -34,7 +33,7 @@ async def get_order(self, order_id: str, request: Request) -> ResultE[Maybe[Orde
3433

3534
async def get_order_statuses(
3635
self, order_id: str, request: Request
37-
) -> ResultE[list[U]]:
36+
) -> ResultE[list[T]]:
3837
"""
3938
Get statuses for order with `order_id`.
4039
@@ -46,17 +45,3 @@ async def get_order_statuses(
4645
A Failure[Exception] will result in a 500.
4746
"""
4847
...
49-
50-
async def set_order_status(
51-
self, order_id: str, payload: T, request: Request
52-
) -> ResultE[U]:
53-
"""
54-
Set statuses for order with `order_id`.
55-
56-
Should return returns.results.Success[OrderStatus] if successful.
57-
58-
Should return returns.results.Failure[Exception] if the status was not able to be set.
59-
60-
A Failure[Exception] will result in a 500.
61-
"""
62-
...

src/stapi_fastapi/models/order.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,3 @@ class OrderPayload(BaseModel, Generic[ORP]):
122122
order_parameters: ORP
123123

124124
model_config = ConfigDict(strict=True)
125-
126-
127-
class OrderStatusPayload(BaseModel):
128-
status_code: OrderStatusCode | None = None
129-
reason_code: str | None = None
130-
reason_text: str | None = None
131-
132-
# todo: rework generic types to allow subclasses to be used correctly, and remove extra=allow
133-
model_config = ConfigDict(strict=True, extra="allow")

src/stapi_fastapi/routers/root_router.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from fastapi import APIRouter, HTTPException, Request, status
66
from fastapi.datastructures import URL
7-
from fastapi.responses import Response
87
from returns.maybe import Maybe, Some
98
from returns.result import Failure, Success
109

@@ -16,7 +15,6 @@
1615
Order,
1716
OrderCollection,
1817
OrderStatuses,
19-
OrderStatusPayload,
2018
)
2119
from stapi_fastapi.models.product import Product, ProductsCollection
2220
from stapi_fastapi.models.root import RootResponse
@@ -101,14 +99,6 @@ def __init__(
10199
tags=["Orders"],
102100
)
103101

104-
self.add_api_route(
105-
"/orders/{order_id}/statuses",
106-
self.set_order_status,
107-
methods=["POST"],
108-
name=f"{self.name}:set-order-status",
109-
tags=["Orders"],
110-
)
111-
112102
def get_root(self, request: Request) -> RootResponse:
113103
return RootResponse(
114104
id="STAPI API",
@@ -245,24 +235,6 @@ async def get_order_statuses(
245235
case _:
246236
raise AssertionError("Expected code to be unreachable")
247237

248-
async def set_order_status(
249-
self, order_id: str, payload: OrderStatusPayload, request: Request
250-
) -> Response:
251-
match await self.backend.set_order_status(order_id, payload, request):
252-
case Success(_):
253-
return Response(status_code=status.HTTP_202_ACCEPTED)
254-
case Failure(e):
255-
logger.error(
256-
"An error occurred while setting order status: %s",
257-
traceback.format_exception(e),
258-
)
259-
raise HTTPException(
260-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
261-
detail="Error setting Order Status",
262-
)
263-
case x:
264-
raise AssertionError(f"Expected code to be unreachable {x}")
265-
266238
def add_product(self: Self, product: Product) -> None:
267239
# Give the include a prefix from the product router
268240
product_router = ProductRouter(product, self)

tests/application.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections import defaultdict
2-
from datetime import UTC, datetime, timezone
2+
from datetime import datetime, timezone
33
from typing import Literal, Self
44
from uuid import uuid4
55

@@ -23,7 +23,6 @@
2323
OrderPayload,
2424
OrderStatus,
2525
OrderStatusCode,
26-
OrderStatusPayload,
2726
)
2827
from stapi_fastapi.models.product import (
2928
Product,
@@ -61,16 +60,6 @@ async def get_order_statuses(
6160
) -> ResultE[list[OrderStatus]]:
6261
return Success(self._orders_db._statuses[order_id])
6362

64-
async def set_order_status(
65-
self, order_id: str, payload: OrderStatusPayload, request: Request
66-
) -> ResultE[OrderStatus]:
67-
input = payload.model_dump()
68-
input["timestamp"] = datetime.now(UTC)
69-
order_status = OrderStatus.model_validate(input)
70-
self._orders_db._orders[order_id].properties.status = order_status
71-
self._orders_db._statuses[order_id].insert(0, order_status)
72-
return Success(order_status)
73-
7463

7564
class MockProductBackend(ProductBackend):
7665
def __init__(self, orders: InMemoryOrderDB) -> None:

tests/test_order.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -131,40 +131,3 @@ def test_order_status_after_create(
131131
assert res.status_code == status.HTTP_200_OK
132132
assert res.headers["Content-Type"] == "application/json"
133133
assert len(res.json()["statuses"]) == 1
134-
135-
136-
@pytest.mark.parametrize("product_id", ["test-spotlight"])
137-
def test_order_status_after_update(
138-
get_order_response: Response, stapi_client: TestClient
139-
) -> None:
140-
body = get_order_response.json()
141-
statuses_url = find_link(body["links"], "monitor")["href"]
142-
143-
res = stapi_client.post(
144-
statuses_url,
145-
json={
146-
"status_code": "accepted",
147-
"reason_code": "REASON1",
148-
"reason_text": "some reason",
149-
},
150-
)
151-
152-
assert res.status_code == status.HTTP_202_ACCEPTED
153-
154-
res = stapi_client.get(statuses_url)
155-
assert res.status_code == status.HTTP_200_OK
156-
assert res.headers["Content-Type"] == "application/json"
157-
body = res.json()
158-
assert len(body["statuses"]) == 2
159-
160-
s = body["statuses"][0]
161-
assert s["reason_code"] == "REASON1"
162-
assert s["reason_text"] == "some reason"
163-
assert s["status_code"] == "accepted"
164-
assert s["timestamp"]
165-
166-
s = body["statuses"][1]
167-
assert s["reason_code"] is None
168-
assert s["reason_text"] is None
169-
assert s["status_code"] == "received"
170-
assert s["timestamp"]

0 commit comments

Comments
 (0)