package com.ruoyi.web.controller.liandao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.DeleteBody;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.liandao.domain.ArticleContent;
import com.ruoyi.liandao.dto.articleContent.ArticleContentAddReqDto;
import com.ruoyi.liandao.dto.articleContent.ArticleContentEditReqDto;
import com.ruoyi.liandao.dto.articleContent.ArticleContentPageReqDto;
import com.ruoyi.liandao.service.ArticleContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 文章内容接口
 *
 * @Author : chenzhengyu
 * @create 2024/3/15 10:30
 */
@RestController
@RequestMapping("/liandao/article/content")
public class ArticleContentController extends BaseController {

    @Autowired
    private ArticleContentService service;

    /**
     * 分页查询
     *
     * @param dto
     * @return
     */
    @GetMapping("/page")
    public TableDataInfo page(ArticleContentPageReqDto dto) {
        IPage<ArticleContent> iPage = service.getPage(dto);
        return getDataTable(iPage);
    }


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

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

    /**
     * 根据id查询详情
     *
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public AjaxResult detail(@RequestParam Long id) {
        ArticleContent 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();
    }


}
