package com.ruoyi.web.controller.liandao;

import cn.hutool.core.lang.tree.Tree;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.DeleteBody;
import com.ruoyi.liandao.domain.ArticleType;
import com.ruoyi.liandao.dto.articleType.ArticleTypeAddReqDto;
import com.ruoyi.liandao.dto.articleType.ArticleTypeEditReqDto;
import com.ruoyi.liandao.dto.articleType.ArticleTypeListReqDto;
import com.ruoyi.liandao.dto.articleType.ArticleTypeListRespDto;
import com.ruoyi.liandao.service.ArticleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文章类型配置接口
 *
 * @Author : chenzhengyu
 * @create 2024/3/15 9:08
 */
@RestController
@RequestMapping("/liandao/article/type")
public class ArticleTypeController extends BaseController {

    @Autowired
    private ArticleTypeService service;

    /**
     * 获取列表
     *
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list(ArticleTypeListReqDto dto) {
        List<Tree<Long>> result = service.getList(dto);
        return success(result);
    }

    /**
     * 新增
     *
     * @param dto
     * @return
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ArticleTypeAddReqDto dto) {
        service.add(dto);
        return success();
    }

    /**
     * 修改
     *
     * @param dto
     * @return
     */
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ArticleTypeEditReqDto dto) {
        service.edit(dto);
        return success();
    }

    /**
     * 根据id查询详情
     *
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public AjaxResult detail(@RequestParam Long id) {
        ArticleType result = service.getById(id);
        return success(result);
    }

    /**
     * 根据id删除
     *
     * @param deleteBody
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody DeleteBody deleteBody) {
        service.removeById(deleteBody.getId());
        return success();
    }
}
