package cn.fateverse.query.controller;

import cn.fateverse.common.core.result.Result;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.core.utils.LongUtils;
import cn.fateverse.query.entity.DynamicTable;
import cn.fateverse.query.entity.query.DynamicTableQuery;
import cn.fateverse.query.service.DynamicDataSourceTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Clay
 * @date 2023-07-16
 */
@Api(value = "动态数据源表格管理",tags = "动态数据源表格管理")
@RestController
@RequestMapping("/dynamic/table")
public class DynamicDataSourceTableController {

    private final DynamicDataSourceTableService dynamicDataSourceTableService;

    public DynamicDataSourceTableController(DynamicDataSourceTableService dynamicDataSourceTableService) {
        this.dynamicDataSourceTableService = dynamicDataSourceTableService;
    }

    @ApiOperation("获取数据源信息")
    @GetMapping
    @PreAuthorize("@ss.hasPermission('query:dynamic-table:list')")
    public Result<TableDataInfo<DynamicTable>> test(DynamicTableQuery query, Long dataSourceId) {
        if (LongUtils.isNull(dataSourceId)){
            return Result.error("数据源id不能为空!");
        }
        TableDataInfo<DynamicTable> dataInfo = dynamicDataSourceTableService.searchTableList(query, dataSourceId);
        return Result.ok(dataInfo);
    }

}
