package com.test.test.controller;

import java.util.List;

import com.test.test.domain.qo.IDQO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.test.common.annotation.Log;
import com.test.common.core.controller.BaseController;
import com.test.common.core.domain.AjaxResult;
import com.test.common.enums.BusinessType;
import com.test.test.domain.TestDatasource;
import com.test.test.service.ITestDatasourceService;

/**
 * 数据源Controller
 */
@RestController
@RequestMapping("/test/datasource")
public class TestDatasourceController extends BaseController {
    @Resource
    private ITestDatasourceService testDatasourceService;

    /**
     * 查询数据源列表
     */
    @GetMapping("/list")
    public AjaxResult list() {
        List<TestDatasource> list = testDatasourceService.selectTestDatasourceList();
        return success(list);
    }

    /**
     * 获取数据源详细信息
     */
    @PostMapping(value = "/detail")
    public AjaxResult getInfo(@RequestBody IDQO qo) {
        return success(testDatasourceService.selectTestDatasourceById(qo.getId()));
    }

    /**
     * 新增数据源
     */
    @Log(title = "数据源", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TestDatasource testDatasource) {
        return success(testDatasourceService.insertTestDatasource(testDatasource));
    }

    /**
     * 修改数据源
     */
    @Log(title = "数据源", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody TestDatasource testDatasource) {
        return toAjax(testDatasourceService.updateTestDatasource(testDatasource));
    }

    /**
     * 删除数据源
     */
    @Log(title = "数据源", businessType = BusinessType.DELETE)
    @PostMapping("/del")
    public AjaxResult remove(@RequestBody IDQO qo) {
        return toAjax(testDatasourceService.deleteTestDatasourceById(qo.getId()));
    }
}
