Skip to content

Commit

Permalink
[#29] Optional params and missing methods for query endpoints added.
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-i-am012 authored and korydraughn committed Jul 26, 2024
1 parent 2e3ba81 commit f794fc0
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 18 deletions.
50 changes: 32 additions & 18 deletions src/main/java/org/example/Operations/QueryOperations.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.example.Operations;

import org.example.Properties.DataObject.DataObjectTouchParams;
import org.example.Properties.Query.QueryExecuteGenqueryParams;
import org.example.Properties.Query.QueryExecuteSpecifcQueryParams;
import org.example.Wrapper;
import org.example.Util.HttpRequestUtil;
import org.example.Util.Response;
Expand Down Expand Up @@ -51,30 +53,42 @@ public Response execute_genquery(String token, String query) {
return this.execute_genquery(token, query, params);
}

public Response execute_specific_query(String token, String name, String args, String argsDelimiter,
int offset, int count) throws IOException, InterruptedException {
public Response execute_specific_query(String token, String name, QueryExecuteSpecifcQueryParams params) {
Map<Object, Object> formData = new HashMap<>();
formData.put("op", "execute_specific_query");
formData.put("name", name);
if (args != null) {
formData.put("args", args);
}
if (argsDelimiter != null) {
formData.put("args-delimiter", argsDelimiter);
} else {
formData.put("args-delimiter", ","); // default
}
if (offset != -1) {
formData.put("offset", String.valueOf(offset));
} else {
formData.put("offset", "0"); // default
}
if (count != -1) {
formData.put("count", String.valueOf(count));
}
params.getArgs().ifPresent(val -> formData.put("args", val));
params.getArgsDelimiter().ifPresent(val -> formData.put("args-delimiter", val));
params.getOffset().ifPresent(val -> formData.put("offset", String.valueOf(val)));
params.getCount().ifPresent(val -> formData.put("count", String.valueOf(val)));

HttpResponse<String> response = HttpRequestUtil.sendAndParseGET(formData, baseUrl, token, client.getClient());
return new Response(response.statusCode(), response.body());
}

public Response execute_specific_query(String token, String name) {
QueryExecuteSpecifcQueryParams param = new QueryExecuteSpecifcQueryParams();
return this.execute_specific_query(token, name, param);
}

public Response add_specific_query(String token, String name, String sql) {
Map<Object, Object> formData = new HashMap<>();
formData.put("op", "add_specific_query");
formData.put("name", name);
formData.put("sql", sql);

HttpResponse<String> response = HttpRequestUtil.sendAndParsePOST(formData, baseUrl, token, client.getClient());
return new Response(response.statusCode(), response.body());
}

public Response remove_specific_query(String token, String name) {
Map<Object, Object> formData = new HashMap<>();
formData.put("op", "remove_specific_query");
formData.put("name", name);

HttpResponse<String> response = HttpRequestUtil.sendAndParsePOST(formData, baseUrl, token, client.getClient());
return new Response(response.statusCode(), response.body());
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.example.Properties.Query;

import javax.swing.text.html.Option;
import java.util.Optional;
import java.util.OptionalInt;

public class QueryExecuteSpecifcQueryParams {
Optional<String> args = Optional.empty();
Optional<String> argsDelimiter = Optional.empty();
OptionalInt offset = OptionalInt.empty();
OptionalInt count = OptionalInt.empty();

public Optional<String> getArgs() {
return args;
}

public void setArgs(String args) {
this.args = Optional.of(args);
}

public Optional<String> getArgsDelimiter() {
return argsDelimiter;
}

public void setArgsDelimiter(String argsDelimiter) {
this.argsDelimiter = Optional.of(argsDelimiter);
}

public OptionalInt getOffset() {
return offset;
}

public void setOffset(int offset) {
this.offset = OptionalInt.of(offset);
}

public OptionalInt getCount() {
return count;
}

public void setCount(int count) {
this.count = OptionalInt.of(count);
}
}

0 comments on commit f794fc0

Please sign in to comment.