clean shopping cart

This commit is contained in:
2024-12-18 22:50:10 +08:00
parent 4734a67b59
commit cf18e8bd82
4 changed files with 32 additions and 0 deletions

View File

@@ -43,7 +43,16 @@ public class ShoppingCartController {
@GetMapping("/list")
@ApiOperation("list shopping cart")
public Result<List<ShoppingCart>> list(){
log.info("list shopping cart");
List<ShoppingCart> list = shoppingCartService.listShoppingCart();
return Result.success(list);
}
@DeleteMapping("/clean")
@ApiOperation("clean the shopping cart")
public Result clean(){
log.info("clean shopping cart");
shoppingCartService.cleanShoppingCart();
return Result.success();
}
}

View File

@@ -1,6 +1,7 @@
package com.sky.mapper;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
@@ -37,4 +38,11 @@ public interface ShoppingCartMapper {
@Insert("insert into sky_take_out.shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) " +
"values (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime})")
void insert(ShoppingCart shoppingCart);
/**
* clean shopping cart
* @param userId
*/
@Delete("delete from sky_take_out.shopping_cart where user_id = #{userId}")
void clean(Long userId);
}

View File

@@ -22,4 +22,9 @@ public interface ShoppingCartService {
* @return
*/
List<ShoppingCart> listShoppingCart();
/**
* clean shopping cart
*/
void cleanShoppingCart();
}

View File

@@ -84,4 +84,14 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
.build();
return shoppingCartMapper.list(shoppingCart);
}
/**
* clean shopping cart
*/
@Override
public void cleanShoppingCart() {
Long userId = BaseContext.getCurrentId();
shoppingCartMapper.clean(userId);
}
}