ordering process done

Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
Johannes Theiner 2019-06-05 18:41:59 +02:00
parent 88145df721
commit 6d6a1c9b2a
10 changed files with 114 additions and 86 deletions

View File

@ -180,13 +180,6 @@
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<!-- other -->
<dependency>
<groupId>javaee</groupId>
<artifactId>javaee-api</artifactId>
<version>5</version>
</dependency>
</dependencies>

View File

@ -40,7 +40,10 @@ public class AuthorDB {
ResultSet rs = entry.getKey();
Author author = null;
try {
rs.beforeFirst();
while(rs.next()) {
author = new Author(rs.getLong("id"), rs.getString("name"));
}
entry.getValue().close();
} catch (SQLException e) {
e.printStackTrace();

View File

@ -35,6 +35,11 @@ public class BookDB {
public Book get(long id) {
Map.Entry<ResultSet, Connection> entry = database.getResultSetById(database.tableBook, id);
assert entry != null;
try {
entry.getKey().beforeFirst();
} catch (SQLException e) {
e.printStackTrace();
}
return build(entry);
}
@ -50,6 +55,8 @@ public class BookDB {
Book book = null;
ResultSet rs = entry.getKey();
try {
rs.beforeFirst();
while(rs.next()) {
Category category = database.category().get(rs.getLong(database.tableCategory));
Publisher publisher = database.publisher().get(rs.getLong(database.tablePublisher));
List<Integer> authorIds = database.author().getAll(rs.getLong("id"));
@ -66,6 +73,7 @@ public class BookDB {
book = new Book(rs.getLong("id"), rs.getLong("isbn"), authors, publisher, category, rs.getString("title"),
Year.of(rs.getInt("year")), rs.getInt("price"), rs.getString("description"),
rs.getString("image"));
}
entry.getValue().close();
} catch (SQLException e) {

View File

@ -37,7 +37,10 @@ public class PublisherDB {
ResultSet rs = entry.getKey();
Publisher publisher = null;
try {
rs.beforeFirst();
while(rs.next()) {
publisher = new Publisher(rs.getLong("id"), rs.getString("name"));
}
entry.getValue().close();
} catch (SQLException e) {
e.printStackTrace();

View File

@ -7,7 +7,7 @@ import lombok.Getter;
import lombok.Setter;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import java.io.Serializable;
import java.util.ArrayList;
@ -19,7 +19,7 @@ import java.util.List;
* @version 1.0
*/
@ManagedBean
@RequestScoped
@SessionScoped
public class AddressBean implements Serializable {
public User getUser() {

View File

@ -1,16 +1,14 @@
package de.hsel.itech.jsf;
import de.hsel.itech.db.Database;
import de.hsel.itech.db.pojo.Book;
import de.hsel.itech.db.pojo.OrderItem;
import de.hsel.itech.db.pojo.ShoppingCartItem;
import de.hsel.itech.db.pojo.User;
import de.hsel.itech.db.pojo.*;
import lombok.Setter;
import javax.faces.annotation.ManagedProperty;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
@ -24,36 +22,46 @@ public class CartBean {
public User getUser() {
FacesContext context = FacesContext.getCurrentInstance();
return (User) context.getApplication().evaluateExpressionGet(context,"#{userBean.user}", User.class);
return (User) context.getApplication().evaluateExpressionGet(context, "#{userBean.user}", User.class);
}
public String add(Book book){
if(getUser() != null){
for(ShoppingCartItem item : getItems()){
if(item.getArticle().getId() == book.getId()){
public Payment getPayment () {
FacesContext context = FacesContext.getCurrentInstance();
return (Payment) context.getApplication().evaluateExpressionGet(context, "#{paymentBean.selected}", Payment.class);
}
public Address getAddress() {
FacesContext context = FacesContext.getCurrentInstance();
return (Address) context.getApplication().evaluateExpressionGet(context, "#{addressBean.selected}", Address.class);
}
public String add(Book book) {
if (getUser() != null) {
for (ShoppingCartItem item : getItems()) {
if (item.getArticle().getId() == book.getId()) {
Database.getInstance().shoppingCart().delete(item);
item.setCount(item.getCount() + 1);
Database.getInstance().shoppingCart().insert(item);
return "cart.jsf";
}
}
Database.getInstance().shoppingCart().insert(new ShoppingCartItem(getUser(),book,1));
Database.getInstance().shoppingCart().insert(new ShoppingCartItem(getUser(), book, 1));
}
return "cart.jsf";
}
public String remove(ShoppingCartItem item){
if(getUser() != null){
public String remove(ShoppingCartItem item) {
if (getUser() != null) {
Database.getInstance().shoppingCart().delete(item);
}
return "cart.jsf";
}
public List<ShoppingCartItem> getItems(){
public List<ShoppingCartItem> getItems() {
Database db = Database.getInstance();
if(getUser()!=null){
if (getUser() != null) {
return db.shoppingCart().get(getUser());
}else{
} else {
return new ArrayList<ShoppingCartItem>();
}
}
@ -63,31 +71,31 @@ public class CartBean {
}*/
public String buy(){
public String buy() {
ArrayList<OrderItem> orderList = new ArrayList<>();
for(ShoppingCartItem item : getItems()){
orderList.add(new OrderItem(item.getArticle(),item.getCount()));
for (ShoppingCartItem item : getItems()) {
orderList.add(new OrderItem(item.getArticle(), item.getCount()));
}
//Database.getInstance().order().insert(new Order(getUser(),orderList, new Date(234235235),sum(),null,null));
for(ShoppingCartItem item : getItems()) {
Database.getInstance().order().insert(new Order(getUser(), orderList, new Date(System.currentTimeMillis()), sum(), getPayment(), getAddress()));
for (ShoppingCartItem item : getItems()) {
Database.getInstance().shoppingCart().delete(item);
}
return "thanks.jsp";
return "index.jsf";
}
public int getItemCount(){
public int getItemCount() {
return getItems().size();
}
public long sum(){
public long sum() {
int sum = 0;
for(ShoppingCartItem item : getItems()){
for (ShoppingCartItem item : getItems()) {
sum += item.getCount() * item.getArticle().getPrice();
}
return sum;
}
public String getSum(){
public String getSum() {
long sum = sum();
String res = "";
res += sum / 100;

View File

@ -16,6 +16,7 @@
<ui:repeat value="#{addressBean.addressList}" var="address">
<h:panelGroup layout="block" styleClass="m-col-t-3">
<h:form>
<h:commandLink action="#{addressBean.select(address)}">
<div class="m-block m-primary">
#{address.name}<br/>
@ -23,6 +24,7 @@
#{address.zipCode} #{address.city}
</div>
</h:commandLink>
</h:form>
</h:panelGroup>
</ui:repeat>
</h:panelGroup>

View File

@ -45,22 +45,22 @@
</ui:repeat>
<h:panelGroup type="block" styleClass="m-row" rendered="#{cartBean.itemCount != 0}">
<h:panelGroup layout="block" styleClass="m-row" rendered="#{cartBean.itemCount != 0}">
<div class="m-col-t-5 m-push-t-7">
<h1 class="m-text-right">Summe(#{cartBean.itemCount} Items): #{cartBean.sum}&#8364;</h1>
</div>
</h:panelGroup>
<h:panelGroup type="block" styleClass="m-row" rendered="#{cartBean.itemCount == 0}">
<h:panelGroup layout="block" styleClass="m-row" rendered="#{cartBean.itemCount == 0}">
<h1 class="m-text-center">Der Warenkorb ist Leer</h1>
</h:panelGroup>
<div class="m-row">
<h:panelGroup layout="block" styleClass="m-row" rendered="#{cartBean.itemCount != 0}">
<div class="m-col-t-4 m-push-t-4 m-button m-success">
<a href="confirmation.jsf">Jetzt Kaufen</a>
</div>
<a href="addressSelection.xhtml">Jetzt Kaufen</a>
</div>
</h:panelGroup>
</ui:define>
</ui:composition>

View File

@ -15,14 +15,21 @@
<div class="m-row">
<div class="m-col-t-3 m-block">
<h4>Addresse:</h4>
Max Mustermann<br/>
Musterstraße 42<br/>
12345 Musterstadt
#{addressBean.selected.name}<br/>
#{addressBean.selected.street} #{addressBean.selected.number}<br/>
#{addressBean.selected.zipCode} #{addressBean.selected.city}
</div>
<div class="m-col-t-4 m-block m-push-t-5">
<h4>Konto</h4>
IBAN: 12345&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;111<br/>
Inhaber: Max Mustermann<br/>
<h4>#{paymentBean.selected.type.name}</h4>
<h:panelGroup layout="block" rendered="#{paymentBean.selected.type.name eq 'CreditCard'}">
Inhaber: #{paymentBean.selected.owner}<br/>
Nummer : #{paymentBean.selected.number} / #{paymentBean.selected.checksum}
gültig bis: #{paymentBean.selected.expiration}
</h:panelGroup>
<h:panelGroup layout="block" rendered="#{paymentBean.selected.type.name eq 'PayPal'}">
Konto: #{paymentBean.selected.email}
</h:panelGroup>
</div>
</div>
@ -43,7 +50,7 @@
</ui:repeat>
<h:panelGroup type="block" styleClass="m-row">
<h:panelGroup layout="block" styleClass="m-row">
<div class="m-col-t-5 m-push-t-7">
<h1 class="m-text-right">Summe: #{cartBean.sum}&#8364;</h1>
</div>

View File

@ -17,6 +17,7 @@
<h3 class="m-text-center m-text m-small">Kreditkarte</h3>
<h:panelGroup layout="block" styleClass="m-row">
<ui:repeat value="#{paymentBean.creditCard}" var="payment">
<h:form>
<h:commandLink action="#{paymentBean.select(payment)}">
<div class="m-col-t-3">
<div class="m-block m-primary">
@ -29,6 +30,7 @@
</div>
</div>
</h:commandLink>
</h:form>
</ui:repeat>
</h:panelGroup>
@ -37,6 +39,7 @@
<h3 class="m-text-center m-text m-small">PayPal</h3>
<h:panelGroup layout="block" styleClass="m-row">
<ui:repeat value="#{paymentBean.payPal}" var="payment">
<h:form>
<h:commandLink action="#{paymentBean.select(payment)}">
<div class="m-col-t-3">
<div class="m-block m-primary">
@ -44,6 +47,7 @@
</div>
</div>
</h:commandLink>
</h:form>
</ui:repeat>
</h:panelGroup>