package com.muyu.saas.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.saas.domain.Datasource;
import com.muyu.saas.service.SaasService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("saas")
public class SaaSController {

    @Autowired
    private SaasService saasService;

    /**
     * 数据源查询
     * @return
     */
    @GetMapping("findDatabaseList")
    public Result<List<Datasource>> findDatabaseList(){
      List<Datasource> list=saasService.list();
        return Result.success(list);
    };

    /**
     * 数据源添加
     * @param datasource
     * @return
     */
    @PostMapping("addDatasource")
    public Result addDatasource(@RequestBody Datasource datasource){
      saasService.save(datasource);
      return Result.success("添加成功");
    };


    @PostMapping("updDatasource")
    public Result updDatasource(@RequestBody Datasource datasource){
        saasService.updateById(datasource);
        return Result.success("修改成功");
    }

    /**
     * 删除成功
     * @param id
     * @return
     */
    @PostMapping("delDatasource/{id}")
    public Result delDatasource(@PathVariable("id") Integer id){
        saasService.removeById(id);
        return Result.success("删除成功");
    }







}
