Description:
Allow users to sort products by price in ascending or descending order using the sort=price and order=asc|desc query parameters.
As a user,
I want to sort products by price,
so that I can view the cheapest or most expensive items first.
Acceptance Criteria:
The API supports sorting of products by price in both ascending (asc) and descending (desc) order using the sort=price and order query parameters.
If no order parameter is provided, default to sorting by price in ascending order.
If the sort=price parameter is not provided, return products in their default order (e.g., based on their natural insertion into the list).
The sort functionality should work in conjunction with other query parameters (e.g., search by name or filtering by price range).
**Example:**
Request (Ascending order by price):
GET /products?sort=price&order=asc
Response (200 OK):
Description: Allow users to sort products by price in ascending or descending order using the
sort=price
andorder=asc|desc
query parameters.As a user, I want to sort products by price, so that I can view the cheapest or most expensive items first.
[ { "id": 1, "name": "Product A", "price": 50 }, { "id": 2, "name": "Product B", "price": 100 }, { "id": 3, "name": "Product C", "price": 200 } ]