Skip to content

Commit f794fc0

Browse files
sam-i-am012korydraughn
authored andcommitted
[#29] Optional params and missing methods for query endpoints added.
1 parent 2e3ba81 commit f794fc0

File tree

2 files changed

+76
-18
lines changed

2 files changed

+76
-18
lines changed

src/main/java/org/example/Operations/QueryOperations.java

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.example.Operations;
22

3+
import org.example.Properties.DataObject.DataObjectTouchParams;
34
import org.example.Properties.Query.QueryExecuteGenqueryParams;
5+
import org.example.Properties.Query.QueryExecuteSpecifcQueryParams;
46
import org.example.Wrapper;
57
import org.example.Util.HttpRequestUtil;
68
import org.example.Util.Response;
@@ -51,30 +53,42 @@ public Response execute_genquery(String token, String query) {
5153
return this.execute_genquery(token, query, params);
5254
}
5355

54-
public Response execute_specific_query(String token, String name, String args, String argsDelimiter,
55-
int offset, int count) throws IOException, InterruptedException {
56+
public Response execute_specific_query(String token, String name, QueryExecuteSpecifcQueryParams params) {
5657
Map<Object, Object> formData = new HashMap<>();
5758
formData.put("op", "execute_specific_query");
5859
formData.put("name", name);
59-
if (args != null) {
60-
formData.put("args", args);
61-
}
62-
if (argsDelimiter != null) {
63-
formData.put("args-delimiter", argsDelimiter);
64-
} else {
65-
formData.put("args-delimiter", ","); // default
66-
}
67-
if (offset != -1) {
68-
formData.put("offset", String.valueOf(offset));
69-
} else {
70-
formData.put("offset", "0"); // default
71-
}
72-
if (count != -1) {
73-
formData.put("count", String.valueOf(count));
74-
}
60+
params.getArgs().ifPresent(val -> formData.put("args", val));
61+
params.getArgsDelimiter().ifPresent(val -> formData.put("args-delimiter", val));
62+
params.getOffset().ifPresent(val -> formData.put("offset", String.valueOf(val)));
63+
params.getCount().ifPresent(val -> formData.put("count", String.valueOf(val)));
7564

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

69+
public Response execute_specific_query(String token, String name) {
70+
QueryExecuteSpecifcQueryParams param = new QueryExecuteSpecifcQueryParams();
71+
return this.execute_specific_query(token, name, param);
72+
}
73+
74+
public Response add_specific_query(String token, String name, String sql) {
75+
Map<Object, Object> formData = new HashMap<>();
76+
formData.put("op", "add_specific_query");
77+
formData.put("name", name);
78+
formData.put("sql", sql);
79+
80+
HttpResponse<String> response = HttpRequestUtil.sendAndParsePOST(formData, baseUrl, token, client.getClient());
81+
return new Response(response.statusCode(), response.body());
82+
}
83+
84+
public Response remove_specific_query(String token, String name) {
85+
Map<Object, Object> formData = new HashMap<>();
86+
formData.put("op", "remove_specific_query");
87+
formData.put("name", name);
88+
89+
HttpResponse<String> response = HttpRequestUtil.sendAndParsePOST(formData, baseUrl, token, client.getClient());
90+
return new Response(response.statusCode(), response.body());
91+
}
92+
93+
8094
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.example.Properties.Query;
2+
3+
import javax.swing.text.html.Option;
4+
import java.util.Optional;
5+
import java.util.OptionalInt;
6+
7+
public class QueryExecuteSpecifcQueryParams {
8+
Optional<String> args = Optional.empty();
9+
Optional<String> argsDelimiter = Optional.empty();
10+
OptionalInt offset = OptionalInt.empty();
11+
OptionalInt count = OptionalInt.empty();
12+
13+
public Optional<String> getArgs() {
14+
return args;
15+
}
16+
17+
public void setArgs(String args) {
18+
this.args = Optional.of(args);
19+
}
20+
21+
public Optional<String> getArgsDelimiter() {
22+
return argsDelimiter;
23+
}
24+
25+
public void setArgsDelimiter(String argsDelimiter) {
26+
this.argsDelimiter = Optional.of(argsDelimiter);
27+
}
28+
29+
public OptionalInt getOffset() {
30+
return offset;
31+
}
32+
33+
public void setOffset(int offset) {
34+
this.offset = OptionalInt.of(offset);
35+
}
36+
37+
public OptionalInt getCount() {
38+
return count;
39+
}
40+
41+
public void setCount(int count) {
42+
this.count = OptionalInt.of(count);
43+
}
44+
}

0 commit comments

Comments
 (0)