-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for the SearchPanes extension
Usage: ```java @RequestMapping(value = "/data/users", method = RequestMethod.GET) public DataTablesOutput<User> getUsers(@Valid DataTablesInput input, @RequestParam Map<String, String> queryParams) { input.parseSearchPanesFromQueryParams(queryParams, Arrays.asList("position", "status")); return userRepository.findAll(input); } ``` Related: #118
- Loading branch information
1 parent
6a0d37d
commit 16803f9
Showing
10 changed files
with
262 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/org/springframework/data/jpa/datatables/mapping/SearchPanes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.springframework.data.jpa.datatables.mapping; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class SearchPanes { | ||
private Map<String, List<Item>> options; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public static class Item { | ||
private String label; | ||
private String value; | ||
private long total; | ||
private long count; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/test/java/org/springframework/data/jpa/datatables/mapping/DataTablesInputTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.springframework.data.jpa.datatables.mapping; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.*; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.entry; | ||
|
||
public class DataTablesInputTest { | ||
|
||
@Test | ||
public void testParseSearchPanes() { | ||
DataTablesInput input = new DataTablesInput(); | ||
HashMap<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("searchPanes.attr1.0", "1"); | ||
queryParams.put("searchPanes.attr1.1", "2"); | ||
queryParams.put("searchPanes.attr2.0", "3"); | ||
queryParams.put("searchPanes.attr3.test", "4"); | ||
queryParams.put("searchPanes.attr4.0", "5"); | ||
queryParams.put("ignored", "6"); | ||
|
||
input.parseSearchPanesFromQueryParams(queryParams, asList("attr1", "attr2")); | ||
|
||
assertThat(input.getSearchPanes()).containsOnly( | ||
entry("attr1", new HashSet<>(asList("1", "2"))), | ||
entry("attr2", new HashSet<>(asList("3"))) | ||
); | ||
} | ||
} |
Oops, something went wrong.