package com.fjhx.controller.classify;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.entity.classify.Classify;
import com.fjhx.params.classify.ClassifyVo;
import com.fjhx.service.classify.ClassifyService;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 分类 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-11-24
 */
@RestController
@RequestMapping("/classify")
public class ClassifyController {

    @Autowired
    private ClassifyService classifyService;

    @PostMapping("/page")
    public R page(@RequestBody Map<String, Object> condition) {
        Page<Classify> result = classifyService.getPage(condition);
        return R.success(result);
    }

    @PostMapping("/add")
    public R add(@RequestBody ClassifyVo classifyVo) {
        classifyService.add(classifyVo);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@RequestBody ClassifyVo classifyVo) {
        classifyService.edit(classifyVo);
        return R.success();
    }

    @PostMapping("/delete")
    public R delete(@RequestBody ClassifyVo classifyVo) {
        classifyService.delete(classifyVo);
        return R.success();
    }

    @PostMapping("/tree")
    public R tree(@RequestBody ClassifyVo entity) {
        return R.success(classifyService.tree(entity));
    }

    @PostMapping("/details")
    public R details(@RequestBody ClassifyVo entity) {
        return R.success(classifyService.getById(entity.getId()));
    }

}

