delTradingDeal + unlock card

This commit is contained in:
Georg Reisinger 2020-12-30 15:30:50 +01:00
parent 3e8003ab50
commit 8e44e37804
2 changed files with 31 additions and 2 deletions

View File

@ -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

View File

@ -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<TradingDeal> 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");
}
}
}
}