package cn.pluss.platform.controller.store;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.device.MercShopTrolleyService;
import cn.pluss.platform.entity.MercShopTrolley;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.vo.DeviceGoodsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author djh
 */
@RestController
@RequestMapping("/mercShopTrolley")
public class MercShopTrolleyController {

    @Autowired
    private MercShopTrolleyService baseService;

    @PostMapping("/addOne")
    public Result<Object> addOne(@RequestBody MercShopTrolley entity) {
        baseService.apiAdd(entity);
        return ResultGenerator.genSuccessResult("已添加到购物车", null);
    }

    @GetMapping("/shopTrolleyList")
    public Result<List<DeviceGoodsVO>> shopTrolleyList() {
        List<DeviceGoodsVO> res = baseService.apiShopTrolleyList();
        return ResultGenerator.genSuccessResult("操作成功", res);
    }

    @GetMapping("/remove/{id}")
    public Result<Object> removeById(@PathVariable("id") Long id) {
        baseService.removeById(id);

        return ResultGenerator.genSuccessResult("操作成功", null);
    }

    @PostMapping("/remove")
    public Result<Object> removeByIds(@RequestBody List<Long> ids) {
        baseService.removeByIds(ids);
        return ResultGenerator.genSuccessResult("操作成功", null);
    }

    @PostMapping("/update")
    public Result<Object> updateById(@RequestBody MercShopTrolley entity) {
        if (entity.getId() == null) {
            throw new MsgException("参数异常");
        }

        baseService.apiUpdate(entity);

        return ResultGenerator.genSuccessResult("操作成功", null);
    }
}
