Refactor models
This commit is contained in:
1 parent
49e7f87d17
commit
989ba7ec8b
9 files changed
+37
-37
No files matched your search
@@ -11,7 +11,7 @@ import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.db.DBController;
|
||||
import netneutrality.db.controllers.DBSettings;
|
||||
import netneutrality.db.models.SellyOrder;
|
||||
import netneutrality.db.models.MSellyOrder;
|
||||
import netneutrality.http.Selly;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -55,7 +55,7 @@ public class SellyCommand extends AbstractCommand {
|
||||
String sellyKey = ((DBSettings) DBController.get("settings")).getSellyKey();
|
||||
Selly selly = new Selly(sellyEmail, sellyKey);
|
||||
|
||||
Map<String, SellyOrder> orders = selly.getOrders();
|
||||
Map<String, MSellyOrder> orders = selly.getOrders();
|
||||
|
||||
System.out.println(selly.getProducts().toString());
|
||||
|
||||
@@ -64,7 +64,7 @@ public class SellyCommand extends AbstractCommand {
|
||||
String id = parseArgs(args, 1);
|
||||
|
||||
if (orders.containsKey(id)) {
|
||||
SellyOrder order = orders.get(id);
|
||||
MSellyOrder order = orders.get(id);
|
||||
if (email.equals(order.getEmail())) {
|
||||
if (order.getStatus() == 100) {
|
||||
event.getAuthor().openPrivateChannel().queue(t -> t.sendMessage("success").queue());
|
||||
|
||||
@@ -11,8 +11,8 @@ import java.sql.Types;
|
||||
import java.util.Calendar;
|
||||
|
||||
import netneutrality.MusicBot;
|
||||
import netneutrality.db.models.RowModel;
|
||||
import netneutrality.db.models.TableModel;
|
||||
import netneutrality.db.models.MRowModel;
|
||||
import netneutrality.db.models.MTableModel;
|
||||
import netneutrality.exceptions.UnimplementedParameterException;
|
||||
|
||||
public class MysqlDatabase {
|
||||
@@ -226,11 +226,11 @@ public class MysqlDatabase {
|
||||
|
||||
/**
|
||||
* @param rs
|
||||
* @return a {@link TableModel} with the appropriate column and rows
|
||||
* @return a {@link MTableModel} with the appropriate column and rows
|
||||
* @throws SQLException
|
||||
*/
|
||||
public TableModel convertToTableModel(ResultSet rs) throws SQLException {
|
||||
TableModel table = new TableModel();
|
||||
public MTableModel convertToTableModel(ResultSet rs) throws SQLException {
|
||||
MTableModel table = new MTableModel();
|
||||
nbRow = getNbRowFromTable(prepareString);
|
||||
|
||||
ResultSetMetaData metadata = rs.getMetaData();
|
||||
@@ -239,7 +239,7 @@ public class MysqlDatabase {
|
||||
}
|
||||
|
||||
while (rs.next()) {
|
||||
RowModel row = new RowModel();
|
||||
MRowModel row = new MRowModel();
|
||||
for (int i = 0; i < metadata.getColumnCount(); i++) {
|
||||
row.addColumnToRow(rs.getObject(i + 1));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import netneutrality.db.AbstractController;
|
||||
import netneutrality.db.DBController;
|
||||
import netneutrality.db.MysqlDatabase;
|
||||
import netneutrality.db.models.MBlacklist;
|
||||
import netneutrality.db.models.TableModel;
|
||||
import netneutrality.db.models.MTableModel;
|
||||
|
||||
public class DBBlacklist extends AbstractController {
|
||||
|
||||
@@ -119,7 +119,7 @@ public class DBBlacklist extends AbstractController {
|
||||
|
||||
try {
|
||||
ResultSet rs = database.prepareAndExecute("SELECT * FROM blacklist WHERE serverId = ? AND isEnabled = 1", serverId);
|
||||
TableModel model = database.convertToTableModel(rs);
|
||||
MTableModel model = database.convertToTableModel(rs);
|
||||
|
||||
if (model.getNbRows() != 0) {
|
||||
for (int row = 0; row < model.getNbRows(); row++) {
|
||||
|
||||
+3
-3
@@ -10,14 +10,14 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class RowModel {
|
||||
public class MRowModel {
|
||||
private ArrayList<Object> row;
|
||||
|
||||
public RowModel() {
|
||||
public MRowModel() {
|
||||
row = new ArrayList<>();
|
||||
}
|
||||
|
||||
public RowModel(Object... objs) {
|
||||
public MRowModel(Object... objs) {
|
||||
row = new ArrayList<>();
|
||||
row.addAll(Arrays.asList(objs));
|
||||
}
|
||||
+6
-6
@@ -8,18 +8,18 @@ package netneutrality.db.models;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RowsModel {
|
||||
private ArrayList<RowModel> rows;
|
||||
public class MRowsModel {
|
||||
private ArrayList<MRowModel> rows;
|
||||
|
||||
public RowsModel() {
|
||||
public MRowsModel() {
|
||||
rows = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addRow(RowModel row) {
|
||||
public void addRow(MRowModel row) {
|
||||
rows.add(row);
|
||||
}
|
||||
|
||||
public RowModel getRowModel(int index) {
|
||||
public MRowModel getRowModel(int index) {
|
||||
if (!rows.isEmpty())
|
||||
return rows.get(index);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class RowsModel {
|
||||
rows.get(index).addColumnToRow(obj);
|
||||
}
|
||||
|
||||
public ArrayList<RowModel> getRows() {
|
||||
public ArrayList<MRowModel> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ package netneutrality.db.models;
|
||||
* This file is closed-source. It should not be distributed or copied in any way or form
|
||||
*/
|
||||
|
||||
public class SellyOrder {
|
||||
public class MSellyOrder {
|
||||
|
||||
private String id;
|
||||
private String product_id;
|
||||
@@ -22,7 +22,7 @@ public class SellyOrder {
|
||||
private float usdValue;
|
||||
private String createdAt;
|
||||
|
||||
public SellyOrder(String id, String product_id, String email, String ip, float value, String currency, String gateway, int risk, int status, int cryptoValue, String cryptoAddress, float usdValue, String createdAt) {
|
||||
public MSellyOrder(String id, String product_id, String email, String ip, float value, String currency, String gateway, int risk, int status, int cryptoValue, String cryptoAddress, float usdValue, String createdAt) {
|
||||
this.id = id;
|
||||
this.product_id = product_id;
|
||||
this.email = email;
|
||||
@@ -93,7 +93,7 @@ public class SellyOrder {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SellyOrder{" +
|
||||
return "MSellyOrder{" +
|
||||
"id='" + id + '\'' +
|
||||
", product_id='" + product_id + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
+1
-1
@@ -6,7 +6,7 @@ package netneutrality.db.models;
|
||||
* This file is closed-source. It should not be distributed or copied in any way or form
|
||||
*/
|
||||
|
||||
public class SellyProduct {
|
||||
public class MSellyProduct {
|
||||
|
||||
private String id;
|
||||
private String title;
|
||||
+9
-9
@@ -11,35 +11,35 @@ import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class TableModel {
|
||||
public class MTableModel {
|
||||
private List<String> column;
|
||||
private RowsModel rows;
|
||||
private MRowsModel rows;
|
||||
|
||||
|
||||
|
||||
public TableModel() {
|
||||
public MTableModel() {
|
||||
this.column = new LinkedList<>();
|
||||
this.rows = new RowsModel();
|
||||
this.rows = new MRowsModel();
|
||||
}
|
||||
|
||||
public TableModel(String... columns) {
|
||||
public MTableModel(String... columns) {
|
||||
this.column = new LinkedList<>();
|
||||
this.rows = new RowsModel();
|
||||
this.rows = new MRowsModel();
|
||||
|
||||
this.column.addAll(Arrays.asList(columns));
|
||||
}
|
||||
|
||||
public TableModel addColumn(String name) {
|
||||
public MTableModel addColumn(String name) {
|
||||
column.add(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TableModel addRow(RowModel row) {
|
||||
public MTableModel addRow(MRowModel row) {
|
||||
rows.addRow(row);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RowsModel getRows() {
|
||||
public MRowsModel getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ package netneutrality.http;
|
||||
* This file is closed-source. It should not be distributed or copied in any way or form
|
||||
*/
|
||||
|
||||
import netneutrality.db.models.SellyOrder;
|
||||
import netneutrality.db.models.MSellyOrder;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -24,10 +24,10 @@ public class Selly {
|
||||
encodedAuth = Base64.getEncoder().encode(concat.getBytes());
|
||||
}
|
||||
|
||||
public Map<String, SellyOrder> getOrders() {
|
||||
public Map<String, MSellyOrder> getOrders() {
|
||||
WebModule sellyApi = new WebModule("https://selly.gg/api/v2/orders");
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
Map<String, SellyOrder> orders = new HashMap<>();
|
||||
Map<String, MSellyOrder> orders = new HashMap<>();
|
||||
headers.put("Authorization", "Basic " + new String(encodedAuth));
|
||||
JSONArray response = null;
|
||||
try {
|
||||
@@ -40,7 +40,7 @@ public class Selly {
|
||||
|
||||
for (int i = 0; i < response.length(); i++) {
|
||||
JSONObject order = response.getJSONObject(i);
|
||||
orders.put(order.getString("id"), new SellyOrder(order.getString("id"), order.getString("product_id"), order.getString("email"), order.getString("ip_address"),
|
||||
orders.put(order.getString("id"), new MSellyOrder(order.getString("id"), order.getString("product_id"), order.getString("email"), order.getString("ip_address"),
|
||||
Float.parseFloat(order.getString("value")), order.getString("currency"), order.getString("gateway"), order.getInt("risk_level"), order.getInt("status"),
|
||||
order.getInt("crypto_value"), order.getString("crypto_address"), Float.parseFloat(order.getString("usd_value")), order.getString("created_at")));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user