Skip to content
Snippets Groups Projects
Commit ef8d7a45 authored by dmz39's avatar dmz39
Browse files

Added checkout page from cart screen

parent b8aebe08
Branches
No related tags found
No related merge requests found
......@@ -4,7 +4,12 @@ import java.util.List;
import javax.servlet.http.HttpSession;
import edu.drexel.TrainDemo.models.users.Address;
import edu.drexel.TrainDemo.services.users.UserService;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
......@@ -19,6 +24,9 @@ public class CartController {
private final Logger logger;
@Autowired
UserService userService;
public CartController(Logger logger){
this.logger = logger;
}
......@@ -40,7 +48,7 @@ public class CartController {
List<Ticket> items = cart.getItems();
model.addAttribute("cart", cart);
model.addAttribute("items", items);
model.addAttribute("cartTotal", cart.getTotal());
// ...
return("cart");
......@@ -75,4 +83,17 @@ public class CartController {
return "redirect:/cart";
}
@RequestMapping("/cart/checkout")
public String checkout(@AuthenticationPrincipal OAuth2User principal, HttpSession session, Model model) {
Cart cart = getCart(session);
List<Address> billingAddresses = this.userService.getBillingAddresses(principal);
List<Address> shippingAddresses = this.userService.getShippingAddresses(principal);
model.addAttribute("cart", cart);
model.addAttribute("billingAddresses", billingAddresses);
model.addAttribute("shippingAddresses", shippingAddresses);
return "cart/checkout";
}
}
\ No newline at end of file
......@@ -40,6 +40,14 @@ public class Cart {
}
}
public double getTotal() {
double total = 0.0;
for (Ticket ticket : this.items) {
total += ticket.getPrice();
}
return total;
}
@Override
public String toString(){
return "Cart{" +
......
......
......@@ -22,6 +22,17 @@ public class Order {
@Column(name = "user_id")
private Long userId;
/*
@Column(name = "billing_id")
private Long billing_id;
@Column(name = "mailing_id")
private Long mailing_id;
@Column(name = "payment_id")
private Long payment_id;
*/
protected Order() {
}
......
......
......@@ -11,6 +11,7 @@ div.address-container {
-moz-border-radius: 5px;
border-radius: 5px;
display: block;
height: 100%;
}
div.list-row {
......@@ -35,3 +36,17 @@ ul.account-header {
body {
margin-top: 50px;
}
.ticket-para {
-ms-word-wrap: normal;
word-wrap: normal;
}
.address-select {
margin: 10px;
}
.row.spacer {
margin-top: 10px;
margin-bottom: 10px;
}
\ No newline at end of file
......@@ -13,6 +13,7 @@
</div>
<div class="container">
<div class="container">
<div class="row">
<table class="table">
<thead class="thead-light">
<tr>
......@@ -49,6 +50,14 @@
</th:block>
</tbody>
</table>
</div>
<div class="row">
<div class="col-md-6">Total Cost:</div>
<div class="col-md-6 text-right">
<a th:text="${cartTotal}"></a><br/>
<span th:if="${!items.isEmpty()}"><a th:href="@{/cart/checkout}"><button class="btn btn-primary">Checkout</button></a></span>
</div>
</div>
<span th:if="${items.isEmpty()}">Your cart is empty.</span>
</div>
</div>
......
......
<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:replace="base::header"/>
</head>
<body>
<th:block th:replace="base::navbar"/>
<main role="main">
<div class="jumbotron">
<div class="container">
<h1>My Cart</h1>
</div>
</div>
<div class="container">
<div class="container">
<div class="row spacer">
<div class="col">
<div class="container address-container">
<th:block th:each="ticket,iter : ${cart.getItems()}">
<div class="row container address">
<p>
<a class="address-header"><pre><a>Ticket #</a><a th:text="${iter.index + 1}"></a></pre><br></a>
<pre><a>From: </a><a th:text="${ticket.getFrom()}"></a></pre><br>
<pre><a>To: </a><a th:text="${ticket.getTo()}"></a></pre><br>
<pre><a>Price: </a><a th:text="${ticket.getPrice()}"></a></pre><br>
</p>
</div>
</th:block>
</div>
</div>
</div>
<div class="row spacer">
<div class="col col-6">
<div class="container address-container">
<a class="address-header">Choose a Billing Address</a>
<div class="row">
<select type="name" class="form-control address-select" id="billingAddress">
<option value="">-- Select Billing Address --</option>
<option th:each="address,iter : ${billingAddresses}" th:value="'billing'+${iter.index + 1}" th:text="'Billing Address ' + ${iter.index + 1}"></option>
</select>
</div>
<br>
<div th:each="address,iter : ${billingAddresses}" class="container address">
<div class="row address-header">
<pre>Billing Info #</a><a th:text="${iter.index + 1}"></a>:</pre>
</div>
<div th:id="'billing'+${iter.index + 1}" class="row" th:object="${address.getId()}">
<p>
<a th:id="addrName" th:text="${address.getName()}"></a><br>
<a th:id="addrLine1" th:text="${address.getLine1()}"></a><br>
<a th:id="addrLine2" th:if="${address.getLine2() != ''}" th:text="${address.getLine2()}"></a><br th:if="${address.getLine2() != ''}">
<a th:id="addrCity" th:text="${address.getCity()}"></a>, <a th:id="addrState" th:text="${address.getState()}"></a> <a th:id="addrZip" th:text="${address.getZip()}"></a><br>
</p>
</div>
</div>
</div>
</div>
<div class="col col-6">
<div class="container address-container">
<a class="address-header">Choose a Shipping Address</a>
<div class="row">
<select type="name" class="form-control address-select" id="shippingAddress">
<option value="">-- Select Shipping Address --</option>
<option th:each="address,iter : ${shippingAddresses}" th:value="'shipping'+${iter.index + 1}" th:text="'Shipping Address ' + ${iter.index + 1}"></option>
</select>
</div>
<br>
<div th:each="address,iter : ${shippingAddresses}" class="container address">
<div class="row address-header">
<pre>Shipping Info #</a><a th:text="${iter.index + 1}"></a>:</pre>
</div>
<div th:id="'shipping'+${iter.index + 1}" class="row" th:object="${address.getId()}">
<p class="ticket-para">
<a th:id="addrName" th:text="${address.getName()}"></a><br>
<a th:id="addrLine1" th:text="${address.getLine1()}"></a><br>
<a th:id="addrLine2" th:if="${address.getLine2() != ''}" th:text="${address.getLine2()}"></a><br th:if="${address.getLine2() != ''}">
<a th:id="addrCity" th:text="${address.getCity()}"></a>, <a th:id="addrState" th:text="${address.getState()}"></a> <a th:id="addrZip" th:text="${address.getZip()}"></a><br>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment