package com.tuoheng.admin.controller;

import com.tuoheng.admin.entity.domain.Goods;
import com.tuoheng.admin.entity.request.goods.QueryGoodsListByWarehouseIdRequest;
import com.tuoheng.admin.service.goods.IGoodsService;
import com.tuoheng.common.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @desc: 仓库物资 前端控制器
 * @team: tuoheng
 * @author: wanjing
 * @date: 2023-02-06
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private IGoodsService goodsService;

    /**
     * 根据仓库ID查询物资列表
     */
    @GetMapping("/list/by/warehouseid")
    public JsonResult getListByWarehouseId(QueryGoodsListByWarehouseIdRequest request) {
        return goodsService.getListByWarehouseId(request);
    }

    /**
     * 添加物资
     *
     * @param entity 实体对象
     * @return
     */
    @PostMapping("/add")
    public JsonResult add(@RequestBody Goods entity) {
        return goodsService.editInfo(entity);
    }

    /**
     * 编辑物资
     *
     * @param entity 实体对象
     * @return
     */
    @PutMapping("/edit")
    public JsonResult edit(@RequestBody Goods entity) {
        return goodsService.editInfo(entity);
    }

    /**
     * 删除物资
     *
     * @param ids 物资ID
     * @return
     */
    @DeleteMapping("/delete/{ids}")
    public JsonResult delete(@PathVariable("ids") Integer[] ids) {
        return goodsService.deleteByIds(ids);
    }


}
