package org.springblade.community.grid.feign;

import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springblade.community.grid.entity.GridResource;
import org.springblade.community.grid.vo.GridResourceVO;
import org.springblade.community.grid.wrapper.GridResourceWrapper;
import org.springblade.community.grid.service.IGridResourceService;

import java.util.List;
/**
 *  client
 *
 * @author lianghanqiang
 * @since 2021-03-23
 */

@AllArgsConstructor
@RestController
@RequestMapping("/feign/gridresource")

public class GridResourceClient implements IGridResourceClient {

    private final IGridResourceService gridResourceService;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public GridResourceVO detail(GridResource gridResource) {
        GridResource detail = gridResourceService.getOne(Condition.getQueryWrapper(gridResource));
        return GridResourceWrapper.build().entityVO(detail);
        }

    /**
     * 查询
     */
    @Override
    @GetMapping("/list")
    public List<GridResourceVO> list(GridResource gridResource) {
        return GridResourceWrapper.build().listVO(gridResourceService.list(Condition.getQueryWrapper(gridResource)));
        }



    /**
     * 新增
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody GridResource gridResource) {
        return gridResourceService.save(gridResource);
        }

    /**
     * 修改
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody GridResource gridResource) {
        return gridResourceService.updateById(gridResource);
        }

    /**
     * 新增或修改
     */
    @Override
    @PostMapping("/submit")
    public boolean submit(@Valid @RequestBody GridResource gridResource) {
        return gridResourceService.saveOrUpdate(gridResource);
        }


    /**
     * 删除
     */
    @Override
    @PostMapping("/remove")
    public boolean remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return gridResourceService.deleteLogic(Func.toLongList(ids));
        }


}
