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.ResourcesConfig;
import com.ruoyi.liandao.dto.resourcesConfig.ResourcesConfigAddReqDto;
import com.ruoyi.liandao.dto.resourcesConfig.ResourcesConfigEditReqDto;
import com.ruoyi.liandao.dto.resourcesConfig.ResourcesConfigPageReqDto;
import com.ruoyi.liandao.service.ResourcesConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 资源配置接口
 * @Author : chenzhengyu
 * @create 2024/3/14 13:43
 */
@RestController
@RequestMapping("/liandao/resources/config")
public class ResourcesConfigController extends BaseController {

    @Autowired
    private ResourcesConfigService service;

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

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

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

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


}
