/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.base.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.base.entity.Connection;
import com.tofly.base.service.ConnectionService;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 空间库连接配置信息表
 *
 * @author admin
 * @date Thu Oct 10 00:00:00 CST 2019
 */
@RestController
@AllArgsConstructor
@RequestMapping("/connection")
@Api(tags="空间库连接配置信息表接口")
public class ConnectionController {

    private final  ConnectionService connectionService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param connection 空间库连接配置信息表
    * @return
    */
    @GetMapping("/page" )
    //@ApiOperation(value = "分页查询")
    public ResultRespone getConnectionPage(Page page, @ModelAttribute Connection connection) {
      return ResultRespone.success(connectionService.page(page, Wrappers.query(connection)));
    }


    /**
     * 通过id查询空间库连接配置信息表
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    //@ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("id" ) Long id) {
      return ResultRespone.success(connectionService.getById(id));
    }

    /**
     * 新增空间库连接配置信息表
     * @param connection 空间库连接配置信息表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增空间库连接配置信息表" )
    //@ApiOperation(value = "新增空间库连接配置信息表")
    @PostMapping
    public ResultRespone save(@RequestBody Connection connection) {
      return ResultRespone.success(connectionService.save(connection));
    }

    /**
     * 修改空间库连接配置信息表
     * @param connection 空间库连接配置信息表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改空间库连接配置信息表" )
    //@ApiOperation(value = "修改空间库连接配置信息表")
    @PutMapping
    public ResultRespone updateById(@RequestBody Connection connection) {
      return ResultRespone.success(connectionService.updateById(connection));
    }

    /**
     * 通过id删除空间库连接配置信息表
     * @param id id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id删除空间库连接配置信息表" )
    //@ApiOperation(value = "通过ID删除空间库连接配置信息表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeById(@PathVariable Long id) {
      return ResultRespone.success(connectionService.removeById(id));
    }
}
