Shipping label endpoint for the warehouse screen

C# · ASP.NET Core · beginner · modification

Warehouse staff print shipping labels from the order screen, and the screen needs the address in one call. `src/Shop.Api/Orders/ShippingLabelEndpoints.cs` (new) adds `GET /api/orders/{id}/shipping-label`: it loads the order with its shipping address in one no-tracking query and returns the label fields as a `ShippingLabel` record. `src/Shop.Api/Program.cs` maps it on the existing staff-only `/api/orders` group, next to the other order endpoints. `tests/Shop.Api.Tests/ShippingLabelTests.cs` (new) tests the endpoint through the existing `ShopApiFactory`.

Shop API on ASP.NET Core 10 (.NET 10, C# 14) with minimal APIs, nullable reference types enabled, JSON in camelCase (the default). EF Core 10 on PostgreSQL. Existing and unchanged: `AddShopData` registers `ShopDbContext`; `AddShopAuth` configures the staff sign-in and the `ShopPolicies.Staff` policy; `MapOrderEndpoints` maps the other order endpoints. The entities are unchanged: `Order` has `Id` (int), `Number` (non-null string), `Fulfillment` (`Delivery` or `Pickup`), `ShippingAddressId` (`int?`) and `ShippingAddress` (`Address?`, an optional navigation). A delivery order always has a shipping address and a pickup order never has one (a database check constraint enforces both). `Address` has non-null `Recipient`, `Line1`, `PostalCode`, `City` and `CountryCode`, and a nullable `Line2`. The shop is a single store: every staff member may see every order. Tests are xUnit; `ShopApiFactory` (existing) is a `WebApplicationFactory<Program>` on an in-memory SQLite database with the schema created at start, plus `SeedAsync` and `CreateStaffClient()` helpers. The warehouse screen (a separate app) is the only caller of this endpoint.

Requirements

Files touched

Review this PR

C# practice