From 8e44e37804ff7ece5389d9f974ff20232693267f Mon Sep 17 00:00:00 2001 From: Georg Reisinger Date: Wed, 30 Dec 2020 15:30:50 +0100 Subject: [PATCH] delTradingDeal + unlock card --- src/main/java/at/reisinger/DBConnection.java | 10 +++++++- .../at/reisinger/server/objects/Response.java | 23 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/java/at/reisinger/DBConnection.java b/src/main/java/at/reisinger/DBConnection.java index 24cceef..b0201aa 100644 --- a/src/main/java/at/reisinger/DBConnection.java +++ b/src/main/java/at/reisinger/DBConnection.java @@ -46,10 +46,18 @@ public class DBConnection { * @return true bei erfolg, sonst false */ public boolean updateCardLock(String name, boolean lock){ - System.out.println("Update user_cards set gesperrt = " + lock + " where name = \'" + name + "\';"); return PostgresHelper.executeUpdate("Update user_cards set gesperrt = " + lock + " where name = \'" + name + "\';"); } + /** + * Löscht einen Trading Deal aus der Datenbank + * @param id Id des deals der gelöscht werden soll + * @return True bei erfolg, sonst false + */ + public boolean deleteTradingDeal(String id){ + return PostgresHelper.executeUpdate("delete from trading where id = \'" + id + "\';"); + } + /** * Fügt der DB einen Trading deal hinzu * @param username User der den Trade hinzufügt diff --git a/src/main/java/at/reisinger/server/objects/Response.java b/src/main/java/at/reisinger/server/objects/Response.java index 717dd5e..783b72c 100644 --- a/src/main/java/at/reisinger/server/objects/Response.java +++ b/src/main/java/at/reisinger/server/objects/Response.java @@ -405,7 +405,28 @@ public class Response { * @throws JsonProcessingException Fehler beim de-/serialisieren */ private void deleteMethodes(){ - if (this.url.startsWith("/messages")) { + if (this.url.startsWith("/tradings")) { + String tradeid = this.url.substring(this.url.lastIndexOf('/') + 1); + System.out.println("Format in /tradings/{tradingid}: " + tradeid); + ArrayList allTradingDeals = new DBConnection().getAllTradingDeals(); + TradingDeal tr = null; + if (allTradingDeals != null && !allTradingDeals.isEmpty()) { + for (TradingDeal i : allTradingDeals) { + if (i.getId().equals(tradeid)) { + tr = i; + } + } + if (tr != null) { + if (new DBConnection().deleteTradingDeal(tradeid)) { + if (new DBConnection().updateCardLock(tr.getCardToTrade().getName(), false)) + sendResponse("", "204"); + } else { + sendError("500"); + } + }else{ + sendError("500"); + } + } } }