StaffCoder
Spring Boot
Spring BootSpring Boot 4.1Java 25
12 modules · 48 challengesSign up
Module 5 · Querying and Filtering

Farmers Market Vendor Search

easy100%1 of 1 solved

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"
    }
]

More in Querying and Filtering

See the module
Used Textbook Listings FilterThis problem covers filtering listings by a price range and other options, with the results always ordered newest first.100%1 of 1 solvedeasyPodcast Episode BrowserThis problem covers returning results one page at a time, with a capped page size and a consistent page envelope.100%1 of 1 solvedeasyHotel Room Availability QueryThis problem covers finding rooms that are free across a date range, without counting a booking that ends on the day the new one starts.100%1 of 1 solvedeasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.