package com.fjhx.controller;

import com.alibaba.fastjson.JSONObject;
import com.fjhx.entity.Classify;
import com.fjhx.service.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.List;
import java.util.Map;

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

    @Autowired
    private ClassifyService classifyService;

    @PostMapping("/tree")
    public R page(@RequestBody Map<String, String> condition) {
        List<JSONObject> result = classifyService.getTree(condition);
        return R.success(result);
    }

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

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

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

}

