feat(customer-vue, order service): 장바구니 아이템 삭제기능 추가
- 장바구니 아이템 삭제기능 추가
This commit is contained in:
@@ -24,5 +24,8 @@ export default {
|
|||||||
getOrder() {
|
getOrder() {
|
||||||
return axios.get(process.env.VUE_APP_ORDER_API_URL + "/order/orders");
|
return axios.get(process.env.VUE_APP_ORDER_API_URL + "/order/orders");
|
||||||
},
|
},
|
||||||
|
deleteOrderItem(orderItemId){
|
||||||
|
return axios.delete(process.env.VUE_APP_ORDER_API_URL + "/orderItem/"+orderItemId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -64,12 +64,12 @@ const routes = [
|
|||||||
name: 'notification',
|
name: 'notification',
|
||||||
component: () => import('../views/NotificationView')
|
component: () => import('../views/NotificationView')
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
path: "/item/:itemId",
|
// path: "/item/:itemId",
|
||||||
beforeEnter: authCheck,
|
// beforeEnter: authCheck,
|
||||||
name: 'itemDetail',
|
// name: 'itemDetail',
|
||||||
component: () => import('../views/ItemDetail')
|
// component: () => import('../views/ItemDetail')
|
||||||
},
|
// },
|
||||||
{
|
{
|
||||||
path: "/order",
|
path: "/order",
|
||||||
beforeEnter: authCheck,
|
beforeEnter: authCheck,
|
||||||
@@ -103,6 +103,19 @@ const routes = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/item',
|
||||||
|
redirect: 'item',
|
||||||
|
component: StoreLayout,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: "/item/:itemId",
|
||||||
|
beforeEnter: authCheck,
|
||||||
|
name: 'itemDetail',
|
||||||
|
component: () => import('../views/ItemDetail')
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/auth',
|
path: '/auth',
|
||||||
name: 'auth',
|
name: 'auth',
|
||||||
|
|||||||
@@ -8,17 +8,6 @@
|
|||||||
<router-view
|
<router-view
|
||||||
v-on:getStoreId="renderNavigation">
|
v-on:getStoreId="renderNavigation">
|
||||||
</router-view>
|
</router-view>
|
||||||
<div align="right" >
|
|
||||||
<v-btn
|
|
||||||
color="primary"
|
|
||||||
dark
|
|
||||||
right
|
|
||||||
fab
|
|
||||||
@click="toOrder"
|
|
||||||
>
|
|
||||||
<v-icon>mdi-basket</v-icon>
|
|
||||||
</v-btn>
|
|
||||||
</div>
|
|
||||||
</v-container>
|
</v-container>
|
||||||
</v-main>
|
</v-main>
|
||||||
<bottom-navigation></bottom-navigation>
|
<bottom-navigation></bottom-navigation>
|
||||||
@@ -56,11 +45,6 @@ export default {
|
|||||||
|
|
||||||
const response = await storeApi.requestStore(this.store.id);
|
const response = await storeApi.requestStore(this.store.id);
|
||||||
this.store = response.data.data;
|
this.store = response.data.data;
|
||||||
},
|
|
||||||
toOrder(){
|
|
||||||
if(confirm("주문화면으로 이동할까요?")){
|
|
||||||
this.$router.push("/order")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
</v-list-item>
|
</v-list-item>
|
||||||
|
|
||||||
<v-card-actions class="pb-2">
|
<v-card-actions class="pb-2">
|
||||||
<v-btn block color="warning" @click="message('준비중입니다.')">삭제하기</v-btn>
|
<v-btn block color="warning" @click="deleteOrderItem(orderItem)">삭제하기</v-btn>
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
|
|
||||||
</v-card>
|
</v-card>
|
||||||
@@ -98,7 +98,6 @@ export default {
|
|||||||
getOrder: function(){
|
getOrder: function(){
|
||||||
orderApi.getOrder()
|
orderApi.getOrder()
|
||||||
.then(response=>{
|
.then(response=>{
|
||||||
console.log(response)
|
|
||||||
this.orderData=response.data.data
|
this.orderData=response.data.data
|
||||||
})
|
})
|
||||||
.catch(error=>{
|
.catch(error=>{
|
||||||
@@ -107,9 +106,27 @@ export default {
|
|||||||
console.log(error.response)
|
console.log(error.response)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
message: function(message){
|
deleteOrderItem: function(orderItem){
|
||||||
alert(message)
|
var vm = this
|
||||||
}
|
const deleteOrderItemId = orderItem.id
|
||||||
|
console.log(deleteOrderItemId)
|
||||||
|
orderApi.deleteOrderItem(deleteOrderItemId)
|
||||||
|
.then(response=>{
|
||||||
|
console.log(response)
|
||||||
|
alert(response.data.data+"삭제되었습니다.")
|
||||||
|
vm.orderData.orderPrice -=orderItem.price
|
||||||
|
vm.orderData.orderItemDtoList.splice(
|
||||||
|
vm.orderData.orderItemDtoList.indexOf(orderItem),1
|
||||||
|
)
|
||||||
|
if(vm.orderData.orderItemDtoList.length ==0)
|
||||||
|
this.$router.back()
|
||||||
|
})
|
||||||
|
.catch(error=>{
|
||||||
|
alert("문제가 발생하였습니다.")
|
||||||
|
console.log(error.response)
|
||||||
|
})
|
||||||
|
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -54,6 +54,17 @@
|
|||||||
<br>
|
<br>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div align="right" >
|
||||||
|
<v-btn
|
||||||
|
color="primary"
|
||||||
|
dark
|
||||||
|
right
|
||||||
|
fab
|
||||||
|
@click="toOrder"
|
||||||
|
>
|
||||||
|
<v-icon>mdi-basket</v-icon>
|
||||||
|
</v-btn>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -94,6 +105,11 @@ export default {
|
|||||||
},
|
},
|
||||||
itemDetail: function (itemId) {
|
itemDetail: function (itemId) {
|
||||||
this.$router.push("/item/"+itemId)
|
this.$router.push("/item/"+itemId)
|
||||||
|
},
|
||||||
|
toOrder(){
|
||||||
|
if(confirm("주문화면으로 이동할까요?")){
|
||||||
|
this.$router.push("/order")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class Order extends BaseEntity {
|
|||||||
private Transaction transaction;
|
private Transaction transaction;
|
||||||
|
|
||||||
@BatchSize(size = 100)
|
@BatchSize(size = 100)
|
||||||
@OneToMany(mappedBy = "order", cascade = CascadeType.ALL)
|
@OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
private List<OrderItem> orderItems = new ArrayList<>();
|
private List<OrderItem> orderItems = new ArrayList<>();
|
||||||
|
|
||||||
public static Order of(Long userId, Long userCouponId, Long storeId, OrderItem orderItem) {
|
public static Order of(Long userId, Long userCouponId, Long storeId, OrderItem orderItem) {
|
||||||
@@ -83,6 +83,13 @@ public class Order extends BaseEntity {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Order deleteOrderItem(OrderItem orderItem) {
|
||||||
|
this.orderPrice -= orderItem.getTotalPrice();
|
||||||
|
this.orderItems.remove(orderItem);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public void setOrderStatus(OrderStatus orderStatus){
|
public void setOrderStatus(OrderStatus orderStatus){
|
||||||
this.orderStatus = orderStatus;
|
this.orderStatus = orderStatus;
|
||||||
}
|
}
|
||||||
@@ -105,4 +112,9 @@ public class Order extends BaseEntity {
|
|||||||
public void fail() {
|
public void fail() {
|
||||||
this.orderStatus = OrderStatus.FAILED;
|
this.orderStatus = OrderStatus.FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void changeOrderDate(LocalDateTime orderTime){
|
||||||
|
this.orderTime = orderTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface OrderRepository extends JpaRepository<Order, Long> {
|
public interface OrderRepository extends JpaRepository<Order, Long> {
|
||||||
|
Long countByUserIdAndOrderStatus(Long userId, OrderStatus orderStatus);
|
||||||
Optional<Order> findByUserIdAndOrderStatus(Long userId, OrderStatus orderStatus);
|
Optional<Order> findByUserIdAndOrderStatus(Long userId, OrderStatus orderStatus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,12 +175,16 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
//HARD_CODE
|
//HARD_CODE
|
||||||
Long userCouponId=0L;
|
Long userCouponId=0L;
|
||||||
|
|
||||||
|
Long countByUserIdAndOrderStatus = orderRepository.countByUserIdAndOrderStatus(userId, OrderStatus.PENDING);
|
||||||
|
if(countByUserIdAndOrderStatus>=2) throw new OrderException("장바구니 데이터는 2건 이상 일 수 없습니다.");
|
||||||
|
|
||||||
Optional<Order> optionalOrder = orderRepository.findByUserIdAndOrderStatus(userId, OrderStatus.PENDING);
|
Optional<Order> optionalOrder = orderRepository.findByUserIdAndOrderStatus(userId, OrderStatus.PENDING);
|
||||||
if(optionalOrder.isPresent()){
|
if(optionalOrder.isPresent()){
|
||||||
if(!optionalOrder.get().addOrderItem(orderItem)
|
if(!optionalOrder.get().addOrderItem(orderItem)
|
||||||
.getStoreId().equals(storeId))
|
.getStoreId().equals(storeId))
|
||||||
throw new OrderException("장바구니에 여러 카페의 메뉴를 담을수 없습니다.");
|
throw new OrderException("장바구니에 여러 카페의 메뉴를 담을수 없습니다.");
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
orderRepository.save(Order.of(userId,userCouponId,storeId,orderItem));
|
orderRepository.save(Order.of(userId,userCouponId,storeId,orderItem));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,6 +193,9 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
public FetchOrderDto fetchOrder(Long userId) {
|
public FetchOrderDto fetchOrder(Long userId) {
|
||||||
Order order = orderRepositoryCustom.fetchOrderBasket(userId)
|
Order order = orderRepositoryCustom.fetchOrderBasket(userId)
|
||||||
.orElseThrow(() -> new OrderException("장바구니 정보를 찾을 수 없습니다."));
|
.orElseThrow(() -> new OrderException("장바구니 정보를 찾을 수 없습니다."));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GetStoreResponse store = storeClient.getStore(String.valueOf(order.getStoreId())).getData();
|
GetStoreResponse store = storeClient.getStore(String.valueOf(order.getStoreId())).getData();
|
||||||
|
|
||||||
List<GetItemResponse> data = storeClient.getItemAndItemOptions(order.getOrderItems().stream()
|
List<GetItemResponse> data = storeClient.getItemAndItemOptions(order.getOrderItems().stream()
|
||||||
@@ -253,8 +260,6 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
// 일주일 판매금액( 일별 )
|
// 일주일 판매금액( 일별 )
|
||||||
List<DashBoardDto.SellAmountAWeek> sellAmountAWeeks = orderRepositoryCustom.salesAmountBetweenAWeek(storeId);
|
List<DashBoardDto.SellAmountAWeek> sellAmountAWeeks = orderRepositoryCustom.salesAmountBetweenAWeek(storeId);
|
||||||
|
|
||||||
log.info("asdad");
|
|
||||||
|
|
||||||
return DashBoardDto.of(orderPrices , bestSellItem, sellAmountAWeeks);
|
return DashBoardDto.of(orderPrices , bestSellItem, sellAmountAWeeks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.justpickup.orderservice.domain.orderItem.service;
|
||||||
|
|
||||||
|
import com.justpickup.orderservice.domain.order.entity.Order;
|
||||||
|
import com.justpickup.orderservice.domain.order.entity.OrderStatus;
|
||||||
|
import com.justpickup.orderservice.domain.order.exception.OrderException;
|
||||||
|
import com.justpickup.orderservice.domain.order.repository.OrderRepository;
|
||||||
|
import com.justpickup.orderservice.domain.order.repository.OrderRepositoryCustom;
|
||||||
|
import com.justpickup.orderservice.domain.orderItem.entity.OrderItem;
|
||||||
|
import com.justpickup.orderservice.domain.orderItem.repository.OrderItemRepository;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public class OrderItemService {
|
||||||
|
|
||||||
|
private final OrderItemRepository orderItemRepository;
|
||||||
|
private final OrderRepository orderRepository;
|
||||||
|
private final OrderRepositoryCustom orderRepositoryCustom;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void deleteOrderItem(Long deleteOrderItemId, Long userId){
|
||||||
|
|
||||||
|
|
||||||
|
Order order = orderRepositoryCustom.fetchOrderBasket(userId)
|
||||||
|
.orElseThrow(() -> new OrderException("존재하지 않는 장바구니 아이템입니다."));
|
||||||
|
|
||||||
|
OrderItem orderItem = orderItemRepository.findById(deleteOrderItemId)
|
||||||
|
.orElseThrow(() -> new OrderException("존재하지 않는 장바구니 아이템입니다."));
|
||||||
|
|
||||||
|
order.deleteOrderItem(orderItem);
|
||||||
|
|
||||||
|
if(order.getOrderItems().size() ==0)
|
||||||
|
orderRepository.delete(order);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.justpickup.orderservice.domain.orderItem.web;
|
||||||
|
|
||||||
|
import com.justpickup.orderservice.domain.orderItem.service.OrderItemService;
|
||||||
|
import com.justpickup.orderservice.global.dto.Result;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/api/customer/orderItem")
|
||||||
|
public class OrderItemCustomerApiController {
|
||||||
|
|
||||||
|
private final OrderItemService orderItemService;
|
||||||
|
|
||||||
|
@DeleteMapping("/{orderItemId}")
|
||||||
|
public ResponseEntity deleteOrderItem(@PathVariable Long orderItemId,
|
||||||
|
@RequestHeader(value = "user-id") String userId){
|
||||||
|
orderItemService.deleteOrderItem(orderItemId,Long.parseLong(userId));
|
||||||
|
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(Result.createSuccessResult(orderItemId));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user