mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 21:20:45 +00:00
Added delete
This commit is contained in:
@ -5,11 +5,14 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.kingsrook.qqq.backend.core.actions.DeleteAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.InsertAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.MetaDataAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.QueryAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.TableMetaDataAction;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QUserFacingException;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.DeleteRequest;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.DeleteResult;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.InsertRequest;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.InsertResult;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.MetaDataRequest;
|
||||
@ -137,7 +140,25 @@ public class QJavalinImplementation
|
||||
*******************************************************************************/
|
||||
private static void dataDelete(Context context)
|
||||
{
|
||||
context.result("{\"deleteResult\":{}}");
|
||||
try
|
||||
{
|
||||
String table = context.pathParam("table");
|
||||
List<Serializable> primaryKeys = new ArrayList<>();
|
||||
primaryKeys.add(context.pathParam("id"));
|
||||
|
||||
DeleteRequest deleteRequest = new DeleteRequest(qInstance);
|
||||
deleteRequest.setTableName(table);
|
||||
deleteRequest.setPrimaryKeys(primaryKeys);
|
||||
|
||||
DeleteAction deleteAction = new DeleteAction();
|
||||
DeleteResult deleteResult = deleteAction.execute(deleteRequest);
|
||||
|
||||
context.result(JsonUtils.toJson(deleteResult));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
handleException(context, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,6 +16,8 @@ import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
@ -98,6 +100,7 @@ class QJavalinImplementationTest
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@ -106,7 +109,7 @@ class QJavalinImplementationTest
|
||||
{
|
||||
HttpResponse<String> response = Unirest.get(BASE_URL + "/metaData/notAnActualTable").asString();
|
||||
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus());
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus()); // todo 404?
|
||||
JSONObject jsonObject = JsonUtils.toJSONObject(response.getBody());
|
||||
assertEquals(1, jsonObject.keySet().size(), "Number of top-level keys");
|
||||
String error = jsonObject.getString("error");
|
||||
@ -137,6 +140,7 @@ class QJavalinImplementationTest
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@ -186,4 +190,33 @@ class QJavalinImplementationTest
|
||||
assertTrue(values0.has("firstName"));
|
||||
assertEquals("Bobby", values0.getString("firstName"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void test_dataDelete() throws Exception
|
||||
{
|
||||
HttpResponse<String> response = Unirest.delete(BASE_URL + "/data/person/3")
|
||||
.header("Content-Type", "application/json")
|
||||
.asString();
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
|
||||
JSONObject jsonObject = JsonUtils.toJSONObject(response.getBody());
|
||||
assertNotNull(jsonObject);
|
||||
assertEquals(1, jsonObject.getJSONArray("records").length());
|
||||
assertEquals(3, jsonObject.getJSONArray("records").getJSONObject(0).getInt("primaryKey"));
|
||||
TestUtils.runTestSql("SELECT id FROM person", (rs -> {
|
||||
int rowsFound = 0;
|
||||
while(rs.next())
|
||||
{
|
||||
rowsFound++;
|
||||
assertFalse(rs.getInt(1) == 3);
|
||||
}
|
||||
assertEquals(4, rowsFound);
|
||||
}));
|
||||
}
|
||||
}
|
@ -41,6 +41,18 @@ public class TestUtils
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public static void runTestSql(String sql, QueryManager.ResultSetProcessor resultSetProcessor) throws Exception
|
||||
{
|
||||
ConnectionManager connectionManager = new ConnectionManager();
|
||||
Connection connection = connectionManager.getConnection(new RDBSMBackendMetaData(defineBackend()));
|
||||
QueryManager.executeStatement(connection, sql, resultSetProcessor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
Reference in New Issue
Block a user