diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index 4d38309..634afc7 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -77,7 +77,7 @@ public class Database { private Database() { Configuration config = Configuration.get(); dataSource = new MariaDbPoolDataSource("jdbc:mysql://" + config.getDatabase().getHostname() - + ":" + config.getDatabase().getPort() + "/" + config.getDatabase().getDatabase() + "?useUnicode=true&characterEncoding=UTF-8"); + + ":" + config.getDatabase().getPort() + "/" + config.getDatabase().getDatabase() + "?useUnicode=true&characterEncoding=UTF-8&maxPoolSize=10&pool"); try { dataSource.setUser(config.getDatabase().getUsername()); dataSource.setPassword(config.getDatabase().getPassword()); diff --git a/src/main/java/de/hsel/itech/jsf/CartBean.java b/src/main/java/de/hsel/itech/jsf/CartBean.java index d66895c..4069a22 100644 --- a/src/main/java/de/hsel/itech/jsf/CartBean.java +++ b/src/main/java/de/hsel/itech/jsf/CartBean.java @@ -6,6 +6,7 @@ import lombok.Setter; import org.jetbrains.annotations.NotNull; import javax.faces.annotation.ManagedProperty; +import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.faces.context.FacesContext; @@ -45,31 +46,44 @@ public class CartBean { if (getUser() != null && getUser().getId() != 0) { for (ShoppingCartItem item : getItems()) { if (item.getArticle().getId() == book.getId()) { + if(item.getCount() >= 127) { + items = getFreshItems(); + FacesContext.getCurrentInstance().addMessage("count:count", new FacesMessage("Es können maximal 127 eines Artikels auf einmal gekauft werden.")); + return "cart.jsf"; + } Database.getInstance().shoppingCart().delete(item); item.setCount(item.getCount() + 1); Database.getInstance().shoppingCart().insert(item); + items = getFreshItems(); return "cart.jsf"; } } Database.getInstance().shoppingCart().insert(new ShoppingCartItem(getUser(), book, 1)); } + items = getFreshItems(); return "cart.jsf"; } public String remove(ShoppingCartItem item) { if (getUser() != null) { Database.getInstance().shoppingCart().delete(item); + items = getFreshItems(); } return "cart.jsf"; } public List getItems() { - if(items != null) return items; + if(items == null) + items = getFreshItems(); + return items; + } + + private List getFreshItems() { Database db = Database.getInstance(); if (getUser() != null) { items = db.shoppingCart().get(getUser()); } else { - items = new ArrayList(); + items = new ArrayList<>(); } return items; } @@ -88,18 +102,23 @@ public class CartBean { public String buy() { ArrayList orderList = new ArrayList<>(); - for (ShoppingCartItem item : getItems()) { + for (ShoppingCartItem item : getFreshItems()) { orderList.add(new OrderItem(item.getArticle(), item.getCount())); } Database.getInstance().order().insert(new Order(getUser(), orderList, new Date(System.currentTimeMillis()), sum(), getPayment(), getAddress())); - for (ShoppingCartItem item : getItems()) { + for (ShoppingCartItem item : getFreshItems()) { Database.getInstance().shoppingCart().delete(item); } + items = getFreshItems(); return "thanks.jsf"; } public int getItemCount() { - return getItems().size(); + int count = 0; + for(ShoppingCartItem item : getItems()) { + count += item.getCount(); + } + return count; } public long sum() { diff --git a/src/main/java/de/hsel/itech/jsf/CreditCardBean.java b/src/main/java/de/hsel/itech/jsf/CreditCardBean.java index 582e2dc..98eec3e 100644 --- a/src/main/java/de/hsel/itech/jsf/CreditCardBean.java +++ b/src/main/java/de/hsel/itech/jsf/CreditCardBean.java @@ -10,6 +10,7 @@ import lombok.Setter; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import javax.faces.context.FacesContext; +import javax.validation.constraints.Future; import java.io.Serializable; import java.util.Date; @@ -38,6 +39,7 @@ public class CreditCardBean implements Serializable { @Getter @Setter + @Future private Date expiration; @Getter diff --git a/src/main/java/de/hsel/itech/jsf/PayPalBean.java b/src/main/java/de/hsel/itech/jsf/PayPalBean.java index 022037e..4b01faf 100644 --- a/src/main/java/de/hsel/itech/jsf/PayPalBean.java +++ b/src/main/java/de/hsel/itech/jsf/PayPalBean.java @@ -9,6 +9,7 @@ import lombok.Setter; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import javax.faces.context.FacesContext; +import javax.validation.constraints.Pattern; import java.io.Serializable; /** @@ -27,6 +28,7 @@ public class PayPalBean implements Serializable { @Getter @Setter + @Pattern(regexp = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])") private String mail; @Getter diff --git a/src/main/java/de/hsel/itech/jsf/SettingsBean.java b/src/main/java/de/hsel/itech/jsf/SettingsBean.java index c7e27c8..1fc50a6 100644 --- a/src/main/java/de/hsel/itech/jsf/SettingsBean.java +++ b/src/main/java/de/hsel/itech/jsf/SettingsBean.java @@ -19,6 +19,6 @@ public class SettingsBean { @Getter @Setter - private boolean darkTheme = true; + private boolean darkTheme = false; } \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/jsf/UserBean.java b/src/main/java/de/hsel/itech/jsf/UserBean.java index 8390234..3453d72 100644 --- a/src/main/java/de/hsel/itech/jsf/UserBean.java +++ b/src/main/java/de/hsel/itech/jsf/UserBean.java @@ -64,7 +64,8 @@ public class UserBean implements Serializable { public String logout() { user = null; loggedIn = false; - return "index.html"; + FacesContext.getCurrentInstance().getExternalContext().invalidateSession(); + return "/index.xhtml?faces-redirect=true"; } public String register() { diff --git a/src/main/webapp/cart.xhtml b/src/main/webapp/cart.xhtml index f06bbd2..d8b449e 100644 --- a/src/main/webapp/cart.xhtml +++ b/src/main/webapp/cart.xhtml @@ -38,9 +38,10 @@
- - + + + @@ -68,10 +69,14 @@
- +

Bitte melden Sie sich an um Bücher in ihrem Warenkorb hinzuzufügen.

+ +

Ihr Warenkorb ist leer.

+
+
diff --git a/src/main/webapp/orders.xhtml b/src/main/webapp/orders.xhtml index c269a01..8e58480 100644 --- a/src/main/webapp/orders.xhtml +++ b/src/main/webapp/orders.xhtml @@ -27,7 +27,7 @@
  • - #{item.book.title} - #{item.book.authorsString} + #{item.count} x #{item.book.title} - #{item.book.authorsString}
diff --git a/src/main/webapp/template.xhtml b/src/main/webapp/template.xhtml index 8051697..f7dedb1 100644 --- a/src/main/webapp/template.xhtml +++ b/src/main/webapp/template.xhtml @@ -73,15 +73,9 @@
  • Dark Theme
    - - - - - - + + +