Skip to content

Generates search POST endpoint for Spring JPA entities

Notifications You must be signed in to change notification settings

Komdosh/SearchableRestEntity

Repository files navigation

SearchableRestEntity

This lib generates search POST endpoint for Spring JPA entities. All necessary code is being automatically generated: Service, Repository, Mapper, Controller.

Build: gradle build -x bootJar

Usage:

@Entity
@SearchableRestEntity(path='/playerInfo', useEntityAsDto=true)
public class Player{
    private String familyName;
    private String givenName;
    private Int age;
    private PlayerScore playerScore;
}

@Entity
public class PlayerScore{
    private Int games;
    private Int totalScore;
} 

Check it with POST request:

curl \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{"key": "givenName", "operation": "EQUALS", "value": "Mark"}' \
  https://yourhost/playerInfo/search?page=0&size=10&sort=givenName,ASC

Body of search request can contains a complex queries:

[{
    "key": "givenName",
    "operation": "EQUALS",
    "value": "Mark",
    "or": [
        {
            "key": "playerScore.totalScore",
            "operation": "GREATER",
            "value": "120",
            "or":[
                {
                    "key": "playerScore.games",
                    "operation": "LESS",
                    "value": "5"
                }
            ]
        },
        {
            "key": "playerScore.age",
            "operation": "GREATER",
            "value": "23",
            "and":[
                {
                    "key": "playerScore.totalScore",
                    "operation": "LESS_EQUALS",
                    "value": "1200"
                },
                {
                    "key": "playerScore.games",
                    "operation": "LESS_EQUALS",
                    "value": "10"
                }
            ]
        }
    ]
}]

About

Generates search POST endpoint for Spring JPA entities

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages