package com.sckw.goods.controller;

import com.sckw.goods.entity.req.CategoryInsertParam;
import com.sckw.goods.entity.req.CategoryUpdateParam;
import com.sckw.goods.service.CategoryService;
import com.sckw.core.web.response.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc:
 * @author: Lt
 * @date: 2024-04-26
 */
@Validated
@RestController
@RequestMapping("/goods/category")
public class CategoryController {

    @Autowired
    CategoryService categoryService;
    @GetMapping("/findList")
    public HttpResult findList(@RequestParam(value = "name", required = false) String name)
    {
        return HttpResult.ok(categoryService.findList(name));
    }


    /**
    * @Description: 新增
    * @Author: Lt
    * @Date: 2024/4/26 16:08
    */
    @PostMapping("/insert")
    public HttpResult insert(@RequestBody @Validated CategoryInsertParam categoryInsertParam)
    {
        return HttpResult.ok(categoryService.insert(categoryInsertParam));
    }

    /**
    * @Description: 分类编辑
    * @Author: Lt
    * @Date: 2024/4/26 16:49
    */
    @PostMapping("/update")
    public HttpResult update(@RequestBody @Validated CategoryUpdateParam categoryUpdateParam)
    {
        return HttpResult.ok(categoryService.update(categoryUpdateParam));
    }

    /**
     * 删除
     *
     * @return
     */
    @PostMapping("/delete")
    public HttpResult delete(@RequestParam(value = "ids") List<Long> ids) {
        int result = categoryService.delete(ids);
        return HttpResult.ok(result);
    }




}
