package com.cpp.web.controller.configManager;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpp.common.core.domain.R;
import com.cpp.web.domain.datafactory.SftpChannel;
import com.cpp.web.service.datafactory.SftpChannelService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/sftpChannel")
@AllArgsConstructor
public class SftpChannelController {

    private final SftpChannelService sftpChannelService;


    @ApiOperation(value = "添加ftp通道", notes = "添加ftp通道")
    @PostMapping()
    public Boolean add(@RequestBody SftpChannel sftpChannel) {
        return sftpChannelService.save(sftpChannel);
    }

    @ApiOperation(value = "修改ftp通道", notes = "修改ftp通道")
    @PutMapping()
    public Boolean update(@RequestBody SftpChannel sftpChannel) {
        return sftpChannelService.updateById(sftpChannel);

    }


    @ApiOperation(value = "根据id删除ftp通道", notes = "根据id删除ftp通道")
    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable String id) {
        return sftpChannelService.removeById(id);

    }

    @ApiOperation(value = "查询所有ftp通道", notes = "查询所有ftp通道")
    @GetMapping()
    public List<SftpChannel> getAll() {
         return sftpChannelService.list();
    }

    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R page(Long currentPage,Long pageSize) {
        Page page = new Page(currentPage, pageSize);
        page.setMaxLimit((long) -1);
        return R.ok(sftpChannelService.page(page));
    }
}
