Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions OrderService/OrderService/Controllers/OrdersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ public async Task<IActionResult> 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<IActionResult> GetOrderHistory([FromQuery] string customerId)
public async Task<IActionResult> 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);
}
}
1 change: 1 addition & 0 deletions OrderService/OrderService/Services/IOrderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public interface IOrderService
Task<OrderResponseDto> PlaceOrderAsync(PlaceOrderDto dto);
Task<OrderResponseDto?> GetOrderAsync(Guid id);
Task<IEnumerable<OrderResponseDto>> GetOrderHistoryAsync(string customerId);
Task<IEnumerable<OrderResponseDto>> GetAllOrdersAsync();
}
11 changes: 11 additions & 0 deletions OrderService/OrderService/Services/OrderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ public async Task<IEnumerable<OrderResponseDto>> GetOrderHistoryAsync(string cus
return orders.Select(ToResponseDto);
}

// Returns every order, newest first. Backs the admin Orders view (issue #53).
public async Task<IEnumerable<OrderResponseDto>> 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)
Expand Down
Loading