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.command.Visibility;
|
||||||
import netneutrality.db.DBController;
|
import netneutrality.db.DBController;
|
||||||
import netneutrality.db.controllers.DBSettings;
|
import netneutrality.db.controllers.DBSettings;
|
||||||
import netneutrality.db.models.SellyOrder;
|
import netneutrality.db.models.MSellyOrder;
|
||||||
import netneutrality.http.Selly;
|
import netneutrality.http.Selly;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -55,7 +55,7 @@ public class SellyCommand extends AbstractCommand {
|
|||||||
String sellyKey = ((DBSettings) DBController.get("settings")).getSellyKey();
|
String sellyKey = ((DBSettings) DBController.get("settings")).getSellyKey();
|
||||||
Selly selly = new Selly(sellyEmail, sellyKey);
|
Selly selly = new Selly(sellyEmail, sellyKey);
|
||||||
|
|
||||||
Map<String, SellyOrder> orders = selly.getOrders();
|
Map<String, MSellyOrder> orders = selly.getOrders();
|
||||||
|
|
||||||
System.out.println(selly.getProducts().toString());
|
System.out.println(selly.getProducts().toString());
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ public class SellyCommand extends AbstractCommand {
|
|||||||
String id = parseArgs(args, 1);
|
String id = parseArgs(args, 1);
|
||||||
|
|
||||||
if (orders.containsKey(id)) {
|
if (orders.containsKey(id)) {
|
||||||
SellyOrder order = orders.get(id);
|
MSellyOrder order = orders.get(id);
|
||||||
if (email.equals(order.getEmail())) {
|
if (email.equals(order.getEmail())) {
|
||||||
if (order.getStatus() == 100) {
|
if (order.getStatus() == 100) {
|
||||||
event.getAuthor().openPrivateChannel().queue(t -> t.sendMessage("success").queue());
|
event.getAuthor().openPrivateChannel().queue(t -> t.sendMessage("success").queue());
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import java.sql.Types;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
import netneutrality.MusicBot;
|
import netneutrality.MusicBot;
|
||||||
import netneutrality.db.models.RowModel;
|
import netneutrality.db.models.MRowModel;
|
||||||
import netneutrality.db.models.TableModel;
|
import netneutrality.db.models.MTableModel;
|
||||||
import netneutrality.exceptions.UnimplementedParameterException;
|
import netneutrality.exceptions.UnimplementedParameterException;
|
||||||
|
|
||||||
public class MysqlDatabase {
|
public class MysqlDatabase {
|
||||||
@@ -226,11 +226,11 @@ public class MysqlDatabase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param rs
|
* @param rs
|
||||||
* @return a {@link TableModel} with the appropriate column and rows
|
* @return a {@link MTableModel} with the appropriate column and rows
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public TableModel convertToTableModel(ResultSet rs) throws SQLException {
|
public MTableModel convertToTableModel(ResultSet rs) throws SQLException {
|
||||||
TableModel table = new TableModel();
|
MTableModel table = new MTableModel();
|
||||||
nbRow = getNbRowFromTable(prepareString);
|
nbRow = getNbRowFromTable(prepareString);
|
||||||
|
|
||||||
ResultSetMetaData metadata = rs.getMetaData();
|
ResultSetMetaData metadata = rs.getMetaData();
|
||||||
@@ -239,7 +239,7 @@ public class MysqlDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
RowModel row = new RowModel();
|
MRowModel row = new MRowModel();
|
||||||
for (int i = 0; i < metadata.getColumnCount(); i++) {
|
for (int i = 0; i < metadata.getColumnCount(); i++) {
|
||||||
row.addColumnToRow(rs.getObject(i + 1));
|
row.addColumnToRow(rs.getObject(i + 1));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import netneutrality.db.AbstractController;
|
|||||||
import netneutrality.db.DBController;
|
import netneutrality.db.DBController;
|
||||||
import netneutrality.db.MysqlDatabase;
|
import netneutrality.db.MysqlDatabase;
|
||||||
import netneutrality.db.models.MBlacklist;
|
import netneutrality.db.models.MBlacklist;
|
||||||
import netneutrality.db.models.TableModel;
|
import netneutrality.db.models.MTableModel;
|
||||||
|
|
||||||
public class DBBlacklist extends AbstractController {
|
public class DBBlacklist extends AbstractController {
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ public class DBBlacklist extends AbstractController {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
ResultSet rs = database.prepareAndExecute("SELECT * FROM blacklist WHERE serverId = ? AND isEnabled = 1", serverId);
|
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) {
|
if (model.getNbRows() != 0) {
|
||||||
for (int row = 0; row < model.getNbRows(); row++) {
|
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.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RowModel {
|
public class MRowModel {
|
||||||
private ArrayList<Object> row;
|
private ArrayList<Object> row;
|
||||||
|
|
||||||
public RowModel() {
|
public MRowModel() {
|
||||||
row = new ArrayList<>();
|
row = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RowModel(Object... objs) {
|
public MRowModel(Object... objs) {
|
||||||
row = new ArrayList<>();
|
row = new ArrayList<>();
|
||||||
row.addAll(Arrays.asList(objs));
|
row.addAll(Arrays.asList(objs));
|
||||||
}
|
}
|
||||||
+6
-6
@@ -8,18 +8,18 @@ package netneutrality.db.models;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class RowsModel {
|
public class MRowsModel {
|
||||||
private ArrayList<RowModel> rows;
|
private ArrayList<MRowModel> rows;
|
||||||
|
|
||||||
public RowsModel() {
|
public MRowsModel() {
|
||||||
rows = new ArrayList<>();
|
rows = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRow(RowModel row) {
|
public void addRow(MRowModel row) {
|
||||||
rows.add(row);
|
rows.add(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RowModel getRowModel(int index) {
|
public MRowModel getRowModel(int index) {
|
||||||
if (!rows.isEmpty())
|
if (!rows.isEmpty())
|
||||||
return rows.get(index);
|
return rows.get(index);
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ public class RowsModel {
|
|||||||
rows.get(index).addColumnToRow(obj);
|
rows.get(index).addColumnToRow(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<RowModel> getRows() {
|
public ArrayList<MRowModel> getRows() {
|
||||||
return rows;
|
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
|
* 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 id;
|
||||||
private String product_id;
|
private String product_id;
|
||||||
@@ -22,7 +22,7 @@ public class SellyOrder {
|
|||||||
private float usdValue;
|
private float usdValue;
|
||||||
private String createdAt;
|
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.id = id;
|
||||||
this.product_id = product_id;
|
this.product_id = product_id;
|
||||||
this.email = email;
|
this.email = email;
|
||||||
@@ -93,7 +93,7 @@ public class SellyOrder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SellyOrder{" +
|
return "MSellyOrder{" +
|
||||||
"id='" + id + '\'' +
|
"id='" + id + '\'' +
|
||||||
", product_id='" + product_id + '\'' +
|
", product_id='" + product_id + '\'' +
|
||||||
", email='" + email + '\'' +
|
", 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
|
* 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 id;
|
||||||
private String title;
|
private String title;
|
||||||
+9
-9
@@ -11,35 +11,35 @@ import java.util.Arrays;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TableModel {
|
public class MTableModel {
|
||||||
private List<String> column;
|
private List<String> column;
|
||||||
private RowsModel rows;
|
private MRowsModel rows;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public TableModel() {
|
public MTableModel() {
|
||||||
this.column = new LinkedList<>();
|
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.column = new LinkedList<>();
|
||||||
this.rows = new RowsModel();
|
this.rows = new MRowsModel();
|
||||||
|
|
||||||
this.column.addAll(Arrays.asList(columns));
|
this.column.addAll(Arrays.asList(columns));
|
||||||
}
|
}
|
||||||
|
|
||||||
public TableModel addColumn(String name) {
|
public MTableModel addColumn(String name) {
|
||||||
column.add(name);
|
column.add(name);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TableModel addRow(RowModel row) {
|
public MTableModel addRow(MRowModel row) {
|
||||||
rows.addRow(row);
|
rows.addRow(row);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RowsModel getRows() {
|
public MRowsModel getRows() {
|
||||||
return rows;
|
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
|
* 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.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@@ -24,10 +24,10 @@ public class Selly {
|
|||||||
encodedAuth = Base64.getEncoder().encode(concat.getBytes());
|
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");
|
WebModule sellyApi = new WebModule("https://selly.gg/api/v2/orders");
|
||||||
Map<String, String> headers = new HashMap<>();
|
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));
|
headers.put("Authorization", "Basic " + new String(encodedAuth));
|
||||||
JSONArray response = null;
|
JSONArray response = null;
|
||||||
try {
|
try {
|
||||||
@@ -40,7 +40,7 @@ public class Selly {
|
|||||||
|
|
||||||
for (int i = 0; i < response.length(); i++) {
|
for (int i = 0; i < response.length(); i++) {
|
||||||
JSONObject order = response.getJSONObject(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"),
|
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")));
|
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