Review List Controller

In this lesson, we'll implement the REST API endpoint that enables users to list reviews for a specific restaurant.

Controller Implementation

The ReviewController class is responsible for handling HTTP requests related to restaurant reviews.

Rather than attempt to manually parse the page, page size and sorting query parameters, we'll rely on Spring to do this for us with @PageableDefault.

We didn't use this approach when searching for restaurants because, even though we were passing page information, we weren't supporting sorting.

Let's look at how to implement the getRestaurantReviews method:

@GetMapping public Page<ReviewDto> listReviews( @PathVariable String restaurantId, @PageableDefault(size = 20, page = 0, sort = "datePosted", direction = Sort.Direction.DESC) Pageable pageable) { return reviewService .getRestaurantReviews(restaurantId, pageable) .map(reviewMapper::toDto); }

This endpoint accepts several parameters:

  • restaurantId: The ID of the restaurant whose reviews we want to retrieve
  • pageable: The page, page size and sorting preferences for results

Summary

  • Implemented listReviews endpoint in ReviewController
  • Method accepts sorting and pagination parameters
© 2026 Devtiro Ltd. All rights reserved