mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-17 20:50:44 +00:00
Update to accept count filter as POST
This commit is contained in:
@ -281,6 +281,7 @@ public class QJavalinImplementation
|
||||
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);
|
||||
post("/count", QJavalinImplementation::dataCount);
|
||||
get("/export", QJavalinImplementation::dataExportWithoutFilename);
|
||||
get("/export/{filename}", QJavalinImplementation::dataExportWithFilename);
|
||||
get("/possibleValues/{fieldName}", QJavalinImplementation::possibleValues);
|
||||
@ -562,6 +563,10 @@ public class QJavalinImplementation
|
||||
countInput.setTableName(context.pathParam("table"));
|
||||
|
||||
String filter = stringQueryParam(context, "filter");
|
||||
if(!StringUtils.hasContent(filter))
|
||||
{
|
||||
filter = context.formParam("filter");
|
||||
}
|
||||
if(filter != null)
|
||||
{
|
||||
countInput.setFilter(JsonUtils.toObject(filter, QQueryFilter.class));
|
||||
|
@ -239,6 +239,48 @@ class QJavalinImplementationTest extends QJavalinTestBase
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** test a table count with a filter.
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void test_dataCountWithFilter()
|
||||
{
|
||||
String filterJson = getFirstNameEqualsTimFilterJSON();
|
||||
HttpResponse<String> response = Unirest.get(BASE_URL + "/data/person/count?filter=" + URLEncoder.encode(filterJson, StandardCharsets.UTF_8)).asString();
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
JSONObject jsonObject = JsonUtils.toJSONObject(response.getBody());
|
||||
|
||||
assertTrue(jsonObject.has("count"));
|
||||
int count = jsonObject.getInt("count");
|
||||
assertEquals(1, count);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** test a table count POST.
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void test_dataCountPOST()
|
||||
{
|
||||
String filterJson = getFirstNameEqualsTimFilterJSON();
|
||||
HttpResponse<String> response = Unirest.post(BASE_URL + "/data/person/count")
|
||||
.field("filter", filterJson)
|
||||
.asString();
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
JSONObject jsonObject = JsonUtils.toJSONObject(response.getBody());
|
||||
|
||||
assertTrue(jsonObject.has("count"));
|
||||
int count = jsonObject.getInt("count");
|
||||
assertEquals(1, count);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** test a table query
|
||||
**
|
||||
|
Reference in New Issue
Block a user