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

Used Textbook Listings Filter

easy100%1 of 1 solved

Problem statement

Build a REST API for filtering used textbook listings by price range and condition.

Requirements

ListingRepository

Add one query method taking minPrice, maxPrice, and condition that returns the matching listings:

  • A null argument applies no restriction, so the one method serves all eight combinations of the three filters
  • minPrice and maxPrice bound the price inclusively
  • condition matches a stored condition exactly, ignoring case on both sides
  • Results come back ordered by listedAt descending

ListingController

Implement the search endpoint. It must be reachable at exactly the verb and path listed below and accepts three optional query parameters, minPrice, maxPrice, and condition.

GET /listings

  • Return 200 OK with a JSON array of listings; each listing carries its id, title, price, condition, and listedAt
  • Results are always ordered by listedAt descending, newest listing first, whatever filters are applied
  • A parameter that is omitted or sent with an empty value applies no filtering, so a request with no parameters returns every stored listing; a condition sent as whitespace-only is ignored the same way
  • Every supplied filter must hold at the same time: adding a parameter can only narrow the result
  • minPrice keeps the listings priced at least that value; a listing priced exactly at minPrice is included, one priced 1 below it is not
  • maxPrice keeps the listings priced at most that value; a listing priced exactly at maxPrice is included, one priced 1 above it is not
  • With both bounds supplied, the listings priced from minPrice through maxPrice inclusive are returned; minPrice equal to maxPrice keeps exactly the listings at that price
  • When minPrice is greater than maxPrice, return 200 OK with an empty array, never an error
  • condition keeps the listings whose stored condition equals the supplied value exactly, ignoring case in both directions; a value that is only part of a stored condition matches nothing
  • When no stored listing satisfies the filters, or when nothing is stored at all, return 200 OK with an empty array
  • A minPrice or maxPrice value that is not a whole number is rejected with 400 Bad Request
  • Requests to this endpoint never change the stored listings

Sample Requests & Responses

Expand to view details on sample requests and responses.

GET /listings

Response (200 OK):

[
    {
      "id": 4,
      "title": "Intro to Microeconomics",
      "price": 55,
      "condition": "Good",
      "listedAt": "2026-07-28T11:00:00"
    },
    {
      "id": 2,
      "title": "Organic Chemistry Essentials",
      "price": 80,
      "condition": "Like New",
      "listedAt": "2026-07-27T09:15:00"
    },
    {
      "id": 5,
      "title": "Data Structures in Java",
      "price": 120,
      "condition": "New",
      "listedAt": "2026-07-26T16:20:00"
    },
    {
      "id": 1,
      "title": "Calculus Made Simple",
      "price": 45,
      "condition": "Good",
      "listedAt": "2026-07-25T14:30:00"
    },
    {
      "id": 3,
      "title": "Linear Algebra Done Right",
      "price": 30,
      "condition": "Acceptable",
      "listedAt": "2026-07-24T18:45:00"
    }
]

GET /listings?minPrice=40&maxPrice=80

Response (200 OK):

[
    {
      "id": 4,
      "title": "Intro to Microeconomics",
      "price": 55,
      "condition": "Good",
      "listedAt": "2026-07-28T11:00:00"
    },
    {
      "id": 2,
      "title": "Organic Chemistry Essentials",
      "price": 80,
      "condition": "Like New",
      "listedAt": "2026-07-27T09:15:00"
    },
    {
      "id": 1,
      "title": "Calculus Made Simple",
      "price": 45,
      "condition": "Good",
      "listedAt": "2026-07-25T14:30:00"
    }
]

GET /listings?condition=good

Response (200 OK):

[
    {
      "id": 4,
      "title": "Intro to Microeconomics",
      "price": 55,
      "condition": "Good",
      "listedAt": "2026-07-28T11:00:00"
    },
    {
      "id": 1,
      "title": "Calculus Made Simple",
      "price": 45,
      "condition": "Good",
      "listedAt": "2026-07-25T14:30:00"
    }
]

GET /listings?minPrice=100&condition=good

Response (200 OK):

[]

GET /listings?minPrice=50&maxPrice=20

Response (200 OK):

[]

GET /listings?minPrice=abc

Response (400 Bad Request):

{
   "timestamp": "2026-07-30T05:01:10.353+00:00",
   "status": 400,
   "error": "Bad Request",
   "path": "/listings"
}

More in Querying and Filtering

See the module
Farmers Market Vendor SearchThis problem covers searching vendors by several optional filters that can be combined in any way.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.