diff --git a/spring-showcase-web/src/main/java/ch/polgrabia/springshowcaseweb/configs/ApplicationConfig.java b/spring-showcase-web/src/main/java/ch/polgrabia/springshowcaseweb/configs/ApplicationConfig.java new file mode 100644 index 0000000..a53c9b3 --- /dev/null +++ b/spring-showcase-web/src/main/java/ch/polgrabia/springshowcaseweb/configs/ApplicationConfig.java @@ -0,0 +1,8 @@ +package ch.polgrabia.springshowcaseweb.configs; + +import org.springframework.context.annotation.Configuration; + +@Configuration +public class ApplicationConfig { + +} diff --git a/spring-showcase-web/src/main/java/ch/polgrabia/springshowcaseweb/controllers/UserController.java b/spring-showcase-web/src/main/java/ch/polgrabia/springshowcaseweb/controllers/UserController.java index 2e13df8..769a7b0 100644 --- a/spring-showcase-web/src/main/java/ch/polgrabia/springshowcaseweb/controllers/UserController.java +++ b/spring-showcase-web/src/main/java/ch/polgrabia/springshowcaseweb/controllers/UserController.java @@ -3,8 +3,9 @@ package ch.polgrabia.springshowcaseweb.controllers; import ch.polgrabia.springshowcaseweb.models.User; import ch.polgrabia.springshowcaseweb.services.JpaUserDao; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.PropertySource; import org.springframework.dao.EmptyResultDataAccessException; -import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -15,19 +16,23 @@ import java.util.Optional; import java.util.stream.Collectors; @RestController +@PropertySource("classpath:application.properties") @RequestMapping("/api/users") public class UserController { - public static final int PAGE_SIZE = 10; private final JpaUserDao jpaUserDao; + private final Integer pageSize; - public UserController(@Autowired JpaUserDao jpaUserDao) { + public UserController( + @Autowired JpaUserDao jpaUserDao, + @Value("${springshowcase.users.controller.page.size}") Integer pageSize) { this.jpaUserDao = jpaUserDao; + this.pageSize = pageSize; } @RequestMapping(path = "/", method = RequestMethod.GET) public List handleGetAllUsers(@RequestParam(name = "page", defaultValue = "0", required = false) Integer page) { - return jpaUserDao.findAll(PageRequest.of(page, PAGE_SIZE)) + return jpaUserDao.findAll(PageRequest.of(page, pageSize)) .get() .collect(Collectors.toList()); } diff --git a/spring-showcase-web/src/main/resources/application.properties b/spring-showcase-web/src/main/resources/application.properties index 440db5d..7ea764c 100644 --- a/spring-showcase-web/src/main/resources/application.properties +++ b/spring-showcase-web/src/main/resources/application.properties @@ -2,3 +2,5 @@ spring.jpa.hibernate.ddl-auto=none spring.datasource.url=jdbc:postgresql://localhost:5432/test spring.datasource.username=test spring.datasource.password=test + +springshowcase.users.controller.page.size=10