diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/gui/BazaarAddItemGui.java b/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/gui/BazaarAddItemGui.java index e6a2969c6..f30113368 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/gui/BazaarAddItemGui.java +++ b/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/gui/BazaarAddItemGui.java @@ -1,18 +1,19 @@ package net.leaderos.plugin.modules.bazaar.gui; import com.cryptomorin.xseries.XMaterial; -import de.themoep.inventorygui.*; +import de.themoep.inventorygui.GuiStorageElement; +import de.themoep.inventorygui.InventoryGui; import lombok.SneakyThrows; import net.leaderos.plugin.Bukkit; import net.leaderos.plugin.helpers.ChatUtil; import net.leaderos.plugin.helpers.GameUtil; import net.leaderos.plugin.helpers.GuiHelper; -import net.leaderos.plugin.modules.cache.model.User; -import net.leaderos.plugin.modules.bazaar.BazaarModule; import net.leaderos.plugin.helpers.ItemUtil; +import net.leaderos.plugin.modules.bazaar.BazaarModule; +import net.leaderos.plugin.modules.cache.model.User; import net.leaderos.shared.helpers.Placeholder; import net.leaderos.shared.model.Response; -import net.leaderos.shared.model.request.PostRequest; +import net.leaderos.shared.model.request.impl.bazaar.AddBazaarItemRequest; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryType; @@ -22,7 +23,10 @@ import java.net.HttpURLConnection; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; import java.util.stream.Collectors; /** @@ -108,28 +112,9 @@ public static void showGui(Player player, int itemAmount) { String modelId = ItemUtil.getModelId(item); String enchantment = ItemUtil.getEnchantments(item); - Map body = new HashMap<>(); - body.put("owner", userId); - body.put("name", name); - if (lore != null) - body.put("lore", lore); - body.put("amount", String.valueOf(amount)); - body.put("maxDurability", String.valueOf(maxDurability)); - body.put("durability", String.valueOf(durability)); - - body.put("base64", base64); - body.put("price", String.valueOf(price)); - body.put("creationDate", creationDate); - if (modelId != null) - body.put("modelID", modelId); - if (enchantment != null) - body.put("enchantment", enchantment); - body.put("serverID", String.valueOf(serverId)); - body.put("itemID", material.name()); - // Sends response try { - Response postBazaarItem = new PostRequest("bazaar/storages/" + userId + "/items", body).getResponse(); + Response postBazaarItem = new AddBazaarItemRequest(userId, name, lore, amount, maxDurability, durability, base64, price, creationDate, modelId, enchantment, serverId, material.name()).getResponse(); if (postBazaarItem.getResponseCode() == HttpURLConnection.HTTP_OK && postBazaarItem.getResponseMessage().getBoolean("status")) { ChatUtil.sendMessage(player, ChatUtil.replacePlaceholders( diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/model/PlayerBazaar.java b/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/model/PlayerBazaar.java index c9bfb19d0..aca4c6a74 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/model/PlayerBazaar.java +++ b/bukkit/src/main/java/net/leaderos/plugin/modules/bazaar/model/PlayerBazaar.java @@ -5,11 +5,12 @@ import lombok.SneakyThrows; import net.leaderos.plugin.Bukkit; import net.leaderos.plugin.helpers.ChatUtil; -import net.leaderos.plugin.modules.bazaar.BazaarModule; import net.leaderos.plugin.helpers.ItemUtil; +import net.leaderos.plugin.modules.bazaar.BazaarModule; import net.leaderos.shared.model.Response; -import net.leaderos.shared.model.request.DeleteRequest; import net.leaderos.shared.model.request.GetRequest; +import net.leaderos.shared.model.request.impl.bazaar.GetBazaarItemsRequest; +import net.leaderos.shared.model.request.impl.bazaar.RemoveBazaarItemRequest; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -77,7 +78,7 @@ public ItemStack getItem() { */ @SneakyThrows public boolean withdrawItem(Player player) { - Response deleteRequest = new DeleteRequest("bazaar/storages/" + getUserId() + "/items/" + getId()).getResponse(); + Response deleteRequest = new RemoveBazaarItemRequest(getUserId(), getUserId()).getResponse(); if (deleteRequest.getResponseCode() == HttpURLConnection.HTTP_OK && deleteRequest.getResponseMessage().getBoolean("status")) { ItemStack item = ItemUtil.fromBase64(getBase64()); @@ -97,7 +98,7 @@ public boolean withdrawItem(Player player) { public static List getBazaarStorage(String userId) { try { int serverId = BazaarModule.getServerId(); - GetRequest getRequest = new GetRequest("bazaar/storages/" + userId + "/items?serverID=" + serverId); + GetRequest getRequest = new GetBazaarItemsRequest(userId, String.valueOf(serverId)); JSONObject response = getRequest.getResponse().getResponseMessage(); List playerBazaarList = new ArrayList<>(); response.getJSONArray("array").forEach(bazaar -> playerBazaarList.add(new PlayerBazaar((JSONObject) bazaar, userId))); diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/cache/model/User.java b/bukkit/src/main/java/net/leaderos/plugin/modules/cache/model/User.java index 8b3231298..83aaad425 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/modules/cache/model/User.java +++ b/bukkit/src/main/java/net/leaderos/plugin/modules/cache/model/User.java @@ -5,6 +5,7 @@ import lombok.SneakyThrows; import net.leaderos.plugin.Bukkit; import net.leaderos.shared.model.request.GetRequest; +import net.leaderos.shared.model.request.impl.user.GetUserRequest; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -90,7 +91,7 @@ public User(@NotNull JSONObject user) { this.creationDate = format.parse(user.getString("creationDate")); // Adds data to cache - userList.remove(username); + userList.remove(username); // why remove? instead, can't we just add the new object? afaik, it replaces the old value userList.put(username, this); } @@ -151,7 +152,7 @@ public static void loadAllPlayers() { */ public static void loadPlayerCache(Player player) { try { - GetRequest getRequest = new GetRequest("users/" + player.getName()); + GetRequest getRequest = new GetUserRequest(player.getName()); new User(getRequest.getResponse().getResponseMessage()); } catch (Exception ignored) {} diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/donations/managers/DonationManager.java b/bukkit/src/main/java/net/leaderos/plugin/modules/donations/managers/DonationManager.java index b29dac8ae..f592af289 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/modules/donations/managers/DonationManager.java +++ b/bukkit/src/main/java/net/leaderos/plugin/modules/donations/managers/DonationManager.java @@ -3,10 +3,10 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; -import net.leaderos.plugin.modules.donations.model.DonationType; import net.leaderos.plugin.modules.donations.model.Donation; +import net.leaderos.plugin.modules.donations.model.DonationType; import net.leaderos.shared.model.Response; -import net.leaderos.shared.model.request.GetRequest; +import net.leaderos.shared.model.request.impl.donations.GetDonationsRequest; import org.json.JSONArray; import org.json.JSONObject; @@ -105,7 +105,7 @@ private void loadDonationsData() { this.donations = new ArrayList<>(); List donations = new ArrayList<>(); try { - Response recentDonationResponse = new GetRequest("store/donations/?type=" + getType().getRequest() + "&limit=10").getResponse(); + Response recentDonationResponse = new GetDonationsRequest(getType().getRequest()).getResponse(); if (recentDonationResponse.getResponseCode() == HttpURLConnection.HTTP_OK) { JSONArray data = recentDonationResponse.getResponseMessage().getJSONArray("array"); for (int i = 0; i < data.length(); i++) { diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/helpers/WebStoreHelper.java b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/helpers/WebStoreHelper.java index 0f1b1805e..5ce8f1113 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/helpers/WebStoreHelper.java +++ b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/helpers/WebStoreHelper.java @@ -6,26 +6,19 @@ import net.leaderos.plugin.helpers.ChatUtil; import net.leaderos.plugin.helpers.MDChat.MDChatAPI; import net.leaderos.plugin.modules.cache.model.User; -import net.leaderos.plugin.modules.webstore.model.Product; import net.leaderos.shared.model.Response; -import net.leaderos.shared.model.request.PostRequest; +import net.leaderos.shared.model.request.impl.store.BuyRequest; import net.leaderos.shared.modules.auth.AuthHelper; import net.leaderos.shared.modules.credit.enums.UpdateType; import org.bukkit.entity.Player; import java.io.IOException; import java.net.HttpURLConnection; -import java.util.HashMap; -import java.util.Map; public class WebStoreHelper { public static void buyItem(Player player, String productId) { if (User.isPlayerAuthed(player)) { User user = User.getUser(player.getName()); - Map body = new HashMap<>(); - body.put("user", user.getId()); - body.put("products[0][id]", productId); - body.put("products[0][quantity]", "1"); // Titles String title = ChatUtil.color(Bukkit.getInstance().getLangFile().getGui().getWebStoreGui().getBuyWebStoreTitle()); String subtitleError = ChatUtil.color(Bukkit.getInstance().getLangFile().getGui().getWebStoreGui().getBuyWebStoreError()); @@ -35,7 +28,7 @@ public static void buyItem(Player player, String productId) { player.sendTitle(title, subtitleProgress); // Buy progress try { - Response buyRequest = new PostRequest("store/buy", body).getResponse(); + Response buyRequest = new BuyRequest(user.getId(), productId).getResponse(); if (buyRequest.getResponseCode() == HttpURLConnection.HTTP_OK) { // Calls UpdateCache event for update player's cache double credits = buyRequest.getResponseMessage().getJSONObject("data").getDouble("credits"); diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Category.java b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Category.java index 94c83ffba..71f9d0fc1 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Category.java +++ b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Category.java @@ -8,6 +8,7 @@ import net.leaderos.plugin.helpers.ItemUtil; import net.leaderos.shared.exceptions.RequestException; import net.leaderos.shared.model.request.GetRequest; +import net.leaderos.shared.model.request.impl.store.ListingRequest; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.json.JSONArray; @@ -144,7 +145,7 @@ public static void loadAllCategories() throws IOException, RequestException { if (!categories.isEmpty()) categories.clear(); - GetRequest getRequest = new GetRequest("store/listing"); + GetRequest getRequest = new ListingRequest(); JSONObject response = getRequest.getResponse().getResponseMessage(); response.getJSONArray("categories").forEach(jsonObj -> new Category((JSONObject) jsonObj)); } diff --git a/shared/src/main/java/net/leaderos/shared/model/request/impl/auth/AuthRequest.java b/shared/src/main/java/net/leaderos/shared/model/request/impl/auth/AuthRequest.java new file mode 100644 index 000000000..a35ed00c9 --- /dev/null +++ b/shared/src/main/java/net/leaderos/shared/model/request/impl/auth/AuthRequest.java @@ -0,0 +1,17 @@ +package net.leaderos.shared.model.request.impl.auth; + +import net.leaderos.shared.model.request.PostRequest; + +import java.io.IOException; +import java.util.HashMap; + +public class AuthRequest extends PostRequest { + + public AuthRequest(String username, String uuid) throws IOException { + super("auth/generate-link", new HashMap() {{ + put("username", username); + put("uuid", uuid); + }}); + } + +} diff --git a/shared/src/main/java/net/leaderos/shared/model/request/impl/bazaar/AddBazaarItemRequest.java b/shared/src/main/java/net/leaderos/shared/model/request/impl/bazaar/AddBazaarItemRequest.java new file mode 100644 index 000000000..70570ef36 --- /dev/null +++ b/shared/src/main/java/net/leaderos/shared/model/request/impl/bazaar/AddBazaarItemRequest.java @@ -0,0 +1,31 @@ +package net.leaderos.shared.model.request.impl.bazaar; + +import net.leaderos.shared.model.request.PostRequest; + +import java.io.IOException; +import java.util.HashMap; + +public class AddBazaarItemRequest extends PostRequest { + + public AddBazaarItemRequest(String userId, String name, String lore, int amount, int maxDurability, int durability, String base64, double price, String creationDate, String modelId, String enchantment, int serverId, String item) throws IOException { + super("bazaar/storages/" + userId + "/items", new HashMap() {{ + put("owner", userId); + put("name", name); + if (lore != null) + put("lore", lore); + put("amount", String.valueOf(amount)); + put("maxDurability", String.valueOf(maxDurability)); + put("durability", String.valueOf(durability)); + put("base64", base64); + put("price", String.valueOf(price)); + put("creationDate", String.valueOf(creationDate)); + if (modelId != null) + put("modelID", modelId); + if (enchantment != null) + put("enchantment", enchantment); + put("serverID", String.valueOf(serverId)); + put("itemID", item); + }}); + } + +} diff --git a/shared/src/main/java/net/leaderos/shared/model/request/impl/bazaar/GetBazaarItemsRequest.java b/shared/src/main/java/net/leaderos/shared/model/request/impl/bazaar/GetBazaarItemsRequest.java new file mode 100644 index 000000000..340cc2df4 --- /dev/null +++ b/shared/src/main/java/net/leaderos/shared/model/request/impl/bazaar/GetBazaarItemsRequest.java @@ -0,0 +1,13 @@ +package net.leaderos.shared.model.request.impl.bazaar; + +import net.leaderos.shared.model.request.GetRequest; + +import java.io.IOException; + +public class GetBazaarItemsRequest extends GetRequest { + + public GetBazaarItemsRequest(String userId, String serverId) throws IOException { + super("bazaar/storages/" + userId + "/items?serverID=" + serverId); + } + +} diff --git a/shared/src/main/java/net/leaderos/shared/model/request/impl/bazaar/RemoveBazaarItemRequest.java b/shared/src/main/java/net/leaderos/shared/model/request/impl/bazaar/RemoveBazaarItemRequest.java new file mode 100644 index 000000000..d678e979b --- /dev/null +++ b/shared/src/main/java/net/leaderos/shared/model/request/impl/bazaar/RemoveBazaarItemRequest.java @@ -0,0 +1,14 @@ +package net.leaderos.shared.model.request.impl.bazaar; + +import net.leaderos.shared.model.request.DeleteRequest; + +import java.io.IOException; +import java.util.HashMap; + +public class RemoveBazaarItemRequest extends DeleteRequest { + + public RemoveBazaarItemRequest(String userId, String id) throws IOException { + super("bazaar/storages/" + userId + "/items/" + id, new HashMap<>()); + } + +} diff --git a/shared/src/main/java/net/leaderos/shared/model/request/impl/credit/AddCreditsRequest.java b/shared/src/main/java/net/leaderos/shared/model/request/impl/credit/AddCreditsRequest.java new file mode 100644 index 000000000..1196b586d --- /dev/null +++ b/shared/src/main/java/net/leaderos/shared/model/request/impl/credit/AddCreditsRequest.java @@ -0,0 +1,16 @@ +package net.leaderos.shared.model.request.impl.credit; + +import net.leaderos.shared.model.request.PostRequest; + +import java.io.IOException; +import java.util.HashMap; + +public class AddCreditsRequest extends PostRequest { + + public AddCreditsRequest(String target, double amount) throws IOException { + super("credits/" + target + "/add", new HashMap() {{ + put("amount", String.valueOf(amount)); + }}); + } + +} diff --git a/shared/src/main/java/net/leaderos/shared/model/request/impl/credit/GetCreditsRequest.java b/shared/src/main/java/net/leaderos/shared/model/request/impl/credit/GetCreditsRequest.java new file mode 100644 index 000000000..73cba0b52 --- /dev/null +++ b/shared/src/main/java/net/leaderos/shared/model/request/impl/credit/GetCreditsRequest.java @@ -0,0 +1,13 @@ +package net.leaderos.shared.model.request.impl.credit; + +import net.leaderos.shared.model.request.GetRequest; + +import java.io.IOException; + +public class GetCreditsRequest extends GetRequest { + + public GetCreditsRequest(String username) throws IOException { + super("credits/" + username); + } + +} diff --git a/shared/src/main/java/net/leaderos/shared/model/request/impl/credit/RemoveCreditsRequest.java b/shared/src/main/java/net/leaderos/shared/model/request/impl/credit/RemoveCreditsRequest.java new file mode 100644 index 000000000..3a6657034 --- /dev/null +++ b/shared/src/main/java/net/leaderos/shared/model/request/impl/credit/RemoveCreditsRequest.java @@ -0,0 +1,14 @@ +package net.leaderos.shared.model.request.impl.credit; + +import net.leaderos.shared.model.request.PostRequest; + +import java.io.IOException; +import java.util.HashMap; + +public class RemoveCreditsRequest extends PostRequest { + public RemoveCreditsRequest(String target, double amount) throws IOException { + super("credits/" + target + "/remove", new HashMap() {{ + put("amount", String.valueOf(amount)); + }}); + } +} diff --git a/shared/src/main/java/net/leaderos/shared/model/request/impl/credit/SendCreditsRequest.java b/shared/src/main/java/net/leaderos/shared/model/request/impl/credit/SendCreditsRequest.java new file mode 100644 index 000000000..224f01cc7 --- /dev/null +++ b/shared/src/main/java/net/leaderos/shared/model/request/impl/credit/SendCreditsRequest.java @@ -0,0 +1,15 @@ +package net.leaderos.shared.model.request.impl.credit; + +import net.leaderos.shared.model.request.PostRequest; + +import java.io.IOException; +import java.util.HashMap; + +public class SendCreditsRequest extends PostRequest { + public SendCreditsRequest(String sender, String target, double amount) throws IOException { + super("credits/" + sender + "/send", new HashMap() {{ + put("target", target); + put("amount", String.valueOf(amount)); + }}); + } +} diff --git a/shared/src/main/java/net/leaderos/shared/model/request/impl/credit/SetCreditsRequest.java b/shared/src/main/java/net/leaderos/shared/model/request/impl/credit/SetCreditsRequest.java new file mode 100644 index 000000000..6cb91595a --- /dev/null +++ b/shared/src/main/java/net/leaderos/shared/model/request/impl/credit/SetCreditsRequest.java @@ -0,0 +1,14 @@ +package net.leaderos.shared.model.request.impl.credit; + +import net.leaderos.shared.model.request.PostRequest; + +import java.io.IOException; +import java.util.HashMap; + +public class SetCreditsRequest extends PostRequest { + public SetCreditsRequest(String target, double amount) throws IOException { + super("credits/" + target + "/set", new HashMap() {{ + put("amount", String.valueOf(amount)); + }}); + } +} diff --git a/shared/src/main/java/net/leaderos/shared/model/request/impl/discord/DiscordSyncRequest.java b/shared/src/main/java/net/leaderos/shared/model/request/impl/discord/DiscordSyncRequest.java new file mode 100644 index 000000000..cecd0aac0 --- /dev/null +++ b/shared/src/main/java/net/leaderos/shared/model/request/impl/discord/DiscordSyncRequest.java @@ -0,0 +1,14 @@ +package net.leaderos.shared.model.request.impl.discord; + +import net.leaderos.shared.model.request.PostRequest; + +import java.io.IOException; +import java.util.HashMap; + +public class DiscordSyncRequest extends PostRequest { + public DiscordSyncRequest(String username) throws IOException { + super("integrations/discord/sync", new HashMap() {{ + put("user", username); + }}); + } +} diff --git a/shared/src/main/java/net/leaderos/shared/model/request/impl/donations/GetDonationsRequest.java b/shared/src/main/java/net/leaderos/shared/model/request/impl/donations/GetDonationsRequest.java new file mode 100644 index 000000000..fb34a241d --- /dev/null +++ b/shared/src/main/java/net/leaderos/shared/model/request/impl/donations/GetDonationsRequest.java @@ -0,0 +1,17 @@ +package net.leaderos.shared.model.request.impl.donations; + +import net.leaderos.shared.model.request.GetRequest; + +import java.io.IOException; + +public class GetDonationsRequest extends GetRequest { + /** + * Request constructor + * + * @param api of request + * @throws IOException for HttpUrlConnection + */ + public GetDonationsRequest(String type) throws IOException { + super("store/donations/?type=" + type + "&limit=10"); + } +} diff --git a/shared/src/main/java/net/leaderos/shared/model/request/impl/store/BuyRequest.java b/shared/src/main/java/net/leaderos/shared/model/request/impl/store/BuyRequest.java new file mode 100644 index 000000000..1226c19b2 --- /dev/null +++ b/shared/src/main/java/net/leaderos/shared/model/request/impl/store/BuyRequest.java @@ -0,0 +1,18 @@ +package net.leaderos.shared.model.request.impl.store; + +import net.leaderos.shared.model.request.PostRequest; + +import java.io.IOException; +import java.util.HashMap; + +public class BuyRequest extends PostRequest { + + public BuyRequest(String user, String productId) throws IOException { + super("store/buy", new HashMap() {{ + put("user", user); + put("products[0][id]", productId); + put("products[0][quantity]", "1"); + }}); + } + +} diff --git a/shared/src/main/java/net/leaderos/shared/model/request/impl/store/ListingRequest.java b/shared/src/main/java/net/leaderos/shared/model/request/impl/store/ListingRequest.java new file mode 100644 index 000000000..91a1a9c8d --- /dev/null +++ b/shared/src/main/java/net/leaderos/shared/model/request/impl/store/ListingRequest.java @@ -0,0 +1,17 @@ +package net.leaderos.shared.model.request.impl.store; + +import net.leaderos.shared.model.request.GetRequest; + +import java.io.IOException; + +public class ListingRequest extends GetRequest { + /** + * Request constructor + * + * @param api of request + * @throws IOException for HttpUrlConnection + */ + public ListingRequest() throws IOException { + super("store/listing"); + } +} diff --git a/shared/src/main/java/net/leaderos/shared/model/request/impl/user/GetUserRequest.java b/shared/src/main/java/net/leaderos/shared/model/request/impl/user/GetUserRequest.java new file mode 100644 index 000000000..cbd3bef25 --- /dev/null +++ b/shared/src/main/java/net/leaderos/shared/model/request/impl/user/GetUserRequest.java @@ -0,0 +1,13 @@ +package net.leaderos.shared.model.request.impl.user; + +import net.leaderos.shared.model.request.GetRequest; + +import java.io.IOException; + +public class GetUserRequest extends GetRequest { + + public GetUserRequest(String name) throws IOException { + super("users/" + name); + } + +} diff --git a/shared/src/main/java/net/leaderos/shared/modules/auth/AuthHelper.java b/shared/src/main/java/net/leaderos/shared/modules/auth/AuthHelper.java index 1542c94d9..90648532f 100644 --- a/shared/src/main/java/net/leaderos/shared/modules/auth/AuthHelper.java +++ b/shared/src/main/java/net/leaderos/shared/modules/auth/AuthHelper.java @@ -1,11 +1,9 @@ package net.leaderos.shared.modules.auth; -import net.leaderos.shared.model.request.PostRequest; +import net.leaderos.shared.model.request.impl.auth.AuthRequest; import org.json.JSONObject; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; import java.util.UUID; /** @@ -24,11 +22,8 @@ public class AuthHelper { * @throws IOException request exception */ private static String generateLink(String username, String uuid) throws IOException { - Map formData = new HashMap<>(); - formData.put("username", username); - formData.put("uuid", uuid); - PostRequest postRequest = new PostRequest("auth/generate-link", formData); - JSONObject response = postRequest.getResponse().getResponseMessage().getJSONObject("data"); + AuthRequest authRequest = new AuthRequest(username, uuid); + JSONObject response = authRequest.getResponse().getResponseMessage().getJSONObject("data"); return response.getString("url"); } diff --git a/shared/src/main/java/net/leaderos/shared/modules/credit/CreditHelper.java b/shared/src/main/java/net/leaderos/shared/modules/credit/CreditHelper.java index 6bea5fa0b..4bc51609e 100644 --- a/shared/src/main/java/net/leaderos/shared/modules/credit/CreditHelper.java +++ b/shared/src/main/java/net/leaderos/shared/modules/credit/CreditHelper.java @@ -3,11 +3,9 @@ import net.leaderos.shared.model.Response; import net.leaderos.shared.model.request.GetRequest; import net.leaderos.shared.model.request.PostRequest; +import net.leaderos.shared.model.request.impl.credit.*; import org.jetbrains.annotations.Nullable; -import java.util.HashMap; -import java.util.Map; - /** * Helper Class for auth module * @author poyrazinan @@ -25,10 +23,7 @@ public class CreditHelper { */ public static @Nullable Response sendCreditRequest(String sender, String target, Double amount) { try { - Map list = new HashMap<>(); - list.put("target", target); - list.put("amount", String.valueOf(amount)); - PostRequest postSendCredit = new PostRequest("credits/" + sender + "/send", list); + PostRequest postSendCredit = new SendCreditsRequest(sender, target, amount); return postSendCredit.getResponse(); } catch (Exception e) { @@ -43,7 +38,7 @@ public class CreditHelper { */ public static @Nullable Response getRequest(String sender) { try { - GetRequest getCurrency = new GetRequest("credits/" + sender); + GetRequest getCurrency = new GetCreditsRequest(sender); return getCurrency.getResponse(); } catch (Exception e) { @@ -59,9 +54,7 @@ public class CreditHelper { */ public static @Nullable Response addCreditRequest(String target, double amount) { try { - Map list = new HashMap<>(); - list.put("amount", String.valueOf(amount)); - PostRequest postAddCredit = new PostRequest("credits/" + target + "/add", list); + PostRequest postAddCredit = new AddCreditsRequest(target, amount); return postAddCredit.getResponse(); } catch (Exception e) { @@ -77,9 +70,7 @@ public class CreditHelper { */ public static @Nullable Response removeCreditRequest(String target, double amount) { try { - Map list = new HashMap<>(); - list.put("amount", String.valueOf(amount)); - PostRequest postRemoveCredit = new PostRequest("credits/" + target + "/remove", list); + PostRequest postRemoveCredit = new RemoveCreditsRequest("credits/" + target + "/remove", amount); return postRemoveCredit.getResponse(); } catch (Exception e) { @@ -95,9 +86,7 @@ public class CreditHelper { */ public static @Nullable Response setCreditRequest(String target, double amount) { try { - Map list = new HashMap<>(); - list.put("amount", String.valueOf(amount)); - PostRequest postSetCredit = new PostRequest("credits/" + target + "/set", list); + PostRequest postSetCredit = new SetCreditsRequest("credits/" + target + "/set", amount); return postSetCredit.getResponse(); } catch (Exception e) { diff --git a/shared/src/main/java/net/leaderos/shared/modules/discord/DiscordHelper.java b/shared/src/main/java/net/leaderos/shared/modules/discord/DiscordHelper.java index af33fd499..d0f3c1f56 100644 --- a/shared/src/main/java/net/leaderos/shared/modules/discord/DiscordHelper.java +++ b/shared/src/main/java/net/leaderos/shared/modules/discord/DiscordHelper.java @@ -1,11 +1,10 @@ package net.leaderos.shared.modules.discord; import net.leaderos.shared.model.request.PostRequest; +import net.leaderos.shared.model.request.impl.discord.DiscordSyncRequest; import org.json.JSONObject; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; /** * Auth module helper class, share methods over platforms @@ -22,9 +21,7 @@ public class DiscordHelper { * @throws IOException request exception */ private static String generateLink(String username) throws IOException { - Map formData = new HashMap<>(); - formData.put("user", username); - PostRequest postRequest = new PostRequest("integrations/discord/sync", formData); + PostRequest postRequest = new DiscordSyncRequest(username); JSONObject response = postRequest.getResponse().getResponseMessage().getJSONObject("data"); return response.getString("url"); }