Skip to content
Snippets Groups Projects
Commit 55908125 authored by cmsho's avatar cmsho
Browse files

Added Orders page and Controller, minor tweaks to templates

parent ab61f948
No related branches found
No related tags found
No related merge requests found
package edu.drexel.TrainDemo.controllers.sales;
import edu.drexel.TrainDemo.models.sales.Order;
import edu.drexel.TrainDemo.models.users.UserEntity;
import edu.drexel.TrainDemo.services.sales.OrderService;
import edu.drexel.TrainDemo.services.users.UserService;
import java.util.List;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
......@@ -23,6 +28,9 @@ public class OrderController {
@Autowired
OrderService orderService;
@Autowired
UserService userService;
public OrderController(Logger logger){
this.logger = logger;
}
......@@ -43,12 +51,16 @@ public class OrderController {
}
// @RequestMapping("/orders")
// public String getOrders(Model model){
@RequestMapping("/user/orders")
public String getOrders(@AuthenticationPrincipal OAuth2User principal, Model model){
// // ...
UserEntity user = userService.getUser(principal);
List<Order> orders = orderService.getAllOrders();
model.addAttribute("orders", orders);
return ("user/orders");
}
// return ("orders");
// }
}
......@@ -4,14 +4,14 @@ spring.jpa.hibernate.ddl-auto=none
# Database connection settings
spring.datasource.url=jdbc:postgresql://localhost:5432/TrainDemo
spring.datasource.username=postgres
spring.datasource.password=Notloc1!
spring.datasource.password=
# Enable the settings below to log the SQL generated by Hibernate
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=false
# Spring Security config
spring.security.oauth2.client.registration.github.client-id=33d271bd8e055a9aa53e
spring.security.oauth2.client.registration.github.client-secret=2c00d9225d7a7a064c256d4b9a24295574c8d584
spring.security.oauth2.client.registration.github.client-id=
spring.security.oauth2.client.registration.github.client-secret=
# spring.security.oauth2.client.registration.google.client-id=
# spring.security.oauth2.client.registration.google.client-secret=
......@@ -20,7 +20,7 @@
<li class="list-group-item list-group-item-action"><a th:href="@{/admin/groups}">Manage Groups</a></li>
<li class="list-group-item list-group-item-action"><a th:href="@{/admin/orders}">Manage Orders</a></li>
<li class="list-group-item list-group-item-action"><a th:href="@{/admin/users}">Manage Users</a></li>
<li class="list-group-item list-group-item-action"><a th:href="@{/admin/placeholder}">TBD...</a></li>
<!-- <li class="list-group-item list-group-item-action"><a th:href="@{/admin/placeholder}">TBD...</a></li> -->
</ul>
</div>
</div>
......
......@@ -55,7 +55,14 @@
<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>
<span class="unauthenticated">
<a class="nav-link" href="#" data-toggle="modal" data-target="#signInModal">
<button class="btn btn-primary">Sign In to Continue Checkout</button>
</a>
</span>
<span class="authenticated" 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>
......
......@@ -55,6 +55,44 @@
</p>
</div>
</div>
<!--
TODO: Make form appear if user selects "New Address"
<form id="address-form">
<a>Enter New Billing Info:</a>
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name">
</div>
<div class="form-group">
<label for="addr1">Address Line 1:</label>
<input type="text" class="form-control" id="addr1">
</div>
<div class="form-group">
<label for="addr2">Address Line 2:</label>
<input type="text" class="form-control" id="addr2">
</div>
<div class="form-group">
<label for="city">City:</label>
<input type="text" class="form-control" id="city">
</div>
<div class="form-group">
<label for="zip">Zip Code:</label>
<input id="zip" name="zip" type="text" pattern="[0-9]*">
</div>
<div class="form-group">
<label for="state">State:</label>
<select type="name" class="form-control" id="state">
<option value="">-- State --</option>
<option th:each="state : ${states}" th:value="${state}" th:text="${state}"></option>
</select>
</div>
<div class="form-group">
<button type="button" class="btn btn-primary" onclick="addAddress(true)">Save</button>
</div>
</form> -->
</div>
</div>
......@@ -82,6 +120,44 @@
</p>
</div>
</div>
<!--
TODO: Make form appear if user selects "New Address"
<form id="address-form">
<a>Enter New Billing Info:</a>
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name">
</div>
<div class="form-group">
<label for="addr1">Address Line 1:</label>
<input type="text" class="form-control" id="addr1">
</div>
<div class="form-group">
<label for="addr2">Address Line 2:</label>
<input type="text" class="form-control" id="addr2">
</div>
<div class="form-group">
<label for="city">City:</label>
<input type="text" class="form-control" id="city">
</div>
<div class="form-group">
<label for="zip">Zip Code:</label>
<input id="zip" name="zip" type="text" pattern="[0-9]*">
</div>
<div class="form-group">
<label for="state">State:</label>
<select type="name" class="form-control" id="state">
<option value="">-- State --</option>
<option th:each="state : ${states}" th:value="${state}" th:text="${state}"></option>
</select>
</div>
<div class="form-group">
<button type="button" class="btn btn-primary" onclick="addAddress(false)">Save</button>
</div>
</form> -->
</div>
</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 Orders</h1>
</div>
</div>
<!--
TODO:
Implement Orders as Bootstrap Cards (?)
Display (loop through) each Ticket in the order
Note: Probably will need JavaScript to handle, plus DB queries through Repository methods...
-->
<!-- <div class="container">
<div class="container">
<table class="table">
<thead class="thead-light">
<tr>
<th scope="col">Order Number</th>
<th scope="col">Price</th>
</tr>
</thead>
<tbody>
<th:block th:each="order : ${orders}">
<tr>
<td th:text="${order.id}"></td>
<td th:text="${order.price}"></td>
</tr>
</th:block>
</tbody>
</table>
<span th:if="${items.isEmpty()}">Your cart is empty.</span>
</div>
</div> -->
</main>
</body>
</html>
\ No newline at end of file
......@@ -9,9 +9,7 @@
<div class="jumbotron">
<div class="container">
<div class="row">
<ul class="account-header">
<li><a th:href="@{/user/dashboard}">My Account</a></li>
</ul>
<h1><a th:href="@{/user/dashboard}">My Account</a></h1>
</div>
</div>
</div>
......@@ -58,11 +56,11 @@
<input type="text" class="form-control" id="city">
</div>
<div class="form-group">
<label for="zip">Zipcode:</label>
<label for="zip">Zip Code:</label>
<input id="zip" name="zip" type="text" pattern="[0-9]*">
</div>
<div class="form-group">
<label for="state">Sate:</label>
<label for="state">State:</label>
<select type="name" class="form-control" id="state">
<option value="">-- State --</option>
<option th:each="state : ${states}" th:value="${state}" th:text="${state}"></option>
......
......@@ -19,7 +19,7 @@
<ul class="list-group">
<li class="list-group-item list-group-item-action"><a th:href="@{/user/addresses(addressType='Billing')}">Billing Info</a></li>
<li class="list-group-item list-group-item-action"><a th:href="@{/user/addresses(addressType='Shipping')}">Shipping Info</a></li>
<li class="list-group-item list-group-item-action"><a th:href="@{/user/payment}">Payment Methods</a></li>
<!-- <li class="list-group-item list-group-item-action"><a th:href="@{/user/payment}">Payment Methods</a></li> -->
<li class="list-group-item list-group-item-action"><a th:href="@{/user/orders}">Your Orders</a></li>
</ul>
</div>
......
<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:replace="base::header"/>
<link href="//cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css" rel="stylesheet">
<script src="//cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/js/admin.js"></script>
</head>
<body>
<th:block th:replace="base::navbar"/>
<main role="main">
<div class="jumbotron">
<div class="container">
<div class="row">
<h1><a th:href="@{/user/dashboard}">My Account</a></h1>
</div>
</div>
</div>
<div class="container">
<div class="container">
<div class="row">
<table class="table">
<thead class="thead-light">
<tr>
<th class="th-sm">Order ID</th>
<th class="th-sm">Order Total</th>
</tr>
</thead>
<tbody>
<th:block th:each="order : ${orders}">
<tr>
<td th:text="${order.getId()}"></td>
<td th:text="${order.getPrice()}"></td>
</tr>
</th:block>
</tbody>
</table>
</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 register or to comment