diff --git a/common-spring-jpa/src/main/kotlin/ru/touchin/common/spring/jpa/converters/GetPageConverter.kt b/common-spring-jpa/src/main/kotlin/ru/touchin/common/spring/jpa/converters/GetPageConverter.kt index 5f292d5..0c69652 100644 --- a/common-spring-jpa/src/main/kotlin/ru/touchin/common/spring/jpa/converters/GetPageConverter.kt +++ b/common-spring-jpa/src/main/kotlin/ru/touchin/common/spring/jpa/converters/GetPageConverter.kt @@ -2,11 +2,18 @@ package ru.touchin.common.spring.jpa.converters import org.springframework.data.domain.PageRequest import org.springframework.data.domain.Pageable +import org.springframework.data.domain.Sort import ru.touchin.common.page.GetPage -fun GetPage.toPageable(): Pageable { - return PageRequest.of( +fun GetPage.toPageable(sort: Sort? = null): Pageable { + val pageRequest = PageRequest.of( page - 1, size, ) + + if (sort != null) { + return pageRequest.withSort(sort) + } + + return pageRequest }