delete item from shopping cart
This commit is contained in:
@@ -48,6 +48,10 @@ public class ShoppingCartController {
|
|||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clean shopping cart
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@DeleteMapping("/clean")
|
@DeleteMapping("/clean")
|
||||||
@ApiOperation("clean the shopping cart")
|
@ApiOperation("clean the shopping cart")
|
||||||
public Result clean(){
|
public Result clean(){
|
||||||
@@ -55,4 +59,16 @@ public class ShoppingCartController {
|
|||||||
shoppingCartService.cleanShoppingCart();
|
shoppingCartService.cleanShoppingCart();
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* subtract an item from the shopping cart
|
||||||
|
* @param shoppingCartDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/sub")
|
||||||
|
@ApiOperation("subtract an item from the shopping cart")
|
||||||
|
public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO){
|
||||||
|
shoppingCartService.subtractFromShoppingCart(shoppingCartDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,4 +45,10 @@ public interface ShoppingCartMapper {
|
|||||||
*/
|
*/
|
||||||
@Delete("delete from sky_take_out.shopping_cart where user_id = #{userId}")
|
@Delete("delete from sky_take_out.shopping_cart where user_id = #{userId}")
|
||||||
void clean(Long userId);
|
void clean(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete the item that number is 0 from the shopping cart
|
||||||
|
* @param shoppingCart
|
||||||
|
*/
|
||||||
|
void delete(ShoppingCart shoppingCart);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,4 +27,10 @@ public interface ShoppingCartService {
|
|||||||
* clean shopping cart
|
* clean shopping cart
|
||||||
*/
|
*/
|
||||||
void cleanShoppingCart();
|
void cleanShoppingCart();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* subtract an item from the shopping cart
|
||||||
|
* @param shoppingCartDTO
|
||||||
|
*/
|
||||||
|
void subtractFromShoppingCart(ShoppingCartDTO shoppingCartDTO);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,4 +94,28 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
|
|||||||
Long userId = BaseContext.getCurrentId();
|
Long userId = BaseContext.getCurrentId();
|
||||||
shoppingCartMapper.clean(userId);
|
shoppingCartMapper.clean(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* subtract an item from the shopping cart
|
||||||
|
* @param shoppingCartDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void subtractFromShoppingCart(ShoppingCartDTO shoppingCartDTO) {
|
||||||
|
//construct an object that contains the basic properties : userId, set meal/dish id, dish flavor
|
||||||
|
ShoppingCart shoppingCart = new ShoppingCart();
|
||||||
|
BeanUtils.copyProperties(shoppingCartDTO, shoppingCart);
|
||||||
|
shoppingCart.setUserId(BaseContext.getCurrentId());
|
||||||
|
|
||||||
|
List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);
|
||||||
|
if (!list.isEmpty()) {
|
||||||
|
shoppingCart = list.get(0);
|
||||||
|
//check the number of shopping cart
|
||||||
|
if (shoppingCart.getNumber() > 1) {
|
||||||
|
shoppingCart.setNumber(shoppingCart.getNumber() - 1);
|
||||||
|
shoppingCartMapper.updateNumberById(shoppingCart);
|
||||||
|
} else {
|
||||||
|
shoppingCartMapper.delete(shoppingCart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,23 @@
|
|||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.sky.mapper.ShoppingCartMapper">
|
<mapper namespace="com.sky.mapper.ShoppingCartMapper">
|
||||||
|
<delete id="delete">
|
||||||
|
delete from sky_take_out.shopping_cart
|
||||||
|
<where>
|
||||||
|
<if test="userId != null">
|
||||||
|
and user_id = #{userId}
|
||||||
|
</if>
|
||||||
|
<if test="setmealId != null">
|
||||||
|
and setmeal_id = #{setmealId}
|
||||||
|
</if>
|
||||||
|
<if test="dishId!= null">
|
||||||
|
and dish_id = #{dishId}
|
||||||
|
</if>
|
||||||
|
<if test="dishFlavor != null">
|
||||||
|
and dish_flavor = #{dishFlavor}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</delete>
|
||||||
|
|
||||||
<select id="list" resultType="com.sky.entity.ShoppingCart">
|
<select id="list" resultType="com.sky.entity.ShoppingCart">
|
||||||
select * from sky_take_out.shopping_cart
|
select * from sky_take_out.shopping_cart
|
||||||
|
|||||||
Reference in New Issue
Block a user