Skip to content

Commit

Permalink
Fix: 비회원 주문 가능하게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
mummhy0811 committed May 8, 2024
1 parent d19601c commit e471724
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ public void deleteOrder(@PathVariable int orderIdx) {

@PostMapping("")
public void createOrder(@RequestHeader MultiValueMap<String, String> headers, @RequestBody List<OrderReqDto> dtos) {
orderService.createOrder(headers.getFirst("token"), dtos);
if(headers.containsKey("token") ){
orderService.createOrder(headers.getFirst("token"), dtos);
}else{
orderService.createOrder("null", dtos);
}


}

}
4 changes: 2 additions & 2 deletions src/main/java/com/hanaro/starbucks/entity/OrderDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public class OrderDetail {
@Column(name = "order_detail_count")
private int orderDetailCount;

@Column(name = "menu_temperature", nullable = false)
@Column(name = "menu_temperature")
private String menuTemperature;

@Column(name = "menu_size", nullable = false)
@Column(name = "menu_size")
private String menuSize;

@Builder
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/hanaro/starbucks/entity/Orders.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@ public Orders(String orderId, String orderStatus, Member user) {
this.orderDate = LocalDateTime.now();
this.user = user;
}

@Builder
public Orders(String orderId, String orderStatus) {
this.orderId = orderId;
this.orderStatus = orderStatus;
this.orderDate = LocalDateTime.now();
}
}
43 changes: 29 additions & 14 deletions src/main/java/com/hanaro/starbucks/service/OrderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,32 @@ private Orders findOrderById(int orderIdx) {

@Transactional
public void createOrder(String token, List<OrderReqDto> dtos){

String userId = jwtUtil.getAuthentication(token).getName();
System.out.println("User ID: " + userId);
Member member = memberService.getUserById(userId);

new Orders();
Orders order = Orders.builder()
.user(member)
.orderId(UUID.randomUUID().toString())
.orderStatus("주문완료")
.build();

Member member;
Orders order;
if(token.equals("null")){
System.out.println("~~~~~~~~~~~~~~~~~~``");
order = Orders.builder()
.orderId(UUID.randomUUID().toString())
.orderStatus("주문완료")
.build();
}else{
String userId = jwtUtil.getAuthentication(token).getName();
System.out.println("User ID: " + userId);
member = memberService.getUserById(userId);
order = Orders.builder()
.user(member)
.orderId(UUID.randomUUID().toString())
.orderStatus("주문완료")
.build();
}
Orders savedOrder = orderRepository.save(order);
System.out.println("~~~"+order.getOrderIdx());

List<OrderDetail> orderDetails = dtos.stream()
.map(dto -> {
try {
new OrderDetail();
return OrderDetail.builder()
.orders(order)
.orders(savedOrder)
.menu(menuService.findMenuByMenuIdx(dto.getMenuIdx()))
.menuSize(dto.getMenuSize())
.orderDetailCount(dto.getOrderDetailCount())
Expand All @@ -118,6 +125,14 @@ public void createOrder(String token, List<OrderReqDto> dtos){

})
.collect(Collectors.toList());
System.out.println("~~~~~~~~"+orderDetails.size());
for(OrderDetail orderDetail : orderDetails){
System.out.println(orderDetail.getOrders());
System.out.println(orderDetail.getMenu());
System.out.println(orderDetail.getMenuTemperature());
System.out.println(orderDetail.getOrderDetailIdx());
}

orderDetailRepository.saveAll(orderDetails);
}
private int calculateTotalPrice(List<OrderDetail> orderDetails) {
Expand Down

0 comments on commit e471724

Please sign in to comment.