diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d42fcb..f4f3c88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Endpoint `/orders/{order_id}/statuses` supporting `GET` for retrieving statuses. The entity returned by this conforms to the change proposed in [stapi-spec#239](https://github.com/stapi-spec/stapi-spec/pull/239). -- Endpoint `/orders/{order_id}/statuses` supporting `POST` for updating current status - RootBackend has new methods `get_order_statuses` and `set_order_status` ### Changed @@ -25,7 +24,8 @@ none ### Removed -none +- Endpoint `/orders/{order_id}/statuses` supporting `POST` for updating current status was added and then + removed prior to release ### Fixed diff --git a/src/stapi_fastapi/backends/root_backend.py b/src/stapi_fastapi/backends/root_backend.py index 9a803d9..5b77e2f 100644 --- a/src/stapi_fastapi/backends/root_backend.py +++ b/src/stapi_fastapi/backends/root_backend.py @@ -8,11 +8,10 @@ Order, OrderCollection, OrderStatus, - OrderStatusPayload, ) -class RootBackend[T: OrderStatusPayload, U: OrderStatus](Protocol): # pragma: nocover +class RootBackend[T: OrderStatus](Protocol): # pragma: nocover async def get_orders(self, request: Request) -> ResultE[OrderCollection]: """ Return a list of existing orders. @@ -34,7 +33,7 @@ async def get_order(self, order_id: str, request: Request) -> ResultE[Maybe[Orde async def get_order_statuses( self, order_id: str, request: Request - ) -> ResultE[list[U]]: + ) -> ResultE[list[T]]: """ Get statuses for order with `order_id`. @@ -46,17 +45,3 @@ async def get_order_statuses( A Failure[Exception] will result in a 500. """ ... - - async def set_order_status( - self, order_id: str, payload: T, request: Request - ) -> ResultE[U]: - """ - Set statuses for order with `order_id`. - - Should return returns.results.Success[OrderStatus] if successful. - - Should return returns.results.Failure[Exception] if the status was not able to be set. - - A Failure[Exception] will result in a 500. - """ - ... diff --git a/src/stapi_fastapi/models/order.py b/src/stapi_fastapi/models/order.py index ba379ca..2100375 100644 --- a/src/stapi_fastapi/models/order.py +++ b/src/stapi_fastapi/models/order.py @@ -122,12 +122,3 @@ class OrderPayload(BaseModel, Generic[ORP]): order_parameters: ORP model_config = ConfigDict(strict=True) - - -class OrderStatusPayload(BaseModel): - status_code: OrderStatusCode | None = None - reason_code: str | None = None - reason_text: str | None = None - - # todo: rework generic types to allow subclasses to be used correctly, and remove extra=allow - model_config = ConfigDict(strict=True, extra="allow") diff --git a/src/stapi_fastapi/routers/root_router.py b/src/stapi_fastapi/routers/root_router.py index a83f204..a5da837 100644 --- a/src/stapi_fastapi/routers/root_router.py +++ b/src/stapi_fastapi/routers/root_router.py @@ -4,7 +4,6 @@ from fastapi import APIRouter, HTTPException, Request, status from fastapi.datastructures import URL -from fastapi.responses import Response from returns.maybe import Maybe, Some from returns.result import Failure, Success @@ -16,7 +15,6 @@ Order, OrderCollection, OrderStatuses, - OrderStatusPayload, ) from stapi_fastapi.models.product import Product, ProductsCollection from stapi_fastapi.models.root import RootResponse @@ -101,14 +99,6 @@ def __init__( tags=["Orders"], ) - self.add_api_route( - "/orders/{order_id}/statuses", - self.set_order_status, - methods=["POST"], - name=f"{self.name}:set-order-status", - tags=["Orders"], - ) - def get_root(self, request: Request) -> RootResponse: return RootResponse( id="STAPI API", @@ -245,24 +235,6 @@ async def get_order_statuses( case _: raise AssertionError("Expected code to be unreachable") - async def set_order_status( - self, order_id: str, payload: OrderStatusPayload, request: Request - ) -> Response: - match await self.backend.set_order_status(order_id, payload, request): - case Success(_): - return Response(status_code=status.HTTP_202_ACCEPTED) - case Failure(e): - logger.error( - "An error occurred while setting order status: %s", - traceback.format_exception(e), - ) - raise HTTPException( - status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, - detail="Error setting Order Status", - ) - case x: - raise AssertionError(f"Expected code to be unreachable {x}") - def add_product(self: Self, product: Product) -> None: # Give the include a prefix from the product router product_router = ProductRouter(product, self) diff --git a/tests/application.py b/tests/application.py index 6e9afaf..4329517 100644 --- a/tests/application.py +++ b/tests/application.py @@ -1,5 +1,5 @@ from collections import defaultdict -from datetime import UTC, datetime, timezone +from datetime import datetime, timezone from typing import Literal, Self from uuid import uuid4 @@ -23,7 +23,6 @@ OrderPayload, OrderStatus, OrderStatusCode, - OrderStatusPayload, ) from stapi_fastapi.models.product import ( Product, @@ -61,16 +60,6 @@ async def get_order_statuses( ) -> ResultE[list[OrderStatus]]: return Success(self._orders_db._statuses[order_id]) - async def set_order_status( - self, order_id: str, payload: OrderStatusPayload, request: Request - ) -> ResultE[OrderStatus]: - input = payload.model_dump() - input["timestamp"] = datetime.now(UTC) - order_status = OrderStatus.model_validate(input) - self._orders_db._orders[order_id].properties.status = order_status - self._orders_db._statuses[order_id].insert(0, order_status) - return Success(order_status) - class MockProductBackend(ProductBackend): def __init__(self, orders: InMemoryOrderDB) -> None: diff --git a/tests/test_order.py b/tests/test_order.py index d795634..d5fe5a2 100644 --- a/tests/test_order.py +++ b/tests/test_order.py @@ -131,40 +131,3 @@ def test_order_status_after_create( assert res.status_code == status.HTTP_200_OK assert res.headers["Content-Type"] == "application/json" assert len(res.json()["statuses"]) == 1 - - -@pytest.mark.parametrize("product_id", ["test-spotlight"]) -def test_order_status_after_update( - get_order_response: Response, stapi_client: TestClient -) -> None: - body = get_order_response.json() - statuses_url = find_link(body["links"], "monitor")["href"] - - res = stapi_client.post( - statuses_url, - json={ - "status_code": "accepted", - "reason_code": "REASON1", - "reason_text": "some reason", - }, - ) - - assert res.status_code == status.HTTP_202_ACCEPTED - - res = stapi_client.get(statuses_url) - assert res.status_code == status.HTTP_200_OK - assert res.headers["Content-Type"] == "application/json" - body = res.json() - assert len(body["statuses"]) == 2 - - s = body["statuses"][0] - assert s["reason_code"] == "REASON1" - assert s["reason_text"] == "some reason" - assert s["status_code"] == "accepted" - assert s["timestamp"] - - s = body["statuses"][1] - assert s["reason_code"] is None - assert s["reason_text"] is None - assert s["status_code"] == "received" - assert s["timestamp"]