mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
QQQ-21: added 'count' action
This commit is contained in:
4
pom.xml
4
pom.xml
@ -53,12 +53,12 @@
|
||||
<dependency>
|
||||
<groupId>com.kingsrook.qqq</groupId>
|
||||
<artifactId>qqq-backend-core</artifactId>
|
||||
<version>0.1.0-20220708.152048-3</version>
|
||||
<version>0.1.0-20220708.195335-5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.kingsrook.qqq</groupId>
|
||||
<artifactId>qqq-backend-module-rdbms</artifactId>
|
||||
<version>0.0.0</version>
|
||||
<version>0.1.0-20220708.202041-3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -32,6 +32,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import com.kingsrook.qqq.backend.core.actions.CountAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.DeleteAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.InsertAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.MetaDataAction;
|
||||
@ -51,6 +52,8 @@ import com.kingsrook.qqq.backend.core.exceptions.QNotFoundException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QUserFacingException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QValueException;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.AbstractQRequest;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.count.CountRequest;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.count.CountResult;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.delete.DeleteRequest;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.delete.DeleteResult;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.insert.InsertRequest;
|
||||
@ -213,6 +216,9 @@ public class QJavalinImplementation
|
||||
{
|
||||
get("/", QJavalinImplementation::dataQuery);
|
||||
post("/", QJavalinImplementation::dataInsert); // todo - internal to that method, if input is a list, do a bulk - else, single.
|
||||
path("/count", () -> {
|
||||
get("", QJavalinImplementation::dataCount);
|
||||
});
|
||||
// todo - add put and/or patch at this level (without a primaryKey) to do a bulk update based on primaryKeys in the records.
|
||||
path("/:primaryKey", () ->
|
||||
{
|
||||
@ -420,6 +426,44 @@ public class QJavalinImplementation
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Filter parameter is a serialized QQueryFilter object, that is to say:
|
||||
* <pre>
|
||||
* filter=
|
||||
* {"criteria":[
|
||||
* {"fieldName":"id","operator":"EQUALS","values":[1]},
|
||||
* {"fieldName":"name","operator":"IN","values":["Darin","James"]}
|
||||
* ]
|
||||
* }
|
||||
* </pre>
|
||||
*******************************************************************************/
|
||||
static void dataCount(Context context)
|
||||
{
|
||||
try
|
||||
{
|
||||
CountRequest countRequest = new CountRequest(qInstance);
|
||||
setupSession(context, countRequest);
|
||||
countRequest.setTableName(context.pathParam("table"));
|
||||
|
||||
String filter = stringQueryParam(context, "filter");
|
||||
if(filter != null)
|
||||
{
|
||||
countRequest.setFilter(JsonUtils.toObject(filter, QQueryFilter.class));
|
||||
}
|
||||
|
||||
CountAction countAction = new CountAction();
|
||||
CountResult countResult = countAction.execute(countRequest);
|
||||
|
||||
context.result(JsonUtils.toJson(countResult));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
handleException(context, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Filter parameter is a serialized QQueryFilter object, that is to say:
|
||||
|
@ -251,6 +251,24 @@ class QJavalinImplementationTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** test a table count
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void test_dataCount()
|
||||
{
|
||||
HttpResponse<String> response = Unirest.get(BASE_URL + "/data/person/count").asString();
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
JSONObject jsonObject = JsonUtils.toJSONObject(response.getBody());
|
||||
assertTrue(jsonObject.has("count"));
|
||||
int count = jsonObject.getInt("count");
|
||||
assertEquals(5, count);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** test a table query
|
||||
**
|
||||
|
Reference in New Issue
Block a user