Update to accept query & filter as POST

This commit is contained in:
2022-10-14 10:11:53 -05:00
parent 7c339b4e81
commit 117bb621ff
2 changed files with 29 additions and 0 deletions

View File

@ -278,6 +278,7 @@ public class QJavalinImplementation
path("/data/{table}", () ->
{
get("/", QJavalinImplementation::dataQuery);
post("/query", QJavalinImplementation::dataQuery);
post("/", QJavalinImplementation::dataInsert); // todo - internal to that method, if input is a list, do a bulk - else, single.
get("/count", QJavalinImplementation::dataCount);
get("/export", QJavalinImplementation::dataExportWithoutFilename);
@ -606,6 +607,10 @@ public class QJavalinImplementation
queryInput.setLimit(integerQueryParam(context, "limit"));
String filter = stringQueryParam(context, "filter");
if(!StringUtils.hasContent(filter))
{
filter = context.formParam("filter");
}
if(filter != null)
{
queryInput.setFilter(JsonUtils.toObject(filter, QQueryFilter.class));

View File

@ -285,6 +285,30 @@ class QJavalinImplementationTest extends QJavalinTestBase
/*******************************************************************************
** test a table query using an actual filter via POST.
**
*******************************************************************************/
@Test
public void test_dataQueryWithFilterPOST()
{
String filterJson = getFirstNameEqualsTimFilterJSON();
HttpResponse<String> response = Unirest.post(BASE_URL + "/data/person/query")
.field("filter", filterJson)
.asString();
assertEquals(200, response.getStatus());
JSONObject jsonObject = JsonUtils.toJSONObject(response.getBody());
assertTrue(jsonObject.has("records"));
JSONArray records = jsonObject.getJSONArray("records");
assertEquals(1, records.length());
JSONObject record0 = records.getJSONObject(0);
JSONObject values0 = record0.getJSONObject("values");
assertEquals("Tim", values0.getString("firstName"));
}
/*******************************************************************************
**
*******************************************************************************/