-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
579c230
commit 3ca038d
Showing
6 changed files
with
178 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/com/bookstore/shop/controller/OrderController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.bookstore.shop.controller; | ||
|
||
import com.bookstore.shop.domain.Member; | ||
import com.bookstore.shop.domain.Order; | ||
import com.bookstore.shop.domain.item.Item; | ||
import com.bookstore.shop.repository.OrderSearch; | ||
import com.bookstore.shop.service.ItemService; | ||
import com.bookstore.shop.service.MemberService; | ||
import com.bookstore.shop.service.OrderService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
public class OrderController { | ||
|
||
private final OrderService orderService; | ||
private final MemberService memberService; | ||
private final ItemService itemService; | ||
|
||
@GetMapping("/order") | ||
public String createForm(Model model){ | ||
List<Member> members = memberService.findMembers(); | ||
List<Item> items = itemService.findItems(); | ||
|
||
model.addAttribute("members", members); | ||
model.addAttribute("items", items); | ||
|
||
return "order/orderForm"; | ||
} | ||
|
||
@PostMapping("/order") | ||
public String order(@RequestParam("memberId") Long memberId, @RequestParam("itemId") Long itemId, @RequestParam("count") int count){ | ||
orderService.order(memberId,itemId,count); | ||
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); | ||
System.out.println("dddddddddddddd"); | ||
return "redirect:/orders"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!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"/> | ||
<form role="form" action="/order" method="post"> | ||
<div class="form-group"> | ||
<label for="member">주문회원</label> | ||
<select name="memberId" id="member" class="form-control"> | ||
<option value="">회원선택</option> | ||
<option th:each="member : ${members}" | ||
th:value="${member.id}" | ||
th:text="${member.name}" /> | ||
</select> | ||
</div> | ||
<div class="form-group"> | ||
<label for="item">상품명</label> | ||
<select name="itemId" id="item" class="form-control"> | ||
<option value="">상품선택</option> | ||
<option th:each="item : ${items}" | ||
th:value="${item.id}" | ||
th:text="${item.name}" /> | ||
</select> | ||
</div> | ||
<div class="form-group"> | ||
<label for="count">주문수량</label> | ||
<input type="number" name="count" class="form-control" id="count"placeholder="주문 수량을 입력하세요"> | ||
</div> | ||
<button type="submit" class="btn btn-primary">Submit</button> | ||
</form> | ||
<br/> | ||
<div th:replace="fragments/footer :: footer" /> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<!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="formcontrol" 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.bookstore.shop.domain.status.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="item : ${orders}"> | ||
<td th:text="${item.id}"></td> | ||
<td th:text="${item.member.name}"></td> | ||
<td th:text="${item.orderItems[0].item.name}"></td> | ||
<td th:text="${item.orderItems[0].orderPrice}"></td> | ||
<td th:text="${item.orderItems[0].count}"></td> | ||
<td th:text="${item.status}"></td> | ||
<td th:text="${item.orderDate}"></td> | ||
<td> | ||
<a th:if="${item.status.name() == 'ORDER'}" href="#" | ||
th:href="'javascript:cancel('+${item.id}+')'" | ||
class="btn btn-danger">CANCEL</a> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
<div th:replace="fragments/footer :: footer"/> | ||
</div> | ||
</body> | ||
<script> | ||
function cancel(id) { | ||
var form = document.createElement("form"); | ||
form.setAttribute("method", "post"); | ||
form.setAttribute("action", "/orders/" + id + "/cancel"); | ||
document.body.appendChild(form); | ||
form.submit(); | ||
}</script> | ||
</html> |