Order status endpoint for the tracking page
C++ · C++ · beginner · modification
The support desk and the storefront's tracking page need an order's status and tracking number, and `GET /orders/{id}` only returns the item count and total. This PR adds `GET /orders/{id}/status`. `handlers.hpp` declares a new `status_reply`, `handlers.cpp` implements it (it builds the JSON body the same way `summary_reply` does and adds `tracking` only when the order has one) and registers the route in `register_routes`. `tests/handlers_test.cpp` adds tests for the new reply and checks that both routes are registered.
Internal order-status service in C++20, standard library only, built with CMake (build files unchanged) by Apple clang 17 locally and GCC 13 in CI with `-Wall -Wextra -Wconversion` treated as errors. Only the support desk app and the storefront backend can reach it (the existing network policy, unchanged). Existing and unchanged: `src/orders/order.hpp` defines `enum class Status`, `status_name(Status)` (the five lowercase names), `struct Order { std::uint64_t id; Status status; std::uint32_t item_count; std::int64_t total_cents; std::optional<std::string> tracking; }` and `using OrderTable = std::unordered_map<std::uint64_t, Order>;`, where each entry's key equals its `id` and a tracking number is 8 to 34 characters of `A-Z` and `0-9` (nothing to escape in JSON). `main` loads the table at startup, owns it for the life of the process and never changes it while serving. `server::Router` (`src/server/router.hpp`) runs on a single thread, one request at a time; `get(pattern, handler)` registers a handler that receives the parsed `{id}` and returns a `server::Reply { int status; std::string body; }`, and a handler that throws a `std::exception` is logged and answered 500. The process runs under systemd with `Restart=on-failure`. Tests use the repo's existing helper `tests/check.hpp` (unchanged): `TEST(name)` registers a test, `CHECK(expr)` and `CHECK_EQ(a, b)` record a failure without stopping, and `tests/check_main.cpp` runs every registered test and exits non-zero on any failure.
Requirements
- New: `GET /orders/{id}/status` answers 200 with the order's status, `{"order":<id>,"status":"<status>"}`, where the status is one of `pending`, `paid`, `shipped`, `delivered`, `cancelled`. When the order has a tracking number the body also carries it: `{"order":1043,"status":"shipped","tracking":"1Z999AA10123456784"}`.
- An id with no order answers 404 with the body `{"error":"order not found"}`, exactly like `GET /orders/{id}`. Unknown ids are routine: support agents type the order number a customer reads out on the phone.
- Unchanged: `GET /orders/{id}` and its replies; the router answers 400 for an `{id}` that is not a decimal number in the `std::uint64_t` range before any handler runs.
Files touched
- src/orders/handlers.hpp
- src/orders/handlers.cpp
- tests/handlers_test.cpp