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.springblade.system.user.feign.IUserClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springblade.community.grid.entity.Grid;
import org.springblade.community.grid.vo.GridVO;
import org.springblade.community.grid.wrapper.GridWrapper;
import org.springblade.community.grid.service.IGridService;

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

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

public class GridClient implements IGridClient {

    private final IGridService gridService;
    private final IUserClient userClient;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public GridVO detail(Grid grid) {
        Grid detail = gridService.getOne(Condition.getQueryWrapper(grid));
        return GridWrapper.build(gridService, userClient).entityVO(detail);
        }

    /**
     * 查询
     */
    @Override
    @GetMapping("/list")
    public List<GridVO> list(Grid grid) {
        return GridWrapper.build(gridService, userClient).listVO(gridService.list(Condition.getQueryWrapper(grid)));
        }



    /**
     * 新增
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody Grid grid) {
        return gridService.save(grid);
        }

    /**
     * 修改
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody Grid grid) {
        return gridService.updateById(grid);
        }

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


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


}
