From f577ef4d463db0e40fd3a2a66d6c8636f9036720 Mon Sep 17 00:00:00 2001 From: hequan_waynaqua <1669738430@qq.com> Date: Fri, 7 Aug 2020 11:59:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=89=8B=E6=9C=BA=E7=AB=AF):=20=E8=B4=AD?= =?UTF-8?q?=E7=89=A9=E8=BD=A6=E6=A8=A1=E5=9D=97=20=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/wayn/common/util/R.java | 5 ++++ .../mobile/api/controller/CartController.java | 29 ++++++++++--------- .../wayn/mobile/api/service/ICartService.java | 4 +++ .../api/service/impl/CartServiceImpl.java | 10 +++++++ 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/waynboot-common/src/main/java/com/wayn/common/util/R.java b/waynboot-common/src/main/java/com/wayn/common/util/R.java index cde3528..3c2ae59 100644 --- a/waynboot-common/src/main/java/com/wayn/common/util/R.java +++ b/waynboot-common/src/main/java/com/wayn/common/util/R.java @@ -37,6 +37,11 @@ public class R { return R.error(); } + public static R result(boolean b, String msg) { + if (b) return R.success(); + return R.error(msg); + } + public static R error(String msg) { R r = new R(); r.code = 500; diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CartController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CartController.java index 1fe1e9a..b4a770b 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CartController.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CartController.java @@ -1,26 +1,14 @@ package com.wayn.mobile.api.controller; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.wayn.common.base.BaseController; -import com.wayn.common.core.domain.shop.Goods; -import com.wayn.common.core.domain.shop.GoodsProduct; -import com.wayn.common.core.domain.system.User; -import com.wayn.common.core.service.shop.IGoodsProductService; -import com.wayn.common.core.service.shop.IGoodsService; import com.wayn.common.util.R; import com.wayn.mobile.api.domain.Cart; import com.wayn.mobile.api.service.ICartService; import com.wayn.mobile.framework.security.util.SecurityUtils; -import org.apache.commons.lang3.ObjectUtils; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import java.time.LocalDateTime; -import java.util.List; -import java.util.Objects; - /** *
* 购物车商品表 前端控制器
@@ -42,11 +30,26 @@ public class CartController extends BaseController {
return iCartService.list(userId);
}
- @PostMapping("add")
+ @PostMapping
public R add(@RequestBody Cart cart) {
return iCartService.addCart(cart);
}
+ @PutMapping
+ public R update(@RequestBody Cart cart) {
+ return R.result(iCartService.updateById(cart));
+ }
+
+ @PostMapping("addNum/{cartId}/{number}")
+ public R addNum(@PathVariable Long cartId, @PathVariable Integer number) {
+ return iCartService.addNum(cartId, number);
+ }
+
+ @PostMapping("minusNum/{cartId}/{number}")
+ public R minusNum(@PathVariable Long cartId, @PathVariable Integer number) {
+ return iCartService.minusNum(cartId, number);
+ }
+
@DeleteMapping("{cartId}")
public R delete(@PathVariable Long cartId) {
return R.result(iCartService.removeById(cartId));
diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/ICartService.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/ICartService.java
index c6b4695..4f92a53 100644
--- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/ICartService.java
+++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/ICartService.java
@@ -46,4 +46,8 @@ public interface ICartService extends IService