add TradingDeal /tradings

This commit is contained in:
Georg Reisinger 2020-12-30 15:03:30 +01:00
parent 0df6ff129e
commit 7b2ecd3bf0
3 changed files with 57 additions and 16 deletions

View File

@ -39,6 +39,16 @@ public class DBConnection {
PostgresHelper.executeUpdateMessage("create table IF NOT EXISTS trading(username text not null constraint trading_users_username_fk references users,id text not null constraint trading_pk primary key, cardtotrade text not null constraint trading_card_name_fk references card, mindamage float not null,reqcardtype text not null,reqelement text not null);", "Trading Table created");
}
/**
* Updated den Lock einer user card
* @param name Name der Card
* @param lock Zustand des Locks
* @return true bei erfolg, sonst false
*/
public boolean updateCardLock(String name, boolean lock){
return PostgresHelper.executeUpdate("Update user_cards set gesperrt = " + lock + " where name = \'" + name + "\';");
}
/**
* Fügt der DB einen Trading deal hinzu
* @param username User der den Trade hinzufügt
@ -457,6 +467,7 @@ public class DBConnection {
* @return Null bei error
*/
public Card getCardFromID(String id){
System.out.println(id);
Connection b = PostgresHelper.con();
Card toreturn = null;
try {

View File

@ -54,6 +54,22 @@ public class TradingDeal {
this(id, cardToTrade, EnumHelper.stringToElementType(type), requiredMinDamage, EnumHelper.stringToCardType(type), username);
}
/**
* Holt die ID des Trading deals
* @return Id des Trading Deals
*/
public String getId() {
return id;
}
/**
* Setzt die id des TradingDeals
* @param id Id des TradingDeals
*/
public void setId(String id) {
this.id = id;
}
/**
* Holt den usernamen
* @return Der username als String

View File

@ -262,36 +262,50 @@ public class Response {
String id = (String)map.get("Id");
String cardtotrade = (String)map.get("CardToTrade");
String type = (String)map.get("Type");
double mindamage = (double)map.get("MinimumDamage");
ArrayList<String> cardname = new ArrayList<String>();
cardname.add(cardtotrade);
Cards cards = new DBConnection().getCardsFromIDList(cardname);
Card cardtoTradeC = null;
if (cards != null){
cardtoTradeC = cards.getCards().get(0);
if (cardtoTradeC != null){
TradingDeal tradingDeal = new TradingDeal(id, cardtoTradeC, mindamage, type, basicAuthGetUsername(this.authString));
if (tradingDeal != null){
double mindamage = Double.parseDouble(map.get("MinimumDamage") + "");
String username = basicAuthGetUsername(this.authString);
if (username != null) {
Card cardtoTradeC = new DBConnection().getCardFromID(cardtotrade);
System.out.println("CARD TO TRAD: " + cardtoTradeC.getName());
if (cardtoTradeC != null) {
TradingDeal tradingDeal = new TradingDeal(id, cardtoTradeC, mindamage, type, username);
if (tradingDeal != null) {
String tradingJson = JsonHelper.objToJson(tradingDeal);
if (tradingDeal != null){
if (tradingDeal != null) {
//DB Trading deal add
// Lock Card for deck
//Wenn card im deck, dann del aus deck
//Wenn card im deck, dann del aus deck
//new DBConnection().;
ArrayList<String> deckCards = new DBConnection().getDeck(username);
if (deckCards != null) {
if (deckCards.contains(cardtotrade)) {
new DBConnection().delDeck(username);
}
if(new DBConnection().addTradingdeal(tradingDeal.getUsername(), tradingDeal.getId(), tradingDeal.getRequiredMinDamage(), tradingDeal.getRequiredCardType().name(), tradingDeal.getRequiredElementType().name(), tradingDeal.getCardToTrade().getName())){
if(new DBConnection().updateCardLock(tradingDeal.getUsername(), true)){
sendResponse(JsonHelper.objToJson(tradingDeal), "201");
}else{
sendError("500");
}
}else{
sendError("500");
}
} else {
sendError("500");
}
sendResponse(tradingJson, "201");
}else{
} else {
sendError("500");
}
}else{
} else {
sendError("500");
}
}else {
} else {
sendError("500");
}
}else{
sendError("500");
}
}else{
sendError("401");
}