@@ -64,6 +64,10 @@
|
||||
== snippets 작성 컨벤션
|
||||
domain-httpRequestCode-etc
|
||||
|
||||
== 주문
|
||||
=== 주문 수정
|
||||
operation::order-patch[snippets='curl-request,http-request,http-response,path-parameters,request-fields,response-fields']
|
||||
|
||||
== 점주 서비스
|
||||
=== 주문 페이지
|
||||
- 페이지 offset : 6
|
||||
|
||||
@@ -26,7 +26,7 @@ public class OrderServiceApplication {
|
||||
@Transactional
|
||||
CommandLineRunner run(OrderRepository orderRepository) {
|
||||
return args -> {
|
||||
Long userId = 1L;
|
||||
Long userId = 2L;
|
||||
Long userCouponId = null;
|
||||
Long storeId = 1L;
|
||||
Long orderPrice = 1000L;
|
||||
@@ -45,6 +45,12 @@ public class OrderServiceApplication {
|
||||
|
||||
Order order = Order.of(userId, userCouponId, storeId, orderPrice * i, transaction, orderItem, orderItem1);
|
||||
|
||||
if (i % 2 == 0) {
|
||||
order.placed();
|
||||
} else {
|
||||
order.order();
|
||||
}
|
||||
|
||||
orderRepository.save(order);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.justpickup.orderservice.domain.order.dto;
|
||||
|
||||
import com.justpickup.orderservice.domain.order.entity.Order;
|
||||
import com.justpickup.orderservice.domain.order.entity.OrderStatus;
|
||||
import com.justpickup.orderservice.domain.orderItem.entity.OrderItem;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
@Getter @Builder
|
||||
public class OrderMainDto {
|
||||
private List<_Order> orders;
|
||||
private boolean hasNext;
|
||||
|
||||
// == constructor == //
|
||||
public static OrderMainDto of(List<Order> orders, boolean hasNext) {
|
||||
return OrderMainDto.builder()
|
||||
.orders(orders.stream().map(_Order::of).collect(toList()))
|
||||
.hasNext(hasNext)
|
||||
.build();
|
||||
}
|
||||
|
||||
// == inner class == //
|
||||
@Getter @Builder
|
||||
public static class _Order {
|
||||
private Long id;
|
||||
private Long userId;
|
||||
private OrderStatus orderStatus;
|
||||
private LocalDateTime orderTime;
|
||||
private List<_OrderItem> orderItems;
|
||||
|
||||
private String userName;
|
||||
private String storeName;
|
||||
|
||||
public static _Order of(Order order) {
|
||||
List<_OrderItem> orderItems = order.getOrderItems()
|
||||
.stream()
|
||||
.map(_OrderItem::of)
|
||||
.collect(toList());
|
||||
|
||||
return _Order.builder()
|
||||
.id(order.getId())
|
||||
.userId(order.getUserId())
|
||||
.orderStatus(order.getOrderStatus())
|
||||
.orderTime(order.getOrderTime())
|
||||
.orderItems(orderItems)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@Getter @Builder
|
||||
public static class _OrderItem {
|
||||
private Long id;
|
||||
private Long itemId;
|
||||
private String itemName;
|
||||
|
||||
public static _OrderItem of(OrderItem orderItem) {
|
||||
return _OrderItem.builder()
|
||||
.id(orderItem.getId())
|
||||
.itemId(orderItem.getItemId())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.justpickup.orderservice.domain.order.dto;
|
||||
|
||||
import com.justpickup.orderservice.domain.order.entity.Order;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public class OrderMainResult {
|
||||
private List<Order> orders;
|
||||
private boolean hasNext;
|
||||
}
|
||||
@@ -96,4 +96,16 @@ public class Order extends BaseEntity {
|
||||
this.orderStatus = orderStatus;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void placed() {
|
||||
this.orderStatus = OrderStatus.PLACED;
|
||||
}
|
||||
|
||||
public void order() {
|
||||
this.orderStatus = OrderStatus.ORDER;
|
||||
}
|
||||
|
||||
public void reject() {
|
||||
this.orderStatus = OrderStatus.REJECT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.justpickup.orderservice.domain.order.entity;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.persistence.PostUpdate;
|
||||
|
||||
@Slf4j
|
||||
public class OrderListener {
|
||||
|
||||
@PostUpdate
|
||||
private void postUpdate(Order order) {
|
||||
OrderStatus orderStatus = order.getOrderStatus();
|
||||
if (orderStatus == OrderStatus.ORDER) {
|
||||
// TODO: 2022/03/10 Kafka 알림 전송
|
||||
log.info("[OrderListener] {}", OrderStatus.ORDER.name());
|
||||
} else if (orderStatus == OrderStatus.PLACED) {
|
||||
log.info("[OrderListener] {}", OrderStatus.PLACED.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,15 @@
|
||||
package com.justpickup.orderservice.domain.order.entity;
|
||||
|
||||
public enum OrderStatus {
|
||||
PENDING,
|
||||
PLACED,
|
||||
CANCELED,
|
||||
FAILED
|
||||
PENDING("주문대기"),
|
||||
ORDER("주문"),
|
||||
PLACED("주문수락"),
|
||||
REJECT("주문거절"),
|
||||
FAIL("주문실패");
|
||||
|
||||
private String message;
|
||||
|
||||
OrderStatus(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.justpickup.orderservice.domain.order.repository;
|
||||
|
||||
import com.justpickup.orderservice.domain.order.dto.OrderMainResult;
|
||||
import com.justpickup.orderservice.domain.order.dto.OrderSearchCondition;
|
||||
import com.justpickup.orderservice.domain.order.dto.PrevOrderSearch;
|
||||
import com.justpickup.orderservice.domain.order.entity.Order;
|
||||
@@ -36,22 +37,33 @@ public class OrderRepositoryCustom {
|
||||
ORDER BY id desc
|
||||
LIMIT 페이지 사이즈
|
||||
*/
|
||||
public List<Order> findOrderMain(OrderSearchCondition condition, Long storeId) {
|
||||
public OrderMainResult findOrderMain(OrderSearchCondition condition, Long storeId) {
|
||||
LocalDateTime start = condition.getOrderStartTime();
|
||||
LocalDateTime end = condition.getOrderEndTime();
|
||||
int pageSize = 6;
|
||||
|
||||
return queryFactory
|
||||
List<Order> orders = queryFactory
|
||||
.selectFrom(order)
|
||||
.join(order.transaction).fetchJoin()
|
||||
.where(
|
||||
order.orderTime.between(start, end),
|
||||
order.storeId.eq(storeId),
|
||||
orderIdLt(condition.getLastOrderId())
|
||||
orderIdLt(condition.getLastOrderId()),
|
||||
order.orderTime.between(start, end),
|
||||
order.storeId.eq(storeId),
|
||||
order.orderStatus.ne(OrderStatus.PENDING),
|
||||
order.orderStatus.ne(OrderStatus.FAIL)
|
||||
)
|
||||
.orderBy(order.orderTime.desc())
|
||||
.limit(6)
|
||||
.orderBy(order.id.desc())
|
||||
.limit(pageSize + 1)
|
||||
.distinct()
|
||||
.fetch();
|
||||
|
||||
boolean hasNext = false;
|
||||
if (orders.size() > pageSize) {
|
||||
orders.remove(pageSize);
|
||||
hasNext = true;
|
||||
}
|
||||
|
||||
return OrderMainResult.of(orders, hasNext);
|
||||
}
|
||||
|
||||
private BooleanExpression orderIdLt(Long lastOrderId) {
|
||||
@@ -124,4 +136,5 @@ public class OrderRepositoryCustom {
|
||||
.fetchOne());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,20 +2,22 @@ package com.justpickup.orderservice.domain.order.service;
|
||||
|
||||
import com.justpickup.orderservice.domain.order.dto.FetchOrderDto;
|
||||
import com.justpickup.orderservice.domain.order.dto.OrderDto;
|
||||
import com.justpickup.orderservice.domain.order.dto.OrderMainDto;
|
||||
import com.justpickup.orderservice.domain.order.dto.OrderSearchCondition;
|
||||
import com.justpickup.orderservice.domain.order.dto.PrevOrderSearch;
|
||||
import com.justpickup.orderservice.domain.order.entity.OrderStatus;
|
||||
import com.justpickup.orderservice.domain.orderItem.dto.OrderItemDto;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.SliceImpl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface OrderService {
|
||||
List<OrderDto> findOrderMain(OrderSearchCondition condition, Long storeId);
|
||||
OrderMainDto findOrderMain(OrderSearchCondition condition, Long storeId);
|
||||
Page<OrderDto> findPrevOrderMain(PrevOrderSearch search, Pageable pageable, Long storeId);
|
||||
SliceImpl<OrderDto> findOrderHistory(Pageable pageable, Long userId);
|
||||
void addItemToBasket(OrderItemDto orderItemDto,Long storeId, Long userId);
|
||||
FetchOrderDto fetchOrder(Long userId);
|
||||
void saveOrder(Long userId);
|
||||
|
||||
void modifyOrder(Long userId, OrderStatus orderStatus);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.justpickup.orderservice.domain.order.service;
|
||||
|
||||
import com.justpickup.orderservice.domain.order.dto.FetchOrderDto;
|
||||
import com.justpickup.orderservice.domain.order.dto.OrderDto;
|
||||
import com.justpickup.orderservice.domain.order.dto.OrderSearchCondition;
|
||||
import com.justpickup.orderservice.domain.order.dto.PrevOrderSearch;
|
||||
import com.justpickup.orderservice.domain.order.dto.*;
|
||||
import com.justpickup.orderservice.domain.order.entity.Order;
|
||||
import com.justpickup.orderservice.domain.order.entity.OrderStatus;
|
||||
import com.justpickup.orderservice.domain.order.exception.OrderException;
|
||||
@@ -11,14 +8,8 @@ import com.justpickup.orderservice.domain.order.repository.OrderRepository;
|
||||
import com.justpickup.orderservice.domain.order.repository.OrderRepositoryCustom;
|
||||
import com.justpickup.orderservice.domain.orderItem.dto.OrderItemDto;
|
||||
import com.justpickup.orderservice.domain.orderItem.entity.OrderItem;
|
||||
import com.justpickup.orderservice.domain.orderItem.repository.OrderItemRepository;
|
||||
import com.justpickup.orderservice.domain.orderItemOption.entity.OrderItemOption;
|
||||
import com.justpickup.orderservice.domain.orderItemOption.repository.OrderItemOptionRepository;
|
||||
import com.justpickup.orderservice.global.client.store.GetItemResponse;
|
||||
import com.justpickup.orderservice.global.client.store.StoreClient;
|
||||
import com.justpickup.orderservice.global.client.user.GetCustomerResponse;
|
||||
import com.justpickup.orderservice.global.client.user.UserClient;
|
||||
import lombok.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -29,7 +20,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -38,28 +30,18 @@ import java.util.stream.Collectors;
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
|
||||
private final OrderRepository orderRepository;
|
||||
private final OrderItemRepository orderItemRepository;
|
||||
private final OrderItemOptionRepository orderItemOptionRepository;
|
||||
private final OrderRepositoryCustom orderRepositoryCustom;
|
||||
private final StoreClient storeClient;
|
||||
private final UserClient userClient;
|
||||
private final OrderSender orderSender;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<OrderDto> findOrderMain(OrderSearchCondition condition, Long storeId) {
|
||||
public OrderMainDto findOrderMain(OrderSearchCondition condition, Long storeId) {
|
||||
// 주문 가져오기
|
||||
List<OrderDto> orderDtoList =
|
||||
orderRepositoryCustom.findOrderMain(condition, storeId)
|
||||
.stream()
|
||||
.map(OrderDto::createFullField)
|
||||
.collect(Collectors.toList());
|
||||
OrderMainResult orderMainResult = orderRepositoryCustom.findOrderMain(condition, storeId);
|
||||
|
||||
// 사용자명 및 아이템 이름 가져오기
|
||||
// getUserNameAndItemName(orderDtoList);
|
||||
|
||||
return orderDtoList;
|
||||
return OrderMainDto.of(orderMainResult.getOrders(), orderMainResult.isHasNext());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,7 +51,7 @@ public class OrderServiceImpl implements OrderService {
|
||||
List<OrderDto> orderDtoList = orderPage.getContent()
|
||||
.stream()
|
||||
.map(OrderDto::createFullField)
|
||||
.collect(Collectors.toList());
|
||||
.collect(toList());
|
||||
|
||||
// 사용자명 및 아이템 이름 가져오기
|
||||
// getUserNameAndItemName(orderDtoList);
|
||||
@@ -84,28 +66,13 @@ public class OrderServiceImpl implements OrderService {
|
||||
List<OrderDto> contents = orderHistory.getContent()
|
||||
.stream()
|
||||
.map(OrderDto::createFullField)
|
||||
.collect(Collectors.toList());
|
||||
.collect(toList());
|
||||
|
||||
// TODO: 2022/03/07 Feign Client 통신
|
||||
|
||||
return new SliceImpl<>(contents, pageable, orderHistory.hasNext());
|
||||
}
|
||||
|
||||
private void getUserNameAndItemName(List<OrderDto> orderDtoList) {
|
||||
orderDtoList.forEach(orderDto -> {
|
||||
GetCustomerResponse getCustomerResponse =
|
||||
userClient.getUser(orderDto.getUserId()).getData();
|
||||
orderDto.setUserName(getCustomerResponse.getUserName());
|
||||
|
||||
orderDto.getOrderItemDtoList()
|
||||
.forEach(orderItemDto -> {
|
||||
GetItemResponse getItemResponse =
|
||||
storeClient.getItem(orderItemDto.getItemId()).getData();
|
||||
orderItemDto.setItemName(getItemResponse.getName());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void addItemToBasket(OrderItemDto orderItemDto,Long storeId, Long userId) {
|
||||
@@ -113,7 +80,7 @@ public class OrderServiceImpl implements OrderService {
|
||||
//orderItemOption Entity를 생성한다.
|
||||
List<OrderItemOption> orderItemOptions = orderItemDto.getOrderItemOptionDtoList()
|
||||
.stream().map(orderItemOptionDto -> OrderItemOption.of(orderItemDto.getId()))
|
||||
.collect(Collectors.toList());
|
||||
.collect(toList());
|
||||
|
||||
//orderItem을 Entity를 생성한다.
|
||||
OrderItem orderItem = OrderItem.of(orderItemDto.getItemId()
|
||||
@@ -155,7 +122,13 @@ public class OrderServiceImpl implements OrderService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void modifyOrder(Long orderId, OrderStatus orderStatus) {
|
||||
Order order = orderRepository.findById(orderId)
|
||||
.orElseThrow(() -> new OrderException(orderId + "는 없는 주문 번호입니다."));
|
||||
|
||||
|
||||
order.setOrderStatus(orderStatus);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
package com.justpickup.orderservice.domain.order.web;
|
||||
|
||||
import com.justpickup.orderservice.domain.order.entity.OrderStatus;
|
||||
import com.justpickup.orderservice.domain.order.exception.OrderException;
|
||||
import com.justpickup.orderservice.domain.order.service.OrderService;
|
||||
import com.justpickup.orderservice.global.dto.Result;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PatchMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@@ -9,4 +19,23 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@Slf4j
|
||||
public class OrderController {
|
||||
|
||||
private final OrderService orderService;
|
||||
|
||||
@PatchMapping("/order/{orderId}")
|
||||
public ResponseEntity<Result> patchOrder(@PathVariable("orderId") Long orderId,
|
||||
@RequestBody PatchOrderRequest patchOrderRequest) {
|
||||
OrderStatus orderStatus = patchOrderRequest.getOrderStatus();
|
||||
if (orderStatus != OrderStatus.PLACED && orderStatus != OrderStatus.REJECT) {
|
||||
throw new OrderException("주문 수락, 거절 외에는 변경 불가능합니다.");
|
||||
}
|
||||
|
||||
orderService.modifyOrder(orderId, orderStatus);
|
||||
|
||||
return ResponseEntity.ok(Result.createSuccessResult(null));
|
||||
}
|
||||
|
||||
@Data @NoArgsConstructor
|
||||
static class PatchOrderRequest {
|
||||
private OrderStatus orderStatus;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.justpickup.orderservice.domain.order.web;
|
||||
|
||||
import com.justpickup.orderservice.domain.order.dto.OrderDto;
|
||||
import com.justpickup.orderservice.domain.order.dto.OrderMainDto;
|
||||
import com.justpickup.orderservice.domain.order.dto.OrderSearchCondition;
|
||||
import com.justpickup.orderservice.domain.order.dto.PrevOrderSearch;
|
||||
import com.justpickup.orderservice.domain.order.entity.OrderStatus;
|
||||
@@ -27,7 +28,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import javax.validation.Valid;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/owner/order")
|
||||
@@ -40,56 +42,59 @@ public class OrderOwnerApiController {
|
||||
|
||||
@GetMapping("/order-main")
|
||||
public ResponseEntity<Result> orderMain(@Valid OrderSearchCondition condition) {
|
||||
// TODO: 2022/03/10 Feign client storeId 가져오기 구현 필요
|
||||
Long userId = 1L;
|
||||
Long storeId = 1L;
|
||||
|
||||
List<OrderDto> orderDto = orderService.findOrderMain(condition, storeId);
|
||||
OrderMainDto orderMainDto = orderService.findOrderMain(condition, storeId);
|
||||
|
||||
List<OrderMainResponse> orderMainResponses = orderDto.stream()
|
||||
.map(OrderMainResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
OrderMainResponse orderMainResponse = new OrderMainResponse(orderMainDto);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(Result.createSuccessResult(orderMainResponses));
|
||||
.body(Result.createSuccessResult(orderMainResponse));
|
||||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data @NoArgsConstructor
|
||||
static class OrderMainResponse {
|
||||
private Long orderId;
|
||||
private Long userId;
|
||||
private String userName;
|
||||
private List<OrderItemResponse> orderItemResponses;
|
||||
private OrderStatus orderStatus;
|
||||
private String orderTime;
|
||||
private boolean hasNext;
|
||||
private List<_Order> orders;
|
||||
|
||||
public OrderMainResponse(OrderDto orderDto) {
|
||||
List<OrderItemResponse> orderItemDtoList = orderDto.getOrderItemDtoList()
|
||||
public OrderMainResponse(OrderMainDto orderMainDto) {
|
||||
this.hasNext = orderMainDto.isHasNext();
|
||||
this.orders = orderMainDto.getOrders()
|
||||
.stream()
|
||||
.map(OrderItemResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
this.orderId = orderDto.getId();
|
||||
this.userId = orderDto.getUserId();
|
||||
this.userName = orderDto.getUserName();
|
||||
this.orderItemResponses = orderItemDtoList;
|
||||
this.orderStatus = orderDto.getOrderStatus();
|
||||
this.orderTime = orderDto.getOrderTime()
|
||||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
.map(_Order::new)
|
||||
.collect(toList());
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
static class OrderItemResponse {
|
||||
private Long orderItemId;
|
||||
private Long itemId;
|
||||
private String itemName;
|
||||
@Data
|
||||
static class _Order {
|
||||
private Long id;
|
||||
private String orderTime;
|
||||
private String orderStatus;
|
||||
private String userName;
|
||||
private String storeName;
|
||||
private List<_OrderItem> orderItems;
|
||||
|
||||
public OrderItemResponse(OrderItemDto orderItemDto) {
|
||||
this.orderItemId = orderItemDto.getId();
|
||||
this.itemId = orderItemDto.getItemId();
|
||||
this.itemName = orderItemDto.getItemName();
|
||||
public _Order(OrderMainDto._Order order) {
|
||||
this.id = order.getId();
|
||||
this.orderTime = order.getOrderTime()
|
||||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
|
||||
this.orderStatus = order.getOrderStatus().name();
|
||||
this.userName = order.getUserName();
|
||||
this.storeName = order.getStoreName();
|
||||
this.orderItems = order.getOrderItems()
|
||||
.stream().map(_OrderItem::new).collect(toList());
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
static class _OrderItem {
|
||||
private String itemName;
|
||||
|
||||
public _OrderItem(OrderMainDto._OrderItem orderItem) {
|
||||
this.itemName = orderItem.getItemName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +122,7 @@ public class OrderOwnerApiController {
|
||||
private Page page;
|
||||
|
||||
public ResponsePrevOrder(List<OrderDto> orderDtoList, int startPage, int totalPage) {
|
||||
orders = orderDtoList.stream().map(OrderVo::new).collect(Collectors.toList());
|
||||
orders = orderDtoList.stream().map(OrderVo::new).collect(toList());
|
||||
page = new Page(startPage, totalPage);
|
||||
}
|
||||
|
||||
@@ -137,7 +142,7 @@ public class OrderOwnerApiController {
|
||||
this.orderPrice = orderDto.getOrderPrice();
|
||||
this.userName = orderDto.getUserName();
|
||||
this.orderItems = orderDto.getOrderItemDtoList()
|
||||
.stream().map(OrderItemVo::new).collect(Collectors.toList());
|
||||
.stream().map(OrderItemVo::new).collect(toList());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.justpickup.orderservice.domain.order.web;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.justpickup.orderservice.config.TestConfig;
|
||||
import com.justpickup.orderservice.domain.order.entity.OrderStatus;
|
||||
import com.justpickup.orderservice.domain.order.repository.OrderRepository;
|
||||
import com.justpickup.orderservice.domain.order.service.OrderService;
|
||||
import com.justpickup.orderservice.domain.order.web.OrderController.PatchOrderRequest;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.patch;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(OrderController.class)
|
||||
@Import(TestConfig.class)
|
||||
@AutoConfigureRestDocs(uriHost = "http://just-pickup.com", uriPort = 8001)
|
||||
class OrderControllerTest {
|
||||
|
||||
@Autowired
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
@Autowired
|
||||
MockMvc mockMvc;
|
||||
|
||||
@MockBean
|
||||
OrderService orderService;
|
||||
|
||||
@MockBean
|
||||
OrderRepository orderRepository;
|
||||
|
||||
@Test
|
||||
@DisplayName("[PATCH] 주문 수정")
|
||||
public void patchOrder() throws Exception {
|
||||
// GIVEN
|
||||
Long orderId = 1L;
|
||||
OrderStatus orderStatus = OrderStatus.PLACED;
|
||||
PatchOrderRequest request = new PatchOrderRequest(orderStatus);
|
||||
String requestBody = objectMapper.writeValueAsString(request);
|
||||
|
||||
// WHEN
|
||||
ResultActions actions = mockMvc.perform(patch("/order/{orderId}", String.valueOf(orderId))
|
||||
.content(requestBody)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
);
|
||||
|
||||
// THEN
|
||||
actions.andExpect(status().isOk())
|
||||
.andDo(print())
|
||||
.andDo(document("order-patch",
|
||||
pathParameters(
|
||||
parameterWithName("orderId").description("주문 고유번호")
|
||||
),
|
||||
requestFields(
|
||||
fieldWithPath("orderStatus").description("주문 상태")
|
||||
),
|
||||
responseFields(
|
||||
fieldWithPath("code").description("결과코드 SUCCESS/ERROR"),
|
||||
fieldWithPath("message").description("메시지"),
|
||||
fieldWithPath("data").description("데이터")
|
||||
)
|
||||
))
|
||||
;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,9 @@ package com.justpickup.orderservice.domain.order.web;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.justpickup.orderservice.config.TestConfig;
|
||||
import com.justpickup.orderservice.domain.order.dto.OrderDto;
|
||||
import com.justpickup.orderservice.domain.order.dto.OrderMainDto;
|
||||
import com.justpickup.orderservice.domain.order.dto.OrderMainDto._Order;
|
||||
import com.justpickup.orderservice.domain.order.dto.OrderMainDto._OrderItem;
|
||||
import com.justpickup.orderservice.domain.order.dto.OrderSearchCondition;
|
||||
import com.justpickup.orderservice.domain.order.dto.PrevOrderSearch;
|
||||
import com.justpickup.orderservice.domain.order.entity.OrderStatus;
|
||||
@@ -27,6 +30,7 @@ import org.springframework.test.web.servlet.ResultActions;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@@ -74,7 +78,7 @@ class OrderOwnerApiControllerTest {
|
||||
Long storeId = 1L;
|
||||
|
||||
given(orderService.findOrderMain(condition, storeId))
|
||||
.willReturn(getOrderMainDtoList());
|
||||
.willReturn(getWillReturnOrderMain());
|
||||
|
||||
// WHEN
|
||||
|
||||
@@ -87,10 +91,9 @@ class OrderOwnerApiControllerTest {
|
||||
actions.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("code").value(Code.SUCCESS.name()))
|
||||
.andExpect(jsonPath("message").isEmpty())
|
||||
.andExpect(jsonPath("data").exists())
|
||||
.andExpect(jsonPath("data[*].orderItemResponses").exists())
|
||||
.andExpect(jsonPath("data[*].orderStatus").exists())
|
||||
.andExpect(jsonPath("data[*].orderTime").exists())
|
||||
.andExpect(jsonPath("data.hasNext").exists())
|
||||
.andExpect(jsonPath("data.orders").exists())
|
||||
.andExpect(jsonPath("data.orders[*].orderItems").exists())
|
||||
.andDo(print())
|
||||
.andDo(document("orderMain-get",
|
||||
requestParameters(
|
||||
@@ -100,19 +103,39 @@ class OrderOwnerApiControllerTest {
|
||||
responseFields(
|
||||
fieldWithPath("code").description("결과 코드 SUCCESS/ERROR"),
|
||||
fieldWithPath("message").description("메시지"),
|
||||
fieldWithPath("data[*].orderId").description("주문 고유 번호"),
|
||||
fieldWithPath("data[*].userId").description("고객 고유 번호"),
|
||||
fieldWithPath("data[*].userName").description("고객 이름"),
|
||||
fieldWithPath("data[*].orderItemResponses[*].orderItemId").description("장바구니 고유번호"),
|
||||
fieldWithPath("data[*].orderItemResponses[*].itemId").description("상품 고유번호"),
|
||||
fieldWithPath("data[*].orderItemResponses[*].itemName").description("상품 이름"),
|
||||
fieldWithPath("data[*].orderStatus").description("주문 상태"),
|
||||
fieldWithPath("data[*].orderTime").description("주문 시간")
|
||||
fieldWithPath("data.hasNext").description("다음 게시물 표시 여부"),
|
||||
fieldWithPath("data.orders[*].id").description("주문 고유번호"),
|
||||
fieldWithPath("data.orders[*].orderTime").description("주문 시간 [yyyy-MM-dd HH:mm]"),
|
||||
fieldWithPath("data.orders[*].orderStatus").description("주문 상태"),
|
||||
fieldWithPath("data.orders[*].userName").description("주문한 사용자 이름"),
|
||||
fieldWithPath("data.orders[*].storeName").description("가게 이름"),
|
||||
fieldWithPath("data.orders[*].orderItems[*].itemName").description("아이템 이름")
|
||||
)
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
private OrderMainDto getWillReturnOrderMain() {
|
||||
List<_Order> orders = new ArrayList<>();
|
||||
for (long i = 1; i <= 6; i++) {
|
||||
List<_OrderItem> orderItems = new ArrayList<>();
|
||||
for (long j = 10; j <= 12; j++) {
|
||||
_OrderItem orderItem = _OrderItem.builder()
|
||||
.id(j)
|
||||
.itemId(j)
|
||||
.itemName("아이템" + i * j).build();
|
||||
orderItems.add(orderItem);
|
||||
}
|
||||
|
||||
_Order order = _Order.builder()
|
||||
.id(i).userId(i + 10).orderStatus(OrderStatus.ORDER)
|
||||
.orderTime(LocalDateTime.now()).orderItems(orderItems).storeName("가게명" + i)
|
||||
.build();
|
||||
orders.add(order);
|
||||
}
|
||||
return OrderMainDto.builder().orders(orders).hasNext(true).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("[API] [GET] 점주 서비스 - 주문 페이지 (잘못된 파라미터 형식)")
|
||||
void getOrderMainBadRequestException() throws Exception {
|
||||
@@ -181,7 +204,7 @@ class OrderOwnerApiControllerTest {
|
||||
.id(2L)
|
||||
.userId(1L)
|
||||
.orderItemDtoList(List.of(orderItemDto_102, orderItemDto_103))
|
||||
.orderStatus(OrderStatus.CANCELED)
|
||||
.orderStatus(OrderStatus.FAIL)
|
||||
.orderTime(LocalDateTime.of(2022, 2, 3, 15, 0, 0))
|
||||
.build();
|
||||
orderDto_2.setUserName("닉네임");
|
||||
|
||||
@@ -9,7 +9,7 @@ export default {
|
||||
page: page
|
||||
}
|
||||
}
|
||||
return axios.get( process.env.VUE_APP_ORDER_URL + "/order/prev-order", options);
|
||||
return axios.get( process.env.VUE_APP_API_URL + "/order/prev-order", options);
|
||||
},
|
||||
requestOrder(orderDate, lastOrderId) {
|
||||
const options = {
|
||||
@@ -18,6 +18,12 @@ export default {
|
||||
lastOrderId: lastOrderId
|
||||
}
|
||||
}
|
||||
return axios.get(process.env.VUE_APP_ORDER_URL + "/order/order-main", options);
|
||||
return axios.get(process.env.VUE_APP_API_URL + "/order/order-main", options);
|
||||
},
|
||||
patchOrder(orderId, orderStatus) {
|
||||
const body = {
|
||||
orderStatus: orderStatus
|
||||
}
|
||||
return axios.patch(process.env.VUE_APP_OWNER_SERVICE_BASEURL + "/order-service/order/" + orderId, body);
|
||||
}
|
||||
}
|
||||
@@ -9,19 +9,44 @@
|
||||
<v-card-subtitle></v-card-subtitle>
|
||||
<v-card-text>{{ orderTime }}</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-btn v-if="orderStatus === 'PENDING'"
|
||||
block depressed color="primary">
|
||||
주문 대기
|
||||
</v-btn>
|
||||
<v-btn v-else-if="orderStatus === 'PLACED'"
|
||||
block depressed color="primary">
|
||||
주문 수령
|
||||
</v-btn>
|
||||
<v-row v-if="orderStatus === 'ORDER'">
|
||||
<v-col sm="6">
|
||||
<v-btn
|
||||
block depressed color="success"
|
||||
@click="placed"
|
||||
>
|
||||
주문 수령
|
||||
</v-btn>
|
||||
</v-col>
|
||||
<v-col sm="6">
|
||||
<v-btn block depressed color="error"
|
||||
@click="reject"
|
||||
>
|
||||
주문 거절
|
||||
</v-btn>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row v-else-if="orderStatus === 'PLACED'">
|
||||
<v-col>
|
||||
<v-btn block depressed color="primary">
|
||||
수락됨
|
||||
</v-btn>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row v-else-if="orderStatus === 'REJECT'">
|
||||
<v-col>
|
||||
<v-btn block depressed color="blue-grey" class="white--text">
|
||||
거절됨
|
||||
</v-btn>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import orderApi from "../api/order";
|
||||
|
||||
export default {
|
||||
name: "OrderCard",
|
||||
data: function() {
|
||||
@@ -30,11 +55,32 @@ export default {
|
||||
};
|
||||
},
|
||||
props: {
|
||||
orderId: Number,
|
||||
id: Number,
|
||||
userName: Number,
|
||||
itemNames: [],
|
||||
orderTime: String,
|
||||
orderStatus: String
|
||||
},
|
||||
methods: {
|
||||
placed: async function() {
|
||||
try {
|
||||
await orderApi.patchOrder(this.id, 'PLACED');
|
||||
this.$emit("placed");
|
||||
alert("해당 주문이 수락 되었습니다.");
|
||||
} catch(error) {
|
||||
console.log(error);
|
||||
}
|
||||
},
|
||||
reject: async function() {
|
||||
try {
|
||||
await orderApi.patchOrder(this.id, 'REJECT');
|
||||
this.$emit("reject");
|
||||
alert("해당 주문이 거절 되었습니다.");
|
||||
|
||||
} catch(error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -15,18 +15,20 @@
|
||||
<v-row>
|
||||
<v-col v-for="card in cards" cols="4" :key="card.orderId">
|
||||
<order-card
|
||||
:order-id="card.orderId"
|
||||
:id="card.orderId"
|
||||
:userName="card.userName"
|
||||
:itemNames="card.itemNames"
|
||||
:orderTime="card.orderTime"
|
||||
:orderStatus="card.orderStatus"
|
||||
@placed="card.orderStatus = 'PLACED'"
|
||||
@reject="card.orderStatus = 'REJECT'"
|
||||
>
|
||||
</order-card>
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
<br><br><br>
|
||||
<v-row justify="center" v-if="showButton">
|
||||
<v-row justify="center" v-if="hasNext">
|
||||
<v-btn rounded outlined color="primary"
|
||||
@click="more">더보기</v-btn>
|
||||
</v-row>
|
||||
@@ -53,45 +55,38 @@ export default {
|
||||
date: '',
|
||||
cards: [],
|
||||
lastOrderId: null,
|
||||
showButton: false
|
||||
hasNext: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
search: function() {
|
||||
search: async function() {
|
||||
this.cards = [];
|
||||
this.lastOrderId = null;
|
||||
OrderApi.requestOrder(this.date, this.lastOrderId)
|
||||
.then( (response) => {
|
||||
this.renderCard(response.data);
|
||||
})
|
||||
.catch( (error) => {
|
||||
console.log(error);
|
||||
})
|
||||
|
||||
const response = await OrderApi.requestOrder(this.date, this.lastOrderId);
|
||||
|
||||
this.renderCard(response.data)
|
||||
},
|
||||
renderCard: function (json) {
|
||||
const orders = json.data;
|
||||
console.log(json);
|
||||
const orders = json.data.orders;
|
||||
const size = orders.length;
|
||||
|
||||
if (size === 0) {
|
||||
alert("검색 데이터가 없습니다.");
|
||||
this.showButton = false;
|
||||
} else {
|
||||
this.showButton = true;
|
||||
}
|
||||
this.hasNext = json.data.hasNext;
|
||||
|
||||
orders.forEach( (order, index) => {
|
||||
if (index === (size - 1)) {
|
||||
this.lastOrderId = order.orderId;
|
||||
this.lastOrderId = order.id;
|
||||
}
|
||||
|
||||
let orderItemNames = []
|
||||
order.orderItemResponses.forEach( (orderItem) => {
|
||||
orderItemNames.push(orderItem.itemId);
|
||||
let orderItemNames = [];
|
||||
order.orderItems.forEach( (orderItem) => {
|
||||
orderItemNames.push(orderItem.itemName);
|
||||
})
|
||||
|
||||
this.cards.push({
|
||||
orderId: order.orderId,
|
||||
userName: order.orderId,
|
||||
orderId: order.id,
|
||||
userName: order.userName,
|
||||
itemNames: orderItemNames,
|
||||
orderTime: order.orderTime,
|
||||
orderStatus: order.orderStatus
|
||||
@@ -101,14 +96,9 @@ export default {
|
||||
inputDate: function(value) {
|
||||
this.date = value;
|
||||
},
|
||||
more: function() {
|
||||
OrderApi.requestOrder(this.date, this.lastOrderId)
|
||||
.then( (response) => {
|
||||
this.renderCard(response.data);
|
||||
})
|
||||
.catch( (error) => {
|
||||
console.log(error);
|
||||
})
|
||||
more: async function() {
|
||||
const response = await OrderApi.requestOrder(this.date, this.lastOrderId);
|
||||
this.renderCard(response.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user