Skip to content
Snippets Groups Projects
Commit ab61f948 authored by Jonathan McDaniel's avatar Jonathan McDaniel
Browse files

Merge remote-tracking branch 'origin/master'

parents 998db0b5 ef20b57c
No related branches found
No related tags found
No related merge requests found
Showing
with 111 additions and 23 deletions
......@@ -106,7 +106,7 @@ public class CartController {
public String completeOrder(@AuthenticationPrincipal OAuth2User principal, HttpSession session, @RequestParam Long shippingId, @RequestParam Long billingId, @RequestParam Long paymentId) {
System.out.println("Completing order: " + shippingId + " | " + billingId + " | " + paymentId);
Cart cart = getCart(session);
Order finalOrder = new Order(cart.getTotal(), this.userService.getUser(principal), billingId, shippingId, paymentId);
Order finalOrder = new Order(cart.getTotal(), this.userService.getUser(principal).getId(), billingId, shippingId, paymentId);
this.orderService.addOrder(finalOrder);
return ("Order " + finalOrder.getId() + " Was Successful!");
}
......
......
package edu.drexel.TrainDemo.controllers.sales;
import edu.drexel.TrainDemo.models.sales.Order;
import edu.drexel.TrainDemo.services.sales.OrderService;
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;
import org.springframework.web.bind.annotation.RequestMapping;
import edu.drexel.TrainDemo.models.sales.Cart;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class OrderController {
private final Logger logger;
@Autowired
OrderService orderService;
public OrderController(Logger logger){
this.logger = logger;
}
@RequestMapping("order/remove")
@ResponseBody
public void removeOrder(@RequestParam long orderId) {
System.out.println("Removing order " + orderId);
Order orderToRemove = this.orderService.getOrder(orderId);
this.orderService.removeOrder(orderToRemove);
}
@RequestMapping("order/update")
@ResponseBody
public void updateOrder(@RequestParam long orderId, @RequestParam double price) {
System.out.println("updating order " + orderId);
this.orderService.updateOrderPrice(orderId, price);
}
// @RequestMapping("/orders")
// public String getOrders(Model model){
......
......
......@@ -79,6 +79,11 @@ public class AdminController {
if (currentUser != null && this.userService.isAllowedAdminPanel(currentUser)) {
List<Group> groups = this.groupService.getGroups();
model.addAttribute("groups", groups);
Map<Long, Integer> groupMap = new HashMap<>();
for (Group group : this.groupService.getGroups()) {
groupMap.put(group.getGroupId(), this.userService.getNumUsersInGroup(group.getGroupId()));
}
model.addAttribute("groupMap", groupMap);
return "admin/groups";
} else {
return "admin/access_denied";
......
......
......@@ -31,9 +31,9 @@ public class Order {
protected Order() {
}
public Order(double price, UserEntity user, Long shippingId, Long billingId, Long paymentId){
public Order(double price, long userId, Long shippingId, Long billingId, Long paymentId){
this.price = price;
this.userId = user.getId();
this.userId = userId;
this.billingId = billingId;
this.shippingId = shippingId;
this.paymentId = paymentId;
......
......
......@@ -10,4 +10,5 @@ public interface UserRepository extends CrudRepository<UserEntity, Long> {
List<UserEntity> findByLastName(String lastName);
UserEntity findById(long id);
UserEntity findByExternalId(long externalId);
int countByGroupId(long groupId);
}
......@@ -11,4 +11,7 @@ public interface OrderService {
Order getOrder(Long orderid);
List<Order> getUserOrders(UserEntity userEntity);
List<Order> getAllOrders();
void removeOrder(Order order);
void updateOrderPrice(long orderId, double price);
}
......@@ -33,4 +33,14 @@ public class OrderServiceImpl implements OrderService {
return allOrders;
}
public void removeOrder(Order order) {
this.orderRepository.delete(order);
}
public void updateOrderPrice(long orderId, double price) {
Order orderToUpdate = this.getOrder(orderId);
orderToUpdate.setPrice(price);
this.orderRepository.save(orderToUpdate);
}
}
......@@ -18,6 +18,7 @@ public interface UserService {
void saveUser(UserEntity user, UserEntity newUser);
void removeUser(long id);
int getNumUsersInGroup(long groupId);
boolean isAllowedAdminPanel(UserEntity userEntity);
void changeGroupId(Long userid, Long groupId);
......
......
......@@ -112,6 +112,10 @@ public class UserServiceImpl implements UserService {
}
}
@Override
public int getNumUsersInGroup(long groupId) {
return this.userRepo.countByGroupId(groupId);
}
@Override
public List<Address> getBillingAddresses(OAuth2User principal) {
......
......
......@@ -36,6 +36,28 @@ function adminRemoveUser(userid) {
});
}
function adminRemoveOrder(orderid) {
$.post("/order/remove", {
orderId: orderid
});
}
function showEditOrderModal(orderid) {
var editModal = $("#editOrderModal");
editModal.find('#orderId').val($("#"+orderid).find("#orderId").html());
editModal.find('#customerId').val($("#"+orderid).find("#customerId").html());
editModal.find('#customerName').val($("#"+orderid).find("#customerName").html());
editModal.find('#price').val($("#"+orderid).find("#price").html());
editModal.modal("show");
}
function updateOrder() {
$.post("/order/update", {
orderId: $('#editOrderModal').find("#orderId").val(),
price: $('#editOrderModal').find("#price").val()
});
}
function addGroup() {
var groupName = $('#newGroupModal').find('#gname').val();
var groupType = $('#newGroupModal').find('#gtype').children("option:selected").val();
......
......
......@@ -31,6 +31,7 @@
<th class="th-sm">Group ID</th>
<th class="th-sm">Group Name</th>
<th class="th-sm">Group Type</th>
<th class="th-sm"># Users</th>
<th class="th-sm">Details</th>
<th class="th-sm">Delete</th>
</tr>
......@@ -40,6 +41,7 @@
<td th:text="${group.getGroupId()}"></td>
<td th:text="${group.getGroupName()}"></td>
<td th:text="${group.getGroupType()}"></td>
<td th:text="${groupMap.get(group.getGroupId())}"></td>
<td><button class="btn btn-primary" th:type="button">Details</button></td>
<td><button class="btn btn-primary" th:type="button">&times;</button></td>
</tr>
......
......
......@@ -37,13 +37,23 @@
</tr>
</thead>
<tbody>
<tr th:each="order : ${orders}">
<td th:text="${order.getId()}"></td>
<td th:text="${order.getUserId()}"></td>
<td th:text="${userMap.get(order.getUserId())}"></td>
<td th:text="${order.getPrice()}"></td>
<td><button class="btn btn-primary" th:type="button">Details</button></td>
<td><button class="btn btn-primary" th:type="button">&times;</button></td>
<tr th:each="order,iter : ${orders}" th:id="${iter.index+1}">
<td id="orderId" th:text="${order.getId()}"></td>
<td id="customerId" th:text="${order.getUserId()}"></td>
<td id="customerName" th:text="${userMap.get(order.getUserId())}"></td>
<td id="price" th:text="${order.getPrice()}"></td>
<td><button class="btn btn-primary" th:type="button" th:onclick="'showEditOrderModal(' + ${iter.index+1} + ')'">Details</button></td>
<td>
<form method="post" th:action="@{/order/remove}" th:object="${orderToRemove}">
<input hidden th:name="id" th:value="${order.getId()}"/>
<input hidden th:name="price" th:value="${order.getPrice()}"/>
<input hidden th:name="userId" th:value="${order.getUserId()}"/>
<input hidden th:name="billingId" th:value="${order.getBillingId()}"/>
<input hidden th:name="shippingId" th:value="${order.getShippingId()}"/>
<input hidden th:name="paymentId" th:value="${order.getPaymentId()}"/>
<a th:href="@{/admin/dashboard}"><button class="btn btn-sm btn-primary" th:type="button" th:onclick="'adminRemoveOrder(' + ${iter.index + 1} +')'">&times;</button></a>
</form>
</td>
</tr>
</tbody>
</table>
......@@ -51,11 +61,11 @@
</div>
</div>
<div class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" id="newGroupModal">
<div class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" id="editOrderModal">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="newGroupModalLongTitle">New Group</h5>
<h5 class="modal-title" id="editOrderModalLongTitle">Edit Order</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
......@@ -65,20 +75,23 @@
<p>Please enter the information for the new group:</p>
<form>
<div class="form-group ">
<label for="gname">Group Name: </label>
<input type="text" class="form-control" id="gname">
<label for="orderId">Order ID: </label>
<input type="text" class="form-control" id="orderId" readonly>
</div>
<div class="form-group ">
<label for="customerId">Customer ID: </label>
<input type="text" class="form-control" id="customerId" readonly>
</div>
<div class="form-group ">
<label for="customerName">Customer Name: </label>
<input type="text" class="form-control" id="customerName" readonly>
</div>
<div class="form-group ">
<label for="gtype">Group Type:</label>
<select type="name" class="form-control" id="gtype">
<option value="">-- Type --</option>
<option value="ADMIN">ADMIN</option>
<option value="EMPLOYEE">EMPLOYEE</option>
<option value="CUSTOMER">CUSTOMER</option>
</select>
<label for="price">Price: </label>
<input type="text" class="form-control" id="price">
</div>
<div class="form-group">
<button onclick="addGroup()">Save</button>
<button onclick="updateOrder()">Save</button>
</div>
</form>
</div>
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment