Problem statement
Build a REST API for searching farmers market vendors by optional name and category filters.
Requirements
VendorRepository
The repository ships empty. Give it the data access the controller needs for these four search combinations, each returned in the order described below:
- All vendors
- Vendors filtered by name
- Vendors filtered by category
- Vendors filtered by both name and category
VendorController
Implement the search endpoint. It must be reachable at exactly the verb and path listed below and accepts two optional query parameters, name and category.
GET /vendors
- Return 200 OK with a JSON array of the vendors that match every supplied filter; each returned vendor carries its id, name, and category
- The name filter is a partial match: it matches any vendor whose name contains the value anywhere, including in the middle of the name, ignoring case in both the query value and the stored name
- The category filter is an exact match on the full category value, ignoring case; a value that matches only part of a category matches nothing
- Each filter works on its own; when both are supplied, a vendor must satisfy both of them to be returned, so the combined result is never wider than either filter alone
- A parameter that is omitted, empty, or whitespace-only is ignored; a blank parameter next to a real one leaves the real one in force
- When no filter is supplied, return every stored vendor
- When nothing matches, including when no vendors are stored at all, return 200 OK with an empty array; this endpoint never returns an error status
- Results are always sorted alphabetically by name ascending, whatever the filters
Sample Requests & Responses
Expand to view details on sample requests and responses.
GET /vendors
Response (200 OK):
[
{
"id": 6,
"name": "Apple Creek Orchard",
"category": "Produce"
},
{
"id": 3,
"name": "Applewood Smokehouse",
"category": "Meats"
},
{
"id": 2,
"name": "Golden Grain Bakery",
"category": "Bakery"
},
{
"id": 5,
"name": "Meadow Dairy Co",
"category": "Dairy"
},
{
"id": 4,
"name": "Pine Ridge Produce",
"category": "Produce"
},
{
"id": 1,
"name": "Sunny Apple Stand",
"category": "Produce"
}
]
GET /vendors?name=apple
Response (200 OK):
[
{
"id": 6,
"name": "Apple Creek Orchard",
"category": "Produce"
},
{
"id": 3,
"name": "Applewood Smokehouse",
"category": "Meats"
},
{
"id": 1,
"name": "Sunny Apple Stand",
"category": "Produce"
}
]
GET /vendors?name=Ridge
Response (200 OK):
[
{
"id": 4,
"name": "Pine Ridge Produce",
"category": "Produce"
}
]
GET /vendors?category=produce
Response (200 OK):
[
{
"id": 6,
"name": "Apple Creek Orchard",
"category": "Produce"
},
{
"id": 4,
"name": "Pine Ridge Produce",
"category": "Produce"
},
{
"id": 1,
"name": "Sunny Apple Stand",
"category": "Produce"
}
]
GET /vendors?category=Prod
Response (200 OK):
[]
GET /vendors?name=apple&category=PRODUCE
Response (200 OK):
[
{
"id": 6,
"name": "Apple Creek Orchard",
"category": "Produce"
},
{
"id": 1,
"name": "Sunny Apple Stand",
"category": "Produce"
}
]
GET /vendors?name=&category=
Response (200 OK):
[
{
"id": 6,
"name": "Apple Creek Orchard",
"category": "Produce"
},
{
"id": 3,
"name": "Applewood Smokehouse",
"category": "Meats"
},
{
"id": 2,
"name": "Golden Grain Bakery",
"category": "Bakery"
},
{
"id": 5,
"name": "Meadow Dairy Co",
"category": "Dairy"
},
{
"id": 4,
"name": "Pine Ridge Produce",
"category": "Produce"
},
{
"id": 1,
"name": "Sunny Apple Stand",
"category": "Produce"
}
]
