diff --git a/OrderService/OrderService/Controllers/OrdersController.cs b/OrderService/OrderService/Controllers/OrdersController.cs index b4a1df5..5d7b0e6 100644 --- a/OrderService/OrderService/Controllers/OrdersController.cs +++ b/OrderService/OrderService/Controllers/OrdersController.cs @@ -34,11 +34,14 @@ public async Task GetOrder(Guid id) return order is null ? NotFound() : Ok(order); } - // GET /api/orders?customerId=xxx — returns full order history for a customer + // GET /api/orders — returns all orders (admin view, issue #53) + // GET /api/orders?customerId=xxx — returns full order history for one customer [HttpGet] - public async Task GetOrderHistory([FromQuery] string customerId) + public async Task GetOrders([FromQuery] string? customerId) { - var orders = await _orderService.GetOrderHistoryAsync(customerId); + var orders = string.IsNullOrWhiteSpace(customerId) + ? await _orderService.GetAllOrdersAsync() + : await _orderService.GetOrderHistoryAsync(customerId); return Ok(orders); } } diff --git a/OrderService/OrderService/Services/IOrderService.cs b/OrderService/OrderService/Services/IOrderService.cs index 21734e3..f1f04e2 100644 --- a/OrderService/OrderService/Services/IOrderService.cs +++ b/OrderService/OrderService/Services/IOrderService.cs @@ -9,4 +9,5 @@ public interface IOrderService Task PlaceOrderAsync(PlaceOrderDto dto); Task GetOrderAsync(Guid id); Task> GetOrderHistoryAsync(string customerId); + Task> GetAllOrdersAsync(); } diff --git a/OrderService/OrderService/Services/OrderService.cs b/OrderService/OrderService/Services/OrderService.cs index 38574cc..e593f84 100644 --- a/OrderService/OrderService/Services/OrderService.cs +++ b/OrderService/OrderService/Services/OrderService.cs @@ -88,6 +88,17 @@ public async Task> GetOrderHistoryAsync(string cus return orders.Select(ToResponseDto); } + // Returns every order, newest first. Backs the admin Orders view (issue #53). + public async Task> GetAllOrdersAsync() + { + var orders = await _db.Orders + .Include(o => o.Items) + .OrderByDescending(o => o.CreatedAt) + .ToListAsync(); + + return orders.Select(ToResponseDto); + } + // Calls OpenStreetMap Nominatim to convert a text address to GPS coordinates. // Falls back to downtown Spokane if geocoding fails so orders still go through. private async Task<(double Latitude, double Longitude)> GeocodeAddressAsync(string address)