package com.fdkankan.platform.user.controller.api;

import com.fdkankan.platform.goods.service.ICartService;
import com.fdkankan.platform.user.request.RequestCart;
import com.fdkankan.platform.user.vo.ResponseCart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 个人中心-用户购物车模块
 */
@RestController
@RequestMapping("/service/platform/user/cart")
public class UserCarController {

    private static Logger log = LoggerFactory.getLogger("programLog");

    @Autowired
    private ICartService cartService;


    /**
     * 添加购物车
     * goodsId      商品id
     * skuSn        商品编码
     * goodsCount   商品数量
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String add(@RequestBody RequestCart param, @RequestHeader String token) throws Exception {
        return cartService.addCart(param,token);
    }

    /**
     * 查找会员的购物车记录
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public List<ResponseCart> list(@RequestBody RequestCart param, @RequestHeader String token) throws Exception {
        return cartService.getCartList(param,token);
    }

    /**
     * 购物车商品减或移除
     * goodsId      商品id
     * goodsCount   商品数量
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public String remove(@RequestBody RequestCart param, @RequestHeader String token) throws Exception {
        return cartService.removeCart(param,token);
    }

    /**
     * 删除购物车
     * ids          id组合
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public String delete(@RequestBody RequestCart param, @RequestHeader String token) throws Exception {
        return cartService.removeCarts(param,token);
    }

}
