+ first two payment methods being displayed
Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
parent
9f3b31113f
commit
d205e62419
|
@ -277,10 +277,12 @@ public class Database {
|
||||||
PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + table + " WHERE " + column + " = ?");
|
PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + table + " WHERE " + column + " = ?");
|
||||||
statement.setLong(1, value);
|
statement.setLong(1, value);
|
||||||
ResultSet resultSet = statement.executeQuery();
|
ResultSet resultSet = statement.executeQuery();
|
||||||
if (resultSet.next()) {
|
Map.Entry<ResultSet, Connection> entry = null;
|
||||||
return new AbstractMap.SimpleEntry<>(resultSet, connection);
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
entry = new AbstractMap.SimpleEntry<>(resultSet, connection);
|
||||||
}
|
}
|
||||||
return null;
|
return entry;
|
||||||
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class OrderDB {
|
||||||
ResultSet rs = entry.getKey();
|
ResultSet rs = entry.getKey();
|
||||||
List<OrderItem> items = getItems(id);
|
List<OrderItem> items = getItems(id);
|
||||||
User user = database.user().get(rs.getLong("user"));
|
User user = database.user().get(rs.getLong("user"));
|
||||||
Payment payment = database.payment().get(rs.getLong("payment"));
|
Payment payment = database.payment().get(rs.getLong("payment"), user);
|
||||||
Address address = database.address().get(rs.getLong("address"), 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 order = new Order(id, user, items, rs.getDate("date"), rs.getLong("price"), payment, address);
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,11 @@ public class PaymentDB {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ResultSet rs = entry.getKey();
|
ResultSet rs = entry.getKey();
|
||||||
PaymentType type = new PaymentType(id, rs.getString("name"));
|
rs.beforeFirst();
|
||||||
|
PaymentType type = null;
|
||||||
|
while(rs.next()) {
|
||||||
|
type = new PaymentType(id, rs.getString("name"));
|
||||||
|
}
|
||||||
entry.getValue().close();
|
entry.getValue().close();
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
|
@ -43,15 +47,16 @@ public class PaymentDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<Payment> get(@NotNull User user) {
|
public List<? extends Payment> get(@NotNull User user) {
|
||||||
List<Payment> list = new ArrayList<>();
|
List<Payment> list = new ArrayList<>();
|
||||||
Map.Entry<ResultSet, Connection> entry = database.getResultSetByValue(database.tableUserPayment, "user", user.getId());
|
Map.Entry<ResultSet, Connection> entry = database.getResultSetByValue(database.tableUserPayment, "user", user.getId());
|
||||||
assert entry != null;
|
if(entry == null) return list;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ResultSet rs = entry.getKey();
|
ResultSet rs = entry.getKey();
|
||||||
|
rs.beforeFirst();
|
||||||
while(rs.next()) {
|
while(rs.next()) {
|
||||||
list.add(get(rs.getLong("id")));
|
list.add(get(rs.getLong("id"), user));
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.getValue().close();
|
entry.getValue().close();
|
||||||
|
@ -63,19 +68,19 @@ public class PaymentDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Payment get(long id) {
|
public Payment get(long id, User user) {
|
||||||
Map.Entry<User, PaymentType> metadata = getMetadata(id);
|
Map.Entry<User, PaymentType> metadata = getMetadata(id);
|
||||||
assert metadata != null;
|
assert metadata != null;
|
||||||
|
|
||||||
switch (metadata.getValue().getName()) {
|
switch (metadata.getValue().getName()) {
|
||||||
case "PayPal":
|
case "PayPal":
|
||||||
return getPayPal(id, metadata.getKey());
|
return getPayPal(id, user);
|
||||||
case "CreditCard":
|
case "CreditCard":
|
||||||
return getCreditCard(id, metadata.getKey());
|
return getCreditCard(id, user);
|
||||||
case "DebitCard":
|
case "DebitCard":
|
||||||
return getDebitCard(id, metadata.getKey());
|
return getDebitCard(id, user);
|
||||||
case "Invoice":
|
case "Invoice":
|
||||||
return getInvoice(id, metadata.getKey());
|
return getInvoice(id, user);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +92,11 @@ public class PaymentDB {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ResultSet rs = entry.getKey();
|
ResultSet rs = entry.getKey();
|
||||||
PayPalPayment payment = new PayPalPayment(id, user, rs.getString("email"), rs.getString("authCode"));
|
rs.beforeFirst();
|
||||||
|
PayPalPayment payment = null;
|
||||||
|
while(rs.next()) {
|
||||||
|
payment = new PayPalPayment(id, user, rs.getString("mail"), rs.getString("auth"));
|
||||||
|
}
|
||||||
entry.getValue().close();
|
entry.getValue().close();
|
||||||
|
|
||||||
return payment;
|
return payment;
|
||||||
|
@ -105,7 +114,12 @@ public class PaymentDB {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ResultSet rs = entry.getKey();
|
ResultSet rs = entry.getKey();
|
||||||
CreditCardPayment payment = new CreditCardPayment(id, user, rs.getInt("number"), rs.getString("owner"), rs.getDate("expiration"), rs.getInt("checksum"));
|
rs.beforeFirst();
|
||||||
|
CreditCardPayment payment = null;
|
||||||
|
while(rs.next()) {
|
||||||
|
payment = new CreditCardPayment(id, user, rs.getInt("number"), rs.getString("owner"), rs.getDate("expiration"), rs.getInt("checksum"));
|
||||||
|
}
|
||||||
|
|
||||||
entry.getValue().close();
|
entry.getValue().close();
|
||||||
|
|
||||||
return payment;
|
return payment;
|
||||||
|
@ -123,7 +137,11 @@ public class PaymentDB {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ResultSet rs = entry.getKey();
|
ResultSet rs = entry.getKey();
|
||||||
DebitCardPayment payment = new DebitCardPayment(id, user, rs.getString("iban"), rs.getString("bic"), rs.getString("owner"));
|
rs.beforeFirst();
|
||||||
|
DebitCardPayment payment = null;
|
||||||
|
while(rs.next()) {
|
||||||
|
payment = new DebitCardPayment(id, user, rs.getString("iban"), rs.getString("bic"), rs.getString("owner"));
|
||||||
|
}
|
||||||
entry.getValue().close();
|
entry.getValue().close();
|
||||||
|
|
||||||
return payment;
|
return payment;
|
||||||
|
@ -140,10 +158,13 @@ public class PaymentDB {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ResultSet rs = entry.getKey();
|
ResultSet rs = entry.getKey();
|
||||||
|
rs.beforeFirst();
|
||||||
InvoicePayment payment = null;
|
InvoicePayment payment = null;
|
||||||
|
while(rs.next()) {
|
||||||
if(rs.getLong("id") == id && rs.getLong("user") == user.getId()) {
|
if(rs.getLong("id") == id && rs.getLong("user") == user.getId()) {
|
||||||
payment = new InvoicePayment(id, user);
|
payment = new InvoicePayment(id, user);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
entry.getValue().close();
|
entry.getValue().close();
|
||||||
|
|
||||||
return payment;
|
return payment;
|
||||||
|
@ -296,8 +317,11 @@ public class PaymentDB {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ResultSet rs = entry.getKey();
|
ResultSet rs = entry.getKey();
|
||||||
Map.Entry<User, PaymentType> metadata = new AbstractMap.SimpleEntry<>(database.user().get(rs.getLong("user")), getType(rs.getLong("type")));
|
rs.beforeFirst();
|
||||||
|
Map.Entry<User, PaymentType> metadata = null;
|
||||||
|
while(rs.next()) {
|
||||||
|
metadata = new AbstractMap.SimpleEntry<>(database.user().get(rs.getLong("user")), getType(rs.getLong("type")));
|
||||||
|
}
|
||||||
entry.getValue().close();
|
entry.getValue().close();
|
||||||
|
|
||||||
return metadata;
|
return metadata;
|
||||||
|
|
|
@ -6,10 +6,10 @@ import de.hsel.itech.db.pojo.User;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import javax.faces.annotation.ManagedProperty;
|
|
||||||
import javax.faces.bean.ManagedBean;
|
import javax.faces.bean.ManagedBean;
|
||||||
import javax.faces.bean.RequestScoped;
|
import javax.faces.bean.RequestScoped;
|
||||||
import javax.faces.context.FacesContext;
|
import javax.faces.context.FacesContext;
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -20,11 +20,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@ManagedBean
|
@ManagedBean
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class AddressBean {
|
public class AddressBean implements Serializable {
|
||||||
|
|
||||||
@Setter
|
|
||||||
@ManagedProperty("#{userBean.user}")
|
|
||||||
private User user;
|
|
||||||
|
|
||||||
public User getUser() {
|
public User getUser() {
|
||||||
FacesContext context = FacesContext.getCurrentInstance();
|
FacesContext context = FacesContext.getCurrentInstance();
|
||||||
|
|
|
@ -1,23 +1,56 @@
|
||||||
package de.hsel.itech.jsf;
|
package de.hsel.itech.jsf;
|
||||||
|
|
||||||
import de.hsel.itech.db.Database;
|
import de.hsel.itech.db.Database;
|
||||||
import de.hsel.itech.db.pojo.Payment;
|
import de.hsel.itech.db.pojo.*;
|
||||||
import de.hsel.itech.db.pojo.User;
|
|
||||||
|
|
||||||
import javax.faces.annotation.ManagedProperty;
|
|
||||||
import javax.faces.bean.ManagedBean;
|
import javax.faces.bean.ManagedBean;
|
||||||
import javax.faces.bean.SessionScoped;
|
import javax.faces.bean.SessionScoped;
|
||||||
|
import javax.faces.context.FacesContext;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ManagedBean
|
@ManagedBean
|
||||||
@SessionScoped
|
@SessionScoped
|
||||||
public class PaymentBean {
|
public class PaymentBean {
|
||||||
|
|
||||||
@ManagedProperty("#{userBean.user}")
|
public User getUser() {
|
||||||
private User user;
|
FacesContext context = FacesContext.getCurrentInstance();
|
||||||
|
return (User) context.getApplication().evaluateExpressionGet(context,"#{userBean.user}", User.class);
|
||||||
public List<Payment> getMethods() {
|
|
||||||
return Database.getInstance().payment().get(user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<CreditCardPayment> getCreditCard() {
|
||||||
|
List<CreditCardPayment> list = new ArrayList<>();
|
||||||
|
for(Payment payment : Database.getInstance().payment().get(getUser())) {
|
||||||
|
if(payment instanceof CreditCardPayment)
|
||||||
|
list.add((CreditCardPayment) payment);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DebitCardPayment> getDebitCard() {
|
||||||
|
List<DebitCardPayment> list = new ArrayList<>();
|
||||||
|
for(Payment payment : Database.getInstance().payment().get(getUser())) {
|
||||||
|
if(payment instanceof DebitCardPayment)
|
||||||
|
list.add((DebitCardPayment) payment);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PayPalPayment> getPayPal() {
|
||||||
|
List<PayPalPayment> list = new ArrayList<>();
|
||||||
|
for (Payment payment : Database.getInstance().payment().get(getUser())) {
|
||||||
|
if(payment instanceof PayPalPayment)
|
||||||
|
list.add((PayPalPayment) payment);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<InvoicePayment> getInvoice() {
|
||||||
|
List<InvoicePayment> list = new ArrayList<>();
|
||||||
|
for(Payment payment : Database.getInstance().payment().get(getUser())) {
|
||||||
|
if(payment instanceof InvoicePayment)
|
||||||
|
list.add((InvoicePayment) payment);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -7,10 +7,11 @@ import lombok.Setter;
|
||||||
|
|
||||||
import javax.faces.bean.ManagedBean;
|
import javax.faces.bean.ManagedBean;
|
||||||
import javax.faces.bean.SessionScoped;
|
import javax.faces.bean.SessionScoped;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
@ManagedBean
|
@ManagedBean
|
||||||
@SessionScoped
|
@SessionScoped
|
||||||
public class UserBean {
|
public class UserBean implements Serializable {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
|
|
@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS author(id bigint primary key auto_increment, name var
|
||||||
CREATE TABLE IF NOT EXISTS author_book(author bigint, book bigint, primary key(author, book), foreign key (author) REFERENCES author(id), foreign key (book) references book(id) on delete cascade);
|
CREATE TABLE IF NOT EXISTS author_book(author bigint, book bigint, primary key(author, book), foreign key (author) REFERENCES author(id), foreign key (book) references book(id) on delete cascade);
|
||||||
CREATE TABLE IF NOT EXISTS category(id bigint primary key auto_increment, name varchar(25), image varchar(11));
|
CREATE TABLE IF NOT EXISTS category(id bigint primary key auto_increment, name varchar(25), image varchar(11));
|
||||||
CREATE TABLE IF NOT EXISTS user(id bigint primary key auto_increment, name varchar(50), email varchar(255), password binary(60), type tinyint);
|
CREATE TABLE IF NOT EXISTS user(id bigint primary key auto_increment, name varchar(50), email varchar(255), password binary(60), type tinyint);
|
||||||
CREATE TABLE IF NOT EXISTS address(id bigint primary key auto_increment, name varchar(100), street varchar(100), number smallint, zipCode smallint, city varchar(50));
|
CREATE TABLE IF NOT EXISTS address(id bigint primary key auto_increment, name varchar(100), street varchar(100), number smallint, zipCode int(6), city varchar(50));
|
||||||
CREATE TABLE IF NOT EXISTS user_address(id bigint primary key auto_increment, user bigint, address bigint, foreign key (user) REFERENCES user(id), foreign key (address) references address(id) on delete cascade);
|
CREATE TABLE IF NOT EXISTS user_address(id bigint primary key auto_increment, user bigint, address bigint, foreign key (user) REFERENCES user(id), foreign key (address) references address(id) on delete cascade);
|
||||||
CREATE TABLE IF NOT EXISTS payment_type(id bigint primary key auto_increment, name varchar(25) unique);
|
CREATE TABLE IF NOT EXISTS payment_type(id bigint primary key auto_increment, name varchar(25) unique);
|
||||||
INSERT IGNORE INTO payment_type (name) values ('CreditCard');
|
INSERT IGNORE INTO payment_type (name) values ('CreditCard');
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
<?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">
|
||||||
|
|
||||||
|
<h1 class="m-text-center">Zahlungsmöglichkeiten</h1>
|
||||||
|
|
||||||
|
<h:panelGroup layout="block" rendered="#{userBean.loggedIn}">
|
||||||
|
|
||||||
|
|
||||||
|
<h3 class="m-text-center">Kreditkarte</h3>
|
||||||
|
<h:panelGroup layout="block" styleClass="m-row">
|
||||||
|
<ui:repeat value="#{paymentBean.creditCard}" var="payment">
|
||||||
|
<div class="m-col-t-3">
|
||||||
|
<div class="m-block m-primary">
|
||||||
|
#{payment.owner}<br/>
|
||||||
|
#{payment.number}<br/>
|
||||||
|
#{payment.checksum}<br/>
|
||||||
|
#{payment.expiration}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ui:repeat>
|
||||||
|
<div class="m-col-t-3">
|
||||||
|
<h:outputLink value="payment-add.jsf">
|
||||||
|
<div class="m-block m-text-center">
|
||||||
|
<i class="fas fa-plus fa-4x"/>
|
||||||
|
</div>
|
||||||
|
</h:outputLink>
|
||||||
|
</div>
|
||||||
|
</h:panelGroup>
|
||||||
|
|
||||||
|
|
||||||
|
<h3 class="m-text-center">PayPal</h3>
|
||||||
|
<h:panelGroup layout="block" styleClass="m-row">
|
||||||
|
<ui:repeat value="#{paymentBean.payPal}" var="payment">
|
||||||
|
<div class="m-col-t-3">
|
||||||
|
<div class="m-block m-primary">
|
||||||
|
#{payment.email}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ui:repeat>
|
||||||
|
<div class="m-col-t-3">
|
||||||
|
<h:outputLink value="payment-add.jsf">
|
||||||
|
<div class="m-block m-text-center">
|
||||||
|
<i class="fas fa-plus fa-4x"/>
|
||||||
|
</div>
|
||||||
|
</h:outputLink>
|
||||||
|
</div>
|
||||||
|
</h:panelGroup>
|
||||||
|
|
||||||
|
|
||||||
|
</h:panelGroup>
|
||||||
|
|
||||||
|
</ui:define>
|
||||||
|
</ui:composition>
|
||||||
|
</f:view>
|
||||||
|
</html>
|
Loading…
Reference in New Issue