forked from vmware-archive/spring-boot-cities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CitiesController.java
31 lines (26 loc) · 1.16 KB
/
CitiesController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.example.cities.controller;
import com.example.cities.client.CityRepository;
import com.example.cities.client.model.PagedCities;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/cities")
public class CitiesController {
private CityRepository repository;
@Autowired
public CitiesController(CityRepository repository) {
this.repository = repository;
}
@RequestMapping(method = RequestMethod.GET)
public PagedCities list(Pageable pageable) {
return repository.findAll(pageable.getPageNumber(), pageable.getPageSize());
}
@RequestMapping(value = "/search", method = RequestMethod.GET)
public PagedCities search(@RequestParam("name") String name, Pageable pageable) {
return repository.findByNameContains(name, pageable.getPageNumber(), pageable.getPageSize());
}
}