diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4867bb4
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,26 @@
+# Compiled class file
+*.class
+
+# Log file
+*.log
+
+# BlueJ files
+*.ctxt
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# at.reisinger.Package Files #
+*.jar
+*.war
+*.nar
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+.idea/compiler.xml
+*.lst
+.idea/
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
deleted file mode 100644
index 4e3ecef..0000000
--- a/.idea/compiler.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
index 3d0d7a4..8ef490b 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,2 @@
# SWE1-MTCG
-Monster Trading Card Game
+Monster Trading at.reisinger.Card Game
diff --git a/pom.xml b/pom.xml
index 493c880..b62cfc7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,6 +7,41 @@
at.reisinger.mtcg
MTCG
1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 11
+ 11
+
+
+
+
+
+
+ org.junit.jupiter
+ junit-jupiter
+ RELEASE
+ test
+
+
+ org.mockito
+ mockito-core
+ 3.5.13
+
+
+ org.mockito
+ mockito-junit-jupiter
+ 3.5.13
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.11.2
+
+
\ No newline at end of file
diff --git a/src/main/java/at/reisinger/Battle.java b/src/main/java/at/reisinger/Battle.java
new file mode 100644
index 0000000..d43bbce
--- /dev/null
+++ b/src/main/java/at/reisinger/Battle.java
@@ -0,0 +1,4 @@
+package at.reisinger;
+
+public class Battle {
+}
diff --git a/src/main/java/at/reisinger/Card.java b/src/main/java/at/reisinger/Card.java
new file mode 100644
index 0000000..e3197d0
--- /dev/null
+++ b/src/main/java/at/reisinger/Card.java
@@ -0,0 +1,120 @@
+package at.reisinger;
+
+/**
+ * Object einer at.reisinger.Card
+ */
+public class Card {
+ private String name;
+ private double damage;
+ private ElementTyp elementTyp;
+ private CardType cardType;
+
+ /**
+ * Erstellt eine neue at.reisinger.Card mit gegebenen Eigenschaften
+ * @param name Name der at.reisinger.Card
+ * @param damage Damage den die at.reisinger.Card macht
+ * @param elementTyp ElementType der at.reisinger.Card
+ * @param cardType at.reisinger.CardType der at.reisinger.Card
+ */
+ public Card(String name, double damage, ElementTyp elementTyp, CardType cardType) {
+ this.name = name;
+ this.damage = damage;
+ this.elementTyp = elementTyp;
+ this.cardType = cardType;
+ }
+
+ /**
+ * Holt den Namen der at.reisinger.Card
+ * @return Name der at.reisinger.Card
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * Holt den Damage der at.reisinger.Card
+ * @return Damage der at.reisinger.Card
+ */
+ public double getDamage() {
+ return this.damage;
+ }
+
+ /**
+ * Holt den ElementType der at.reisinger.Card
+ * @return ElementType der at.reisinger.Card
+ */
+ public ElementTyp getElementTyp() {
+ return this.elementTyp;
+ }
+
+ /**
+ * Holt den at.reisinger.CardType der at.reisinger.Card
+ * @return at.reisinger.CardType der at.reisinger.Card
+ */
+ public CardType getCardType() {
+ return this.cardType;
+ }
+
+ /**
+ * Berechnet die Wirksamkeit gegen eine Andere card. Die at.reisinger.Card im Parameter wird angegriffen
+ * @param toCeck at.reisinger.Card gegen welche die Wirksamkeit geprüft werden soll
+ * @return Gibt die Wirksamkeit zurück
+ * @throws InternalError Wenn die Effectifeness von den 2 at.reisinger.Cards nicht berechnet werden kann
+ */
+ public EffectivnessType getEffectivenessAgainst(Card toCeck) {
+ if(toCeck.getCardType() == CardType.MONSTER){
+ if(this.cardType == CardType.MONSTER){
+ return EffectivnessType.NOEFFECT;
+ }else if (this.cardType == CardType.SPELL){
+
+ }
+ }else if (toCeck.getCardType() == CardType.SPELL){
+ if ((toCeck.getElementTyp() == ElementTyp.FIRE && this.elementTyp == ElementTyp.WATER) || (toCeck.getElementTyp() == ElementTyp.NORMAL && this.elementTyp == ElementTyp.FIRE) || (toCeck.getElementTyp() == ElementTyp.WATER && this.elementTyp == ElementTyp.NORMAL)){
+ return EffectivnessType.EFFECTIVE;
+ }else if (this.elementTyp == ElementTyp.FIRE && toCeck.getElementTyp() == ElementTyp.WATER){
+ return EffectivnessType.NOTEFFECTIVE;
+ }else if ((toCeck.getElementTyp() == ElementTyp.NORMAL && this.cardType == CardType.MONSTER && this.elementTyp == ElementTyp.NORMAL)){
+ return EffectivnessType.NOEFFECT;
+ }
+ }
+ throw new InternalError("Konnte die Effectiveness von den at.reisinger.Cards nicht berechnen");
+ }
+
+ /**
+ * Setztden namen der at.reisinger.Card
+ * @param neuerName Name der at.reisinger.Card
+ */
+ public void setName(String neuerName) {
+ this.name = neuerName;
+ }
+
+ /**
+ * Setzt den Damage der at.reisinger.Card
+ * @param damage Der Damage
+ */
+ public void setDamage(int damage) {
+ this.damage = damage;
+ }
+
+ /**
+ * Setzt den ElementType der at.reisinger.Card
+ * @param elementTyp Der ElementType
+ */
+ public void setElementType(ElementTyp elementTyp) {
+ this.elementTyp = elementTyp;
+ }
+
+ /**
+ * Testet ob die beiden Karten gleich sind
+ * @param card at.reisinger.Card die geprüft werden soll
+ * @return True wenn die Karten übereinstimmen
+ */
+ public boolean equals(Card card){
+ if(card == null) return false;
+ if(this.name == card.getName() && this.cardType == card.getCardType() && this.elementTyp == card.getElementTyp() && this.damage == card.getDamage()){
+ return true;
+ }else {
+ return false;
+ }
+ }
+}
diff --git a/src/main/java/at/reisinger/CardType.java b/src/main/java/at/reisinger/CardType.java
new file mode 100644
index 0000000..8c5016f
--- /dev/null
+++ b/src/main/java/at/reisinger/CardType.java
@@ -0,0 +1,5 @@
+package at.reisinger;
+
+public enum CardType {
+ MONSTER, SPELL
+}
diff --git a/src/main/java/at/reisinger/Cards.java b/src/main/java/at/reisinger/Cards.java
new file mode 100644
index 0000000..1d7a78d
--- /dev/null
+++ b/src/main/java/at/reisinger/Cards.java
@@ -0,0 +1,79 @@
+package at.reisinger;
+
+import java.util.ArrayList;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Verwaltet eine Liste vo at.reisinger.Cards
+ */
+public class Cards {
+ private ArrayList cards;
+
+ /**
+ * Erstellt ein nues obj mit gegebenen Karten
+ * @param cardsArrayList Die at.reisinger.Cards zum erstellen des Obj
+ */
+ public Cards(ArrayList cardsArrayList) {
+ this.cards = cardsArrayList;
+ }
+
+
+
+ /**
+ * Fügt eine neue at.reisinger.Card hinzu
+ * @param newCard neue at.reisinger.Card
+ */
+ public void addCard(Card newCard) {
+ this.cards.add(newCard);
+ }
+
+ /**
+ * Holt alle at.reisinger.Cards
+ * @return Alle at.reisinger.Cards
+ */
+ public ArrayList getCards() {
+ return this.cards;
+ }
+
+ /**
+ * Löscht die gegebene at.reisinger.Card
+ * @param delCard at.reisinger.Card zum löschen
+ */
+ public void delCard(Card delCard) {
+ this.cards.removeIf(obj -> obj.equals(delCard));
+ }
+
+ /**
+ * Prüft ob eine at.reisinger.Card in den at.reisinger.Cards vorhanden ist
+ * @param toCeck at.reisinger.Card nach der in den at.reisinger.Cards gesucht werden soll
+ * @return True wenn die at.reisinger.Card in den at.reisinger.Cards ist
+ */
+ public boolean containsCard(Card toCeck){
+ AtomicBoolean returnval = new AtomicBoolean(false);
+ this.cards.forEach(item -> {
+ if(item.getElementTyp().equals(toCeck.getElementTyp()) && item.getCardType().equals(toCeck.getCardType()) && item.getName().equals(toCeck.getName()) && item.getDamage() == toCeck.getDamage()){
+ returnval.set(true);
+ }else{
+ returnval.set(false);
+ }
+ });
+ return returnval.get();
+ }
+
+ /**
+ * Vergleicht 2 at.reisinger.Cards Obj miteinander
+ * @param toCompare at.reisinger.Cards zum vergleichen
+ * @return True wenn es aus den selben at.reisinger.Cards besteht
+ */
+ public boolean equals(Cards toCompare){
+ if (this.cards == null && toCompare.getCards() == null){
+ return true;
+ }else if ((this.cards == null && toCompare.getCards() != null) || (this.cards != null && toCompare.getCards() == null)){
+ return false;
+ }else if(this.cards.containsAll(toCompare.getCards()) && toCompare.getCards().containsAll(this.cards)){
+ return true;
+ }else {
+ return false;
+ }
+ }
+}
diff --git a/src/main/java/at/reisinger/Coins.java b/src/main/java/at/reisinger/Coins.java
new file mode 100644
index 0000000..abd2a5b
--- /dev/null
+++ b/src/main/java/at/reisinger/Coins.java
@@ -0,0 +1,67 @@
+package at.reisinger;
+
+/**
+ * Alle coins eines Users
+ */
+public class Coins {
+ private int amount;
+
+ /**
+ * Erstellt ein neues Münzen Obj
+ * @param coins Alle münzen des Users
+ */
+ public Coins(int coins) {
+ this.amount = coins;
+ }
+
+ /**
+ * Holt alle münzen
+ * @return Alle münzen
+ */
+ public int getCoinAmount() {
+ return this.amount;
+ }
+
+ /**
+ * Fügt münzen hinzu
+ * @param coins Münzen die hinzugefügt werden -> Positiv
+ * @throws NegativAmountException Wenn negative münzen hinzugefüght werden
+ */
+ public void addCoin(int coins) throws NegativAmountException{
+ if(coins < 0) {
+ throw new NegativAmountException("Es kann kein negativer amount an at.reisinger.Coins hinzugefügt werden");
+ }else {
+ this.amount += coins;
+ }
+ }
+
+ /**
+ * Entfernt münzen
+ * @param coins Münzen die entfernt werden sollen, muss positiv sein
+ * @return True wenn erfolgreich
+ * @throws NegativAmountException Wenn ein negativer betrag abgezogen werden soll
+ */
+ public boolean removeCoin(int coins) throws NegativAmountException{
+ if(coins < 0) {
+ throw new NegativAmountException("Es kann kein negativer amount an at.reisinger.Coins hinzugefügt werden");
+ }else {
+ this.amount -= coins;
+ return true;
+ }
+ }
+
+ /**
+ * Ändert den Absoluten Coin amount
+ * @param coins Neue Coin anzahl, muss positiv sein
+ * @return true wenn erfolgreich
+ * @throws NegativAmountException Wenn ein negativer wert eingegeben wird
+ */
+ public boolean changeCoinAmmount(int coins) throws NegativAmountException{
+ if(coins < 0) {
+ throw new NegativAmountException("Es kann kein negativer amount an at.reisinger.Coins hinzugefügt werden");
+ }else {
+ this.amount = coins;
+ return true;
+ }
+ }
+}
diff --git a/src/main/java/at/reisinger/Credentials.java b/src/main/java/at/reisinger/Credentials.java
new file mode 100644
index 0000000..ebbb97d
--- /dev/null
+++ b/src/main/java/at/reisinger/Credentials.java
@@ -0,0 +1,50 @@
+package at.reisinger;
+
+/**
+ * at.reisinger.User Login Daten
+ */
+public class Credentials {
+ private String passwort, username;
+
+ /**
+ * Startet einen neuen at.reisinger.User mit folgenden Daten
+ * @param username Diesem Usernamen
+ * @param passwort Diesem Passwort
+ */
+ public Credentials(String username, String passwort){
+ this.username = username;
+ this.passwort = passwort;
+ }
+
+ /**
+ * Holt das Passwort des users
+ * @return PW des Users
+ */
+ public String getPasswort() {
+ return passwort;
+ }
+
+// /**
+// * Setzt das at.reisinger.User Passwort
+// * @param passwort Neues Passwort
+// */
+// public void setPasswort(String passwort) {
+// this.passwort = passwort;
+// }
+
+ /**
+ * Holt den Usernamen des Users
+ * @return Username
+ */
+ public String getUsername() {
+ return username;
+ }
+
+// /**
+// * Setzt einen neuen Usernamen
+// * @param username Neuer Username
+// */
+// public void setUsername(String username) {
+// this.username = username;
+// }
+}
diff --git a/src/main/java/at/reisinger/DBConnection.java b/src/main/java/at/reisinger/DBConnection.java
new file mode 100644
index 0000000..374cab1
--- /dev/null
+++ b/src/main/java/at/reisinger/DBConnection.java
@@ -0,0 +1,137 @@
+package at.reisinger;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+
+/**
+ * Stellt die Verbindung zur "Datenbank" her
+ * Die "Datenbank" sind hier nur beispieldaten.
+ */
+public class DBConnection {
+ private ArrayList tradingDeals;
+ private ArrayList packages;
+ private Connection c;
+ private Statement stmt;
+
+ private Connection con(){
+ this.c = null;
+ try {
+ Class.forName("org.postgresql.Driver");
+ this.c = DriverManager
+ .getConnection("jdbc:postgresql://postgres.dergeorg.at:5432/mtcg",
+ "user", "user");
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.err.println(e.getClass().getName()+": "+e.getMessage());
+ System.exit(0);
+ }
+ System.out.println("Opened database");
+ return c;
+ }
+
+ /**
+ * Erstellt alle Beispieldaten und simuliert somit den
+ * Verbindungsaufbau zu einer DB
+ */
+ public DBConnection(){
+ this.c = con();
+ System.out.println("Create Tables start");
+ try {
+ createTables();
+ } catch (SQLException throwables) {
+ throwables.printStackTrace();
+ }
+ /*
+ Card c1 = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER);
+ Card c2 = new Card("Name1", 12, ElementTyp.FIRE, CardType.SPELL);
+ Card c3 = new Card("Name2", 13, ElementTyp.WATER, CardType.MONSTER);
+ Card c4 = new Card("Name3", 14, ElementTyp.WATER, CardType.SPELL);
+ Card c5 = new Card("Name4", 15, ElementTyp.FIRE, CardType.MONSTER);
+ ArrayList deckArrList = new ArrayList();
+ ArrayList stackArrList = new ArrayList();
+ deckArrList.add(c1);
+ deckArrList.add(c2);
+ stackArrList.add(c3);
+ stackArrList.add(c4);
+ stackArrList.add(c5);
+ Cards deck = new Cards(deckArrList);
+ Cards stack = new Cards(stackArrList);
+ User user = new User(new Credentials("username", "passwort"), "Name", "Nachname", "Email", new Stack(stack, deck), new Coins(1000));
+ this.tradingDeals = new ArrayList();
+ this.packages = new ArrayList();
+ this.tradingDeals.add(new TradingDeal(user, c1, ElementTyp.FIRE, 10, CardType.MONSTER));
+ this.packages.add(new Package(stack, "Test at.reisinger.Package", 100));
+ */
+ }
+
+ private void createTables() throws SQLException {
+ this.c = con();
+ try{
+ stmt = this.c.createStatement();
+ String sql = "CREATE TABLE IF NOT EXISTS USERS " +
+ "(username TEXT PRIMARY KEY NOT NULL," +
+ " nachname TEXT NOT NULL, " +
+ " email TEXT NOT NULL, " +
+ " password TEXT NOT NULL)";
+ stmt.executeUpdate(sql);
+ stmt.close();
+ this.c.close();
+ } catch ( Exception e ) {
+ System.err.println( e.getClass().getName()+": "+ e.getMessage() );
+ System.exit(0);
+ }
+ System.out.println("User Table created");
+ }
+
+ public boolean addUser(String username, String password, String nachname, String email){
+ this.c = con();
+ try{
+ stmt = this.c.createStatement();
+ String sql = "INSERT INTO users (username, nachname, email, password) values (\'" + username +"\',\'" + nachname + "\',\'" + email + "\',\'" + password + "\')";
+ System.out.println(sql);
+ stmt.executeUpdate(sql);
+ stmt.close();
+ this.c.close();
+ } catch ( Exception e ) {
+ System.err.println( e.getClass().getName()+": "+ e.getMessage() );
+ return false;
+ }
+ System.out.println("User added");
+ return true;
+ }
+
+ /**
+ * Holt alle verfügbaren TradingDeals
+ * @return Alle Trading Deals
+ */
+ public ArrayList getAllTradingDeals(){
+ return this.tradingDeals;
+ }
+
+ /**
+ * Holt alle verfügbaren Packages
+ * @return Alle Packages
+ */
+ public ArrayList getAllPackages(){
+ return this.packages;
+ }
+
+ /**
+ * Fügt einen neuen Tradingdeal zum at.reisinger.Store hinzu
+ * @param tradingDeal Der neue Deal
+ */
+ public void addTradingDeal(TradingDeal tradingDeal){
+ this.tradingDeals.add(tradingDeal);
+ }
+
+// /**
+// * Fügt ein neues at.reisinger.Package zu dem at.reisinger.Store hinzu
+// * @param packageDeal Das neue at.reisinger.Package
+// */
+// public void addPackage(at.reisinger.Package packageDeal){
+// this.packages.add(packageDeal);
+// }
+}
diff --git a/src/main/java/at/reisinger/EffectivnessType.java b/src/main/java/at/reisinger/EffectivnessType.java
new file mode 100644
index 0000000..62421a1
--- /dev/null
+++ b/src/main/java/at/reisinger/EffectivnessType.java
@@ -0,0 +1,7 @@
+package at.reisinger;
+
+public enum EffectivnessType {
+ EFFECTIVE,
+ NOTEFFECTIVE,
+ NOEFFECT
+}
diff --git a/src/main/java/at/reisinger/ElementTyp.java b/src/main/java/at/reisinger/ElementTyp.java
new file mode 100644
index 0000000..b916e84
--- /dev/null
+++ b/src/main/java/at/reisinger/ElementTyp.java
@@ -0,0 +1,5 @@
+package at.reisinger;
+
+public enum ElementTyp {
+ WATER, FIRE, NORMAL
+}
diff --git a/src/main/java/at/reisinger/MonsterCard.java b/src/main/java/at/reisinger/MonsterCard.java
new file mode 100644
index 0000000..c1ffc83
--- /dev/null
+++ b/src/main/java/at/reisinger/MonsterCard.java
@@ -0,0 +1,7 @@
+package at.reisinger;
+
+public class MonsterCard extends Card{
+ public MonsterCard(String name, double damage, ElementTyp elementTyp, CardType cardType) {
+ super(name, damage, elementTyp, cardType);
+ }
+}
diff --git a/src/main/java/at/reisinger/NegativAmountException.java b/src/main/java/at/reisinger/NegativAmountException.java
new file mode 100644
index 0000000..0405378
--- /dev/null
+++ b/src/main/java/at/reisinger/NegativAmountException.java
@@ -0,0 +1,17 @@
+package at.reisinger;
+
+/**
+ * Wenn ein negativer wert eingegeben wird aber ein Positiver erwartet wird, dann kann diese Exception geworfen werden
+ */
+public class NegativAmountException extends Exception {
+
+ /**
+ * Aufruf des Constructors der Super class Exception
+ * @param message Fehler Nachrichgt
+ * @param cause Fehler Ursache
+ */
+ public NegativAmountException(String message){
+ super(message);
+ }
+
+}
diff --git a/src/main/java/at/reisinger/Package.java b/src/main/java/at/reisinger/Package.java
new file mode 100644
index 0000000..f00de77
--- /dev/null
+++ b/src/main/java/at/reisinger/Package.java
@@ -0,0 +1,45 @@
+package at.reisinger;
+
+/**
+ * at.reisinger.Package besteht aus 4 Karten. Ist eine Erweiterung der at.reisinger.Cards, zeigt für 4 at.reisinger.Cards den Preis und einen Packagenamen an
+ */
+public class Package extends Cards{
+ private String name;
+ private int price;
+
+ /**
+ * Erstellt ein neues at.reisinger.Package mit den gegebenen Stats
+ * @param stack at.reisinger.Cards des Packages
+ * @param name Name des Packages
+ * @param price Price des Packages
+ */
+ public Package(Cards stack, String name, int price) {
+ super(stack.getCards());
+ this.name = name;
+ this.price = price;
+ }
+
+ /**
+ * Holt den namen des Packages
+ * @return Name des Packages
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * Holt den Preis des Packages
+ * @return Preis des Packages
+ */
+ public int getPrice() {
+ return this.price;
+ }
+
+ /**
+ * Setzt den Namen des Packages
+ * @param neuName Neuer name des Packages
+ */
+ public void setName(String neuName) {
+ this.name = neuName;
+ }
+}
diff --git a/src/main/java/at/reisinger/SpellCard.java b/src/main/java/at/reisinger/SpellCard.java
new file mode 100644
index 0000000..f9f9881
--- /dev/null
+++ b/src/main/java/at/reisinger/SpellCard.java
@@ -0,0 +1,7 @@
+package at.reisinger;
+
+public class SpellCard extends Card{
+ public SpellCard(String name, double damage, ElementTyp elementTyp, CardType cardType) {
+ super(name, damage, elementTyp, cardType);
+ }
+}
diff --git a/src/main/java/at/reisinger/Stack.java b/src/main/java/at/reisinger/Stack.java
new file mode 100644
index 0000000..eab8633
--- /dev/null
+++ b/src/main/java/at/reisinger/Stack.java
@@ -0,0 +1,50 @@
+package at.reisinger;
+
+/**
+ * Erweitert at.reisinger.Cards insofern, dass es im at.reisinger.Stack auch ein Deck gibt
+ */
+public class Stack extends Cards{
+ private Cards deck;
+
+ /**
+ * Erstellt einen neuen at.reisinger.Stack aus den at.reisinger.User at.reisinger.Cards und seinem Deck
+ * @param cards Alle at.reisinger.Cards des Users
+ * @param deck Sein Deck
+ */
+ public Stack(Cards cards, Cards deck) {
+ super(cards.getCards());
+ this.deck = deck;
+ }
+
+ /**
+ * Fügt ein neues Deck in den at.reisinger.Stack ein
+ * @param newCards Gesamtes Deck
+ */
+ public void addDeck(Cards newCards) {
+ this.deck = newCards;
+ }
+
+ /**
+ * Holt das gesamte Deck
+ * @return Gesamtes Deck
+ */
+ public Cards getDeck() {
+ return this.deck;
+ }
+
+ /**
+ * Löscht eine at.reisinger.Card aus dem Deck
+ * @param toDel at.reisinger.Card zum löschen
+ */
+ public void delDeck(Card toDel) {
+ this.deck.delCard(toDel);
+ }
+
+// /**
+// * Fügt dem deck eine neue at.reisinger.Card ein
+// * @param toAdd Neue at.reisinger.Card
+// */
+// public void addDeckCard(at.reisinger.Card toAdd){
+// this.deck.addCard(toAdd);
+// }
+}
diff --git a/src/main/java/at/reisinger/Store.java b/src/main/java/at/reisinger/Store.java
new file mode 100644
index 0000000..069c79d
--- /dev/null
+++ b/src/main/java/at/reisinger/Store.java
@@ -0,0 +1,15 @@
+package at.reisinger;
+
+import java.util.ArrayList;
+
+public interface Store {
+ DBConnection db = new DBConnection();
+
+ void addTradingDeal(TradingDeal tradingDeal);
+
+ ArrayList getTradingDeals();
+
+ boolean doTrading(TradingDeal tradingDeal1, TradingDeal tradingDeal2);
+
+ ArrayList getPossibleTradingDeals(Card toTrade);
+}
diff --git a/src/main/java/at/reisinger/TradingDeal.java b/src/main/java/at/reisinger/TradingDeal.java
new file mode 100644
index 0000000..8c79b18
--- /dev/null
+++ b/src/main/java/at/reisinger/TradingDeal.java
@@ -0,0 +1,143 @@
+package at.reisinger;
+
+/**
+ * Ein einzelner Trading deal wird hier verwaltet.
+ */
+public class TradingDeal {
+ //private User tradingUser;
+ private Card cardToTrade;
+ private ElementTyp requiredElementType;
+ private double requiredMinDamage;
+ private CardType requiredCardType;
+
+ /**
+ * Ein at.reisinger.TradingDeal wird erstellt
+ * @param user at.reisinger.User des Deals
+ * @param cardToTrade at.reisinger.Card die getauscht werden soll
+ * @param requiredElementType Req ElementType für den Tausch
+ * @param requiredMinDamage Req min damage für den Tausch
+ * @param requiredCardType Req at.reisinger.Card Type für den Tausch
+ */
+ public TradingDeal(User user, Card cardToTrade, ElementTyp requiredElementType, double requiredMinDamage, CardType requiredCardType) {
+ //this.tradingUser = user;
+ this.cardToTrade = cardToTrade;
+ this.requiredElementType = requiredElementType;
+ this.requiredMinDamage = requiredMinDamage;
+ this.requiredCardType = requiredCardType;
+ }
+
+ /**
+ * Holt den Trading at.reisinger.User
+ * @return at.reisinger.User der den Trade erstellt hat
+
+ public User getTradingUser() {
+ return this.tradingUser;
+ }
+*/
+ /**
+ * at.reisinger.Card die getraded werden soll
+ * @return at.reisinger.Card die getradet werden soll
+ */
+ public Card getCardToTrade() {
+ return this.cardToTrade;
+ }
+
+ /**
+ * Req Element type holen
+ * @return Req Element Type
+ */
+ public ElementTyp getRequiredElementType() {
+ return this.requiredElementType;
+ }
+
+ /**
+ * Req min damage holen
+ * @return Req min damage
+ */
+ public double getRequiredMinDamage() {
+ return this.requiredMinDamage;
+ }
+
+ /**
+ * Hole req cardtype
+ * @return Req at.reisinger.CardType
+ */
+ public CardType getRequiredCardType() {
+ return this.requiredCardType;
+ }
+
+ /**
+ * Setzt den at.reisinger.User des Trades
+ * @param tradingUser at.reisinger.User der Traded
+
+ public void setTradingUser(User tradingUser) {
+ this.tradingUser = tradingUser;
+ }
+*/
+ /**
+ * Setzt die Karte die Getradet werden soll
+ * @param cardToTrade at.reisinger.Card zum tauschen
+ */
+ public void setCardToTrade(Card cardToTrade) {
+ this.cardToTrade = cardToTrade;
+ }
+
+ /**
+ * Setzt req elementType
+ * @param requiredElementType Der Req elementType
+ */
+ public void setRequiredElementType(ElementTyp requiredElementType) {
+ this.requiredElementType = requiredElementType;
+ }
+
+ /**
+ * Setzt die req Min damage
+ * @param requiredMinDamage Die req min gamage
+ */
+ public void setRequiredMinDamage(double requiredMinDamage) {
+ this.requiredMinDamage = requiredMinDamage;
+ }
+
+ /**
+ * Setzt req cardType
+ * @param requiredCardType Der Req at.reisinger.CardType
+ */
+ public void setRequiredCardType(CardType requiredCardType) {
+ this.requiredCardType = requiredCardType;
+ }
+
+ /**
+ * Vom deal im Parameter wird die at.reisinger.Card mit den Requirements von THIS verglichen
+ * @param checkDeal Von diesem Deal wird die CardToTrade geprüft
+ * @return True wenn der Deal passt
+ */
+ public boolean dealOk(TradingDeal checkDeal){
+ return this.cardOk(checkDeal.getCardToTrade());
+ }
+
+ /**
+ * Von der at.reisinger.Card im Parameter wird die at.reisinger.Card mit den Requirements von THIS verglichen
+ * @param checkCard at.reisinger.Card die mit dem Deal verglichen wird
+ * @return True wenn der Deal passt
+ */
+ public boolean cardOk(Card checkCard){
+ System.out.println(checkCard.getCardType().equals(this.requiredCardType));
+ System.out.println(checkCard.getCardType().toString());
+ System.out.println(this.requiredCardType.toString());
+ System.out.println(" ");
+ System.out.println(checkCard.getElementTyp().equals(this.requiredElementType));
+ System.out.println(checkCard.getElementTyp().toString());
+ System.out.println(this.requiredElementType);
+ System.out.println(" ");
+ System.out.println(checkCard.getDamage() >= this.requiredMinDamage);
+ System.out.println(checkCard.getDamage());
+ System.out.println(this.requiredMinDamage);
+ if(checkCard.getCardType().equals(this.requiredCardType) && checkCard.getElementTyp().equals(this.requiredElementType) && checkCard.getDamage() >= this.requiredMinDamage){
+ System.out.println("Da simma true");
+ return true;
+ }else {
+ System.out.println("da simma false");
+ return false;
+ }
+ }
+}
diff --git a/src/main/java/at/reisinger/User.java b/src/main/java/at/reisinger/User.java
new file mode 100644
index 0000000..ebd65a3
--- /dev/null
+++ b/src/main/java/at/reisinger/User.java
@@ -0,0 +1,258 @@
+package at.reisinger;
+
+import com.fasterxml.jackson.annotation.*;
+
+import java.util.ArrayList;
+
+/**
+ * at.reisinger.User & at.reisinger.Store Logik
+ */
+@JsonAutoDetect
+public class User implements Store{
+ @JsonProperty
+ private String name, nachname, email;
+ @JsonProperty
+ private Stack stack;
+ //private DBConnection db;
+ @JsonProperty
+ private Credentials credentials;
+ @JsonProperty
+ private Coins coins;
+
+ /**
+ * Erstellt einen neuen at.reisinger.User
+ * @param credentials Zugangsdaten des Users
+ * @param name Name des Users
+ * @param nachname Nachname des Users
+ * @param email Email des Users
+ * @param stack Alle Karten des Users
+ * @param coins Alle Münzen des Users
+ */
+ @JsonCreator
+ public User(@JsonProperty Credentials credentials,@JsonProperty String name,@JsonProperty String nachname,@JsonProperty String email,@JsonProperty Stack stack,@JsonProperty Coins coins) {
+ this.credentials = credentials;
+ this.name = name;
+ this.nachname = nachname;
+ this.email = email;
+ this.stack = stack;
+ this.coins = coins;
+ //this.db = new at.reisinger.DBConnection();
+ }
+
+ @JsonCreator
+ public User(@JsonProperty Credentials credentials,@JsonProperty String name,@JsonProperty String nachname,@JsonProperty String email,@JsonProperty Coins coins) {
+ this.credentials = credentials;
+ this.name = name;
+ this.nachname = nachname;
+ this.email = email;
+ this.stack = null;
+ this.coins = coins;
+ //this.db = new at.reisinger.DBConnection();
+ }
+
+ /**
+ * Holt den at.reisinger.Stack des Users
+ * @return at.reisinger.Stack des Users
+ */
+ @JsonGetter
+ public Stack getStack() {
+ return stack;
+ }
+
+ /**
+ * Setzt den at.reisinger.Stack eines Users
+ * @param stack Der neue at.reisinger.Stack des Users
+ */
+ @JsonSetter
+ public void setStack(Stack stack) {
+ this.stack = stack;
+ }
+
+ /**
+ * Holt das DB Obj
+ * @return Das DB Obj
+
+ @JsonGetter
+ public DBConnection getDb() {
+ return new DBConnection();
+ }
+
+ /**
+ * Setzt ein neues DB Obj
+ * @param db Das neue DB Obj
+
+
+ @JsonSetter
+ public void setDb(DBConnection db) {
+ this.db = db;
+ }
+
+ */
+
+ /**
+ * Holt die eindeutigen Logindaten des Users
+ * @return Eindeutige Logindaten
+ */
+ @JsonGetter
+ public Credentials getCredentials() {
+ return credentials;
+ }
+
+ /**
+ * Setzt die eindeutigen Logindaten
+ * @param credentials Die neuen at.reisinger.Credentials des Users
+ */
+ @JsonSetter
+ public void setCredentials(Credentials credentials) {
+ this.credentials = credentials;
+ }
+
+ /**
+ * Holt alle at.reisinger.Coins des Users
+ * @return at.reisinger.Coins des Users
+ */
+ @JsonGetter
+ public Coins getCoins() {
+ return coins;
+ }
+
+ /**
+ * Setzt alle at.reisinger.Coins des Users
+ * @param coins Neue at.reisinger.Coins des Users
+ */
+ @JsonSetter
+ public void setCoins(Coins coins) {
+ this.coins = coins;
+ }
+
+ /**
+ * Get Name of at.reisinger.User
+ * @return Name of at.reisinger.User
+ */
+ @JsonGetter
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * Get Nachname of at.reisinger.User
+ * @return Nachname of at.reisinger.User
+ */
+ @JsonGetter
+ public String getNachname() {
+ return this.nachname;
+ }
+
+ /**
+ * Email of at.reisinger.User
+ * @return Email of at.reisinger.User
+ */
+ @JsonGetter
+ public String getEmail() {
+ return this.email;
+ }
+
+ /**
+ * Setzt den Namen des Users
+ * @param name Neuer Name des Users
+ */
+ @JsonSetter
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Setzt den Nachnamen
+ * @param nachname Neuer Nachname
+ */
+ @JsonSetter
+ public void setNachname(String nachname) {
+ this.nachname = nachname;
+ }
+
+ /**
+ * Setzt die Email des Users
+ * @param email Neue Email des Users
+ */
+ @JsonSetter
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ //at.reisinger.Store Methoden
+
+ /**
+ * Kauft ein at.reisinger.Package
+ * @param mypackage at.reisinger.Package welches gekauft werden soll
+ * @return Alle Karten des neuen at.reisinger.Package
+ * @throws NegativAmountException Wenn ein negativer Preis im at.reisinger.Package gesetzt wird.
+ */
+ public ArrayList buyPackage(Package mypackage) throws NegativAmountException {
+ //ArrayList availablePackages = new DBConnection().getAllPackages();
+ //availablePackages.removeIf(obj -> obj.equals(mypackage));
+ this.coins.removeCoin(mypackage.getPrice());
+ return mypackage.getCards();
+ }
+
+ /**
+ * Fügt dem at.reisinger.Store einen neuen Tradingdeal hinzu
+ * @param tradingDeal Der neue Tradingdeal
+ */
+ public void addTradingDeal(TradingDeal tradingDeal) {
+ new DBConnection().addTradingDeal(tradingDeal);
+ }
+
+ /**
+ * Holt alle verfügbaren Tradingdeals
+ * @return Alle verfügbaren Deals
+ */
+ public ArrayList getTradingDeals() {
+ return new DBConnection().getAllTradingDeals();
+ }
+
+ /**
+ * Startet ein Trading zw 2 TradingDeals
+ * @param myTradingDeal Wenn der Deal passt, wird diese Karte aus dem at.reisinger.Stack entfernt
+ * @param storeTradingDeal Wenn der Deal passt, wird diese Karte dem at.reisinger.Stack hinzugefügt
+ * @return True wenn erfolgreich, False wenn die Deals nicht zusammenpassen
+ */
+ public boolean doTrading(TradingDeal myTradingDeal, TradingDeal storeTradingDeal) {
+ if (storeTradingDeal.dealOk(myTradingDeal)){
+ stack.delCard(myTradingDeal.getCardToTrade());
+ stack.addCard(storeTradingDeal.getCardToTrade());
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Gibt alle Möglichen Trading Deals zurück
+ * @param toTrade Prüft nach diesem Deal
+ * @return
+ */
+ @Override
+ public ArrayList getPossibleTradingDeals(Card toTrade) {
+ ArrayList storeList = new DBConnection().getAllTradingDeals();
+ ArrayList possible = new ArrayList();
+ storeList.forEach(item -> {
+ if(item.cardOk(toTrade)){
+ System.out.println("ADDED ein item");
+ possible.add(item);
+ }
+ });
+ return possible;
+ }
+
+ /**
+ * Checkt ob es sich um den selben at.reisinger.User handelt
+ * @param toCheck Mit diesem at.reisinger.User wird verglichen
+ * @return True wenn es der selbe at.reisinger.User ist
+ */
+ public boolean equals(User toCheck){
+ if (toCheck.getCredentials().getUsername() == this.credentials.getUsername() && toCheck.getCredentials().getPasswort() == this.credentials.getPasswort()){
+ return true;
+ }else {
+ return false;
+ }
+ }
+}
diff --git a/src/main/java/at/reisinger/server/Main.java b/src/main/java/at/reisinger/server/Main.java
new file mode 100644
index 0000000..1cc786e
--- /dev/null
+++ b/src/main/java/at/reisinger/server/Main.java
@@ -0,0 +1,65 @@
+package at.reisinger.server;
+
+import at.reisinger.server.msg.MsgHandler;
+import at.reisinger.server.objects.Request;
+import at.reisinger.server.objects.Response;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+/**
+ * Grundlegende Server logic
+ * Vereint alle anderen Klassen
+ */
+public class Main {
+ static final int port = 80;
+ private Socket socket;
+ private int id;
+ private MsgHandler msgHandler;
+
+ /**
+ * Initial Start
+ * @param args Nicht Verwendet
+ */
+ public static void main(String[] args) {
+ System.out.println("Starte Server auf Port 80");
+ new Main(port);
+ }
+
+ /**
+ * Öffnet den Server Socket und akzepiert diesen
+ * @param port Port auf dem der Server läuft
+ */
+ public Main(int port){
+ ServerSocket serverSocket = null;
+ try {
+ serverSocket = new ServerSocket(port);
+
+ //this.msgHandler = new MsgHandler();
+ //this.id = 0;
+ while (true){
+ this.socket = serverSocket.accept();
+ requestResponding();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Jeder Request durchläuft diese Funktion, reagiert auf requests
+ */
+ public void requestResponding(){
+ try{
+ System.out.println("Socket von Client #" + this.id + " wurde gestartet!");
+ Request rq = new Request(this.socket, this.id);
+ Response rp = new Response(this.id, rq.getUrl(), rq.getCmd(), rq.getOut(), null, rq.getPayload());
+ //this.msgHandler = rp.getMsghandler();
+ this.socket.close();
+ System.out.println("Socket von Client #" + this.id + " wurde geschlossen!");
+ }catch (IOException e){
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/at/reisinger/server/helper/JsonHelper.java b/src/main/java/at/reisinger/server/helper/JsonHelper.java
new file mode 100644
index 0000000..dd53af3
--- /dev/null
+++ b/src/main/java/at/reisinger/server/helper/JsonHelper.java
@@ -0,0 +1,7 @@
+package at.reisinger.server.helper;
+
+public class JsonHelper {
+
+
+
+}
diff --git a/src/main/java/at/reisinger/server/msg/MsgHandler.java b/src/main/java/at/reisinger/server/msg/MsgHandler.java
new file mode 100644
index 0000000..f9f609a
--- /dev/null
+++ b/src/main/java/at/reisinger/server/msg/MsgHandler.java
@@ -0,0 +1,89 @@
+package at.reisinger.server.msg;
+
+import at.reisinger.server.objects.Msg;
+
+import java.util.HashMap;
+
+/**
+ * Der Speicher der Nachrichten
+ * Mit hilfe einer HashMap werden die MsgId und die Msg selbst gespeichert
+ * @author Georg Reisinger
+ */
+public class MsgHandler {
+ private HashMap msgHashMap;
+ private int lastID;
+
+ /**
+ * Erstellt den MsgHandler mit standart Test Messages
+ */
+ public MsgHandler(){
+ msgHashMap = new HashMap();
+ addMsg("Hallo");
+ addMsg("Wie");
+ addMsg("Geht");
+ addMsg("Es");
+ addMsg("Dir?");
+
+ }
+
+ /**
+ * Ermitelt die nächste freie Id
+ * @return Next ID
+ */
+ private int nextId(){
+ return this.lastID + 1;
+ }
+
+ /**
+ * Msg hinzufügen
+ * @param msg Message Text
+ */
+ public int addMsg(String msg){
+ int id = nextId();
+ msgHashMap.put(id, msg);
+ this.lastID = id;
+ return id;
+ }
+
+ /**
+ * Msg löschen
+ * @param id Message Id
+ */
+ public String delMsg(int id){
+ return msgHashMap.remove(id);
+ }
+
+ /**
+ * Msg bearbeiten
+ * @param id Message Id
+ * @param msg Message Text
+ */
+ public String editMsg(int id, String msg){
+ return msgHashMap.replace(id, msg);
+ }
+
+ /**
+ * Msg als Objekt holen
+ * @param id Message Id
+ * @return Message als Msg Objekt
+ */
+ public Msg getMsg(int id){
+ return new Msg(id, msgHashMap.get(id));
+ }
+
+ /**
+ * Alle Nachrichten werden in den Format Key, Value besorgt
+ * bsp: key: 1 value: Nachricht
+ * @return Alle nachrichten in einem String
+ */
+ public String getAllMsg(){
+ String returnStr = "";
+ // Print keys and values
+ for (Integer i : msgHashMap.keySet()) {
+ String item = "key: " + i + " value: " + msgHashMap.get(i) + "\n";
+ returnStr += item;
+ }
+ System.out.println(returnStr);
+ return returnStr;
+ }
+}
diff --git a/src/main/java/at/reisinger/server/objects/Msg.java b/src/main/java/at/reisinger/server/objects/Msg.java
new file mode 100644
index 0000000..87a2ea7
--- /dev/null
+++ b/src/main/java/at/reisinger/server/objects/Msg.java
@@ -0,0 +1,37 @@
+package at.reisinger.server.objects;
+
+/**
+ * Message Objekt beinmhaltet die MsgId und die Msg selbst
+ * @author Georg Reisinger
+ */
+public class Msg {
+ private int id;
+ private String msg;
+
+ /**
+ * Erstellt eine Message
+ */
+ public Msg(int id, String msg){
+ this.id = id;
+ this.msg = msg;
+ }
+
+
+ /**
+ * get field
+ *
+ * @return id Message Id
+ */
+ public int getId() {
+ return this.id;
+ }
+
+ /**
+ * get field
+ *
+ * @return msg Message String
+ */
+ public String getMsg() {
+ return this.msg;
+ }
+}
diff --git a/src/main/java/at/reisinger/server/objects/Request.java b/src/main/java/at/reisinger/server/objects/Request.java
new file mode 100644
index 0000000..bc65127
--- /dev/null
+++ b/src/main/java/at/reisinger/server/objects/Request.java
@@ -0,0 +1,110 @@
+package at.reisinger.server.objects;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.net.Socket;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Verarbeitet einen Request
+ * @author Georg Reisinger
+ */
+public class Request {
+
+ private final Socket socket;
+ private final int id;
+ private PrintStream out;
+ private String cmd;
+ private String url;
+ private final StringBuilder rqBuilder;
+ private String payload;
+
+ /**
+ * Get Request
+ * @param socket Socket von dem der Request kommt
+ * @param id Thread ID
+ */
+ public Request(Socket socket, int id) throws IOException {
+ this.socket = socket;
+ this.rqBuilder = new StringBuilder();
+ this.id = id;
+ this.out = new PrintStream(this.socket.getOutputStream());
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ String line = bufferedReader.readLine();
+ while (!line.isBlank()) {
+ rqBuilder.append(line + "\r\n");
+ line = bufferedReader.readLine();
+ System.out.println(line);
+ }
+ String request = rqBuilder.toString();
+ String[] requestsLines = request.split("\r\n");
+ String[] requestLine = requestsLines[0].split(" ");
+ String method = requestLine[0];
+ String path = requestLine[1];
+ String version = requestLine[2];
+ String host = requestsLines[1].split(" ")[1];
+
+ //code to read the post payload data
+ StringBuilder payload = new StringBuilder();
+ while(bufferedReader.ready()){
+ payload.append((char) bufferedReader.read());
+ }
+ System.out.println("Payload: " + payload.toString());
+ this.payload = payload.toString();
+
+ this.url = path;
+ this.cmd = method;
+
+ List headers = new ArrayList<>();
+ for (int h = 2; h < requestsLines.length; h++) {
+ String header = requestsLines[h];
+ headers.add(header);
+ }
+
+ String accessLog = String.format("Client %s, method %s, path %s, version %s, host %s, headers %s",
+ socket.toString(), method, path, version, host, headers.toString());
+ System.out.println(accessLog);
+ }
+
+
+
+ /**
+ * Get PrintStream --> Output
+ *
+ * @return out PrintStream --> Output
+ */
+ public PrintStream getOut() {
+ return this.out;
+ }
+
+ /**
+ * Command wie GET, PUT, POST, DEL
+ *
+ * @return cmd als String
+ */
+ public String getCmd() {
+ return this.cmd;
+ }
+
+ /**
+ * Request url
+ *
+ * @return url als String
+ */
+ public String getUrl() {
+ return this.url;
+ }
+
+ /**
+ * Payload des Request
+ *
+ * @return payload als String
+ */
+ public String getPayload() {
+ return this.payload;
+ }
+
+}
diff --git a/src/main/java/at/reisinger/server/objects/Response.java b/src/main/java/at/reisinger/server/objects/Response.java
new file mode 100644
index 0000000..011777c
--- /dev/null
+++ b/src/main/java/at/reisinger/server/objects/Response.java
@@ -0,0 +1,192 @@
+package at.reisinger.server.objects;
+
+import at.reisinger.*;
+import at.reisinger.server.msg.MsgHandler;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.io.PrintStream;
+import java.util.Map;
+
+/**
+ * Erstellt und sendet eine Response anhand des Requests
+ * @author Georg Reisinger
+ */
+public class Response {
+
+ //private final Socket socket;
+ private final int id;
+ private PrintStream out;
+ private String cmd;
+ private String url;
+ private String payload;
+ private MsgHandler msgHandler;
+ private StringBuilder rqBuilder;
+
+ /**
+ * Nimmt die Daten des requests und generiert eine Response
+ * @param id Thread Id
+ * @param url Request Url
+ * @param cmd Request CMD
+ * @param out out Print Stream
+ * @param msgHandler Der MsgHandler
+ * @param payload Payload des Requests
+ */
+ public Response(int id, String url, String cmd, PrintStream out, MsgHandler msgHandler, String payload){
+ this.id = id;
+ this.msgHandler = msgHandler;
+ this.url = url;
+ this.cmd = cmd;
+ this.out = out;
+ this.payload = payload;
+ this.rqBuilder = new StringBuilder();
+ System.out.println(cmd);
+ if (this.url != null) {
+ if (this.cmd.equals("GET")) {
+ getMethodes();
+ }else if (this.cmd.equals("POST")){
+ try {
+ postMethodes();
+ } catch (JsonProcessingException e) {
+ e.printStackTrace();
+ }
+ }else if (this.cmd.equals("PUT")){
+ putMethodes();
+ }else if (this.cmd.equals("DELETE")){
+ deleteMethodes();
+ }else{
+ sendError("405");
+ }
+ }
+ }
+
+ private void getMethodes(){
+ if (this.url.startsWith("/messages")) {
+ String lastBit = this.url.substring(this.url.lastIndexOf('/') + 1);
+ System.out.println("Last Bit: " + lastBit);
+ if(lastBit.equals("messages")){
+ listAllMsg();
+ }else{
+ String message = msgHandler.getMsg(Integer.parseInt(lastBit)).getMsg();
+ if(message == null){
+ sendError("404");
+ }else {
+ sendResponse(message, "200");
+ }
+ }
+ } else if (this.url.startsWith("/")) {
+ startseite();
+ }
+ }
+
+ private void postMethodes() throws JsonProcessingException {
+ if (this.url.startsWith("/users")) {
+ //payload to map
+ ObjectMapper objectMapper = new ObjectMapper();
+ Map map = objectMapper.readValue(this.payload, new TypeReference