+ started working on order listing
Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
parent
6d6a1c9b2a
commit
ad17d0d80c
|
@ -37,7 +37,7 @@ public class Database {
|
|||
final String tableUserAddress = "user_address";
|
||||
final String tableAddress = "address";
|
||||
final String tableCartBooks = "cart_books";
|
||||
final String tableOrder = "order";
|
||||
final String tableOrder = "`order`";
|
||||
final String tableOrderBook = "order_book";
|
||||
final String tablePaymentType = "payment_type";
|
||||
final String tablePaymentPayPal = "payment_paypal";
|
||||
|
|
|
@ -23,13 +23,18 @@ public class OrderDB {
|
|||
assert entry != null;
|
||||
|
||||
try {
|
||||
Order order = null;
|
||||
|
||||
ResultSet rs = entry.getKey();
|
||||
rs.beforeFirst();
|
||||
|
||||
while (rs.next()) {
|
||||
List<OrderItem> items = getItems(id);
|
||||
User user = database.user().get(rs.getLong("user"));
|
||||
Payment payment = database.payment().get(rs.getLong("payment"), user);
|
||||
Address address = database.address().get(rs.getLong("address"), user);
|
||||
Order order = new Order(id, user, items, rs.getDate("date"), rs.getLong("price"), payment, address);
|
||||
order = new Order(id, user, items, rs.getDate("date"), rs.getLong("price"), payment, address);
|
||||
}
|
||||
|
||||
entry.getValue().close();
|
||||
return order;
|
||||
|
@ -39,8 +44,25 @@ public class OrderDB {
|
|||
return null;
|
||||
}
|
||||
|
||||
public List<Order> getAll(@NotNull User user) {
|
||||
Map.Entry<ResultSet, Connection> entry = database.getResultSetByValue(database.tableOrder, "user", user.getId());
|
||||
assert entry != null;
|
||||
|
||||
List<Order> list = new ArrayList<>();
|
||||
try {
|
||||
ResultSet rs = entry.getKey();
|
||||
rs.beforeFirst();
|
||||
while (rs.next()) {
|
||||
list.add(get(rs.getLong("id")));
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<OrderItem> getItems(long id) {
|
||||
Map.Entry<ResultSet, Connection> entry = database.getResultSetsById(database.tableOrderBook, "order", id);
|
||||
Map.Entry<ResultSet, Connection> entry = database.getResultSetsById(database.tableOrderBook, database.tableOrder, id);
|
||||
assert entry != null;
|
||||
|
||||
List<OrderItem> items = new ArrayList<>();
|
||||
|
|
|
@ -55,6 +55,7 @@ public class PaymentDB {
|
|||
try {
|
||||
ResultSet rs = entry.getKey();
|
||||
rs.beforeFirst();
|
||||
System.out.println(user);
|
||||
while(rs.next()) {
|
||||
list.add(get(rs.getLong("id"), user));
|
||||
}
|
||||
|
@ -68,10 +69,12 @@ public class PaymentDB {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public Payment get(long id, User user) {
|
||||
public Payment get(long id, @NotNull User user) {
|
||||
Map.Entry<User, PaymentType> metadata = getMetadata(id);
|
||||
assert metadata != null;
|
||||
|
||||
System.out.println(user);
|
||||
|
||||
switch (metadata.getValue().getName()) {
|
||||
case "PayPal":
|
||||
return getPayPal(id, user);
|
||||
|
|
|
@ -6,6 +6,7 @@ import lombok.NonNull;
|
|||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
@ -32,4 +33,13 @@ public class Order {
|
|||
@NonNull private long price;
|
||||
@NonNull private Payment payment;
|
||||
@NonNull private Address address;
|
||||
|
||||
public List<String> getItemNames() {
|
||||
List<String> titles = new ArrayList<>();
|
||||
for(OrderItem item : items) {
|
||||
titles.add(item.getBook().getTitle());
|
||||
}
|
||||
|
||||
return titles;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package de.hsel.itech.jsf;
|
||||
|
||||
import de.hsel.itech.db.Database;
|
||||
import de.hsel.itech.db.pojo.Order;
|
||||
import de.hsel.itech.db.pojo.User;
|
||||
|
||||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.RequestScoped;
|
||||
import javax.faces.context.FacesContext;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 1.0
|
||||
**/
|
||||
|
||||
@ManagedBean
|
||||
@RequestScoped
|
||||
public class OrderBean {
|
||||
|
||||
public User getUser() {
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
return (User) context.getApplication().evaluateExpressionGet(context,"#{userBean.user}", User.class);
|
||||
}
|
||||
|
||||
public List<Order> getOrders() {
|
||||
System.out.println(getUser());
|
||||
return Database.getInstance().order().getAll(getUser());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:h="http://xmlns.jcp.org/jsf/html"
|
||||
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
|
||||
xmlns:f="http://xmlns.jcp.org/jsf/core">
|
||||
<f:view>
|
||||
<ui:composition template="template.xhtml">
|
||||
|
||||
<ui:define name="content">
|
||||
|
||||
<ui:repeat value="#{orderBean.orders}" var="order">
|
||||
<div class="m-row">
|
||||
<div class="m-col-t-12">
|
||||
<div class="m-block m-primary">
|
||||
#{order.itemNames}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ui:repeat>
|
||||
|
||||
</ui:define>
|
||||
|
||||
</ui:composition>
|
||||
</f:view>
|
||||
</html>
|
Loading…
Reference in New Issue