jpashop : order list search, cancle - views, controller
This commit is contained in:
@@ -2,8 +2,10 @@ package com.example.jpashop.controller;
|
|||||||
|
|
||||||
import com.example.jpashop.domain.item.Book;
|
import com.example.jpashop.domain.item.Book;
|
||||||
import com.example.jpashop.domain.item.Item;
|
import com.example.jpashop.domain.item.Item;
|
||||||
|
import com.example.jpashop.repository.OrderSearch;
|
||||||
import com.example.jpashop.service.ItemService;
|
import com.example.jpashop.service.ItemService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.dom4j.rule.Mode;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.example.jpashop.controller;
|
package com.example.jpashop.controller;
|
||||||
|
|
||||||
import com.example.jpashop.domain.Member;
|
import com.example.jpashop.domain.Member;
|
||||||
|
import com.example.jpashop.domain.Order;
|
||||||
import com.example.jpashop.domain.item.Item;
|
import com.example.jpashop.domain.item.Item;
|
||||||
|
import com.example.jpashop.repository.OrderSearch;
|
||||||
import com.example.jpashop.service.ItemService;
|
import com.example.jpashop.service.ItemService;
|
||||||
import com.example.jpashop.service.MemberService;
|
import com.example.jpashop.service.MemberService;
|
||||||
import com.example.jpashop.service.OrderService;
|
import com.example.jpashop.service.OrderService;
|
||||||
@@ -9,6 +11,8 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -38,4 +42,17 @@ public class OrderController {
|
|||||||
orderService.order(memberId, itemId, count);
|
orderService.order(memberId, itemId, count);
|
||||||
return "redirect:/orders";
|
return "redirect:/orders";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/orders")
|
||||||
|
public String orderList(@ModelAttribute("orderSearch") OrderSearch orderSearch, Model model) {
|
||||||
|
List<Order> orders = orderService.findOrders(orderSearch);
|
||||||
|
model.addAttribute("orders", orders);
|
||||||
|
return "order/orderList";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/orders/{orderId}/cancel")
|
||||||
|
public String cancelOrder(@PathVariable("orderId") Long orderId) {
|
||||||
|
orderService.cancelOrder(orderId);
|
||||||
|
return "redirect:/orders";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.example.jpashop.domain.item.Item;
|
|||||||
import com.example.jpashop.repository.ItemRepository;
|
import com.example.jpashop.repository.ItemRepository;
|
||||||
import com.example.jpashop.repository.MemberRepository;
|
import com.example.jpashop.repository.MemberRepository;
|
||||||
import com.example.jpashop.repository.OrderRepository;
|
import com.example.jpashop.repository.OrderRepository;
|
||||||
|
import com.example.jpashop.repository.OrderSearch;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -61,7 +62,7 @@ public class OrderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 검색
|
// 검색
|
||||||
/* public List<Order> findOrders(OrderSearch orderSearch) {
|
public List<Order> findOrders(OrderSearch orderSearch) {
|
||||||
return orderRepository.findAll(orderSearch);
|
return orderRepository.findAllByString(orderSearch);
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
68
jpashop/src/main/resources/templates/order/orderList.html
Normal file
68
jpashop/src/main/resources/templates/order/orderList.html
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head th:replace="fragments/header :: header"/>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<div th:replace="fragments/bodyHeader :: bodyHeader"/>
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<form th:object="${orderSearch}" class="form-inline">
|
||||||
|
<div class="form-group mb-2">
|
||||||
|
<input type="text" th:field="*{memberName}" class="form-control" placeholder="회원명"/>
|
||||||
|
</div>
|
||||||
|
<div class="form-group mx-sm-1 mb-2">
|
||||||
|
<select th:field="*{orderStatus}" class="form-control">
|
||||||
|
<option value="">주문상태</option>
|
||||||
|
<option th:each="status : ${T(com.example.jpashop.domain.OrderStatus).values()}"
|
||||||
|
th:value="${status}"
|
||||||
|
th:text="${status}">option
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary mb-2">검색</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>#</th>
|
||||||
|
<th>회원명</th>
|
||||||
|
<th>대표상품 이름</th>
|
||||||
|
<th>대표상품 주문가격</th>
|
||||||
|
<th>대표상품 주문수량</th>
|
||||||
|
<th>상태</th>
|
||||||
|
<th>일시</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr th:each="order : ${orders}">
|
||||||
|
<td th:text="${order.id}"></td>
|
||||||
|
<td th:text="${order.member.name}"></td>
|
||||||
|
<td th:text="${order.orderItems[0].item.name}"></td>
|
||||||
|
<td th:text="${order.orderItems[0].orderPrice}"></td>
|
||||||
|
<td th:text="${order.orderItems[0].count}"></td>
|
||||||
|
<td th:text="${order.status}"></td>
|
||||||
|
<td th:text="${order.orderDate}"></td>
|
||||||
|
<td>
|
||||||
|
<a th:if="${order.status.name() == 'ORDER'}" href="#"
|
||||||
|
th:href="'javascript:cancel('+${order.id}+')'"
|
||||||
|
class="btn btn-danger">CANCEL</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div th:replace="fragments/footer :: footer"/>
|
||||||
|
</div> <!-- /container -->
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
function cancel(id) {
|
||||||
|
let form = document.createElement("form");
|
||||||
|
form.setAttribute("method", "post");
|
||||||
|
form.setAttribute("action", "/orders/" + id + "/cancel");
|
||||||
|
document.body.appendChild(form);
|
||||||
|
form.submit();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user