package jnpf.cultivate.v2.controller.web.identify;


import jnpf.base.ActionResult;
import jnpf.cultivate.v2.service.FtbCultivateIdentifyCategoriesService;
import jnpf.model.cultivate.po.FtbCultivateIdentifyCategories;
import jnpf.model.cultivate.v2.identify.req.QueryIdentifyCategoryListReq;
import jnpf.model.cultivate.v2.identify.req.V2SaveItemCategoryReq;
import jnpf.model.cultivate.v2.identify.vo.V2IdentifyCategoryTreeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * web实操鉴项 分类模块
 *
 * @author xgl
 * @since 2024-05-08 09:51:36
 */
@RestController
@RequestMapping("/v2/web/identify/category")
public class V2CultivateIdentifyCategoriesController {


    @Autowired
    private FtbCultivateIdentifyCategoriesService ftbCultivateIdentifyCategoriesService;


    /**
     * 查询分类接口
     *
     * @param req 查询参数
     * @return 查询结果
     */
    @GetMapping("/list")
    public ActionResult<List<V2IdentifyCategoryTreeVo>> lists(QueryIdentifyCategoryListReq req) {
        return ActionResult.success("成功", ftbCultivateIdentifyCategoriesService.getCategoryTree(req));
    }


    /**
     * 添加分类
     *
     * @param req 添加参数
     * @return 添加结果
     */
    @PostMapping("/add")
    public ActionResult<FtbCultivateIdentifyCategories> add(@RequestBody @Valid V2SaveItemCategoryReq req) {
        return ActionResult.success("添加成功", ftbCultivateIdentifyCategoriesService.insertData(req));
    }

    /**
     * 修改分类
     *
     * @param id  分类ID
     * @param req 修改参数
     * @return 修改结果
     */
    @PutMapping("/update/{id}")
    public ActionResult<FtbCultivateIdentifyCategories> update(@PathVariable("id") String id, @RequestBody @Valid V2SaveItemCategoryReq req) {
        return ActionResult.success("编辑成功", ftbCultivateIdentifyCategoriesService.updateData(id, req));
    }


    /**
     * 删除分类
     *
     * @param id 分类ID
     * @return 删除结果
     */
    @DeleteMapping("/del/{id}")
    public ActionResult<Boolean> del(@PathVariable("id") String id) {
        ftbCultivateIdentifyCategoriesService.deleteData(id);
        return ActionResult.success("删除成功", true);
    }


}

