Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

soramitsukhmer/jpa-sort-util-deleted-2

 
 

Repository files navigation

Usage

build.gradle.kts:

  1. Configure GitHub credential
repositories {
    maven {
        name = "GitHubPackages"
        url = uri("https://maven.pkg.github.com/sovannarith/jpa-sort-util.git")
        credentials {
            username = System.getenv("GIT_PUBLISH_USER")
            password = System.getenv("GIT_PUBLISH_PASSWORD")
        }
    }
}
  1. Add dependency
dependencies {
  	implementation("kh.org.sovannarith:jpa-sort-util:${property("jpa-sort-util.version")}")
}
  1. Create sorting mapper object
@Component
class UserSortMapping : JpaSortMappingResource<User>, JpaSortMappingSupport<User>() {
    // You can use default JpaSortMappingSupport.getSource() to get all declared fields or override it like below
    override fun getSource(): MutableMap<String, String> {
        val map = mutableMapOf("name" to "nameKH")
        super.getSource().putAll(map)
        return super.getSource()
    }

}
  1. Use sorting mapper object on Rest Controller getting endpoint
    @GetMapping
    @JpaSortMapping(value = UserSortMapping::class)
    fun findAll(
        filter: UserReq.Filter?,
        @SortDefault(sort = ["createdAt"], direction = Sort.Direction.DESC) pageable: Pageable
    ): ResponseEntity<ResponseWrapper>? {
        return ok(userService.findAll(filter, pageable))
    }

About

Helper util for fields sort naming

Resources

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 100.0%