package com.cpp.web.controller.configManager;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpp.common.core.domain.R;
import com.cpp.web.domain.datafactory.FtpChannel;
import com.cpp.web.service.datafactory.FtpChannelService;
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("/ftpChannel")
@AllArgsConstructor
public class FtpChannelController {

    private final FtpChannelService ftpChannelService;


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

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

    }


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

    }

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

    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R page(FtpChannel ftpChannel, Page page) {

        return R.ok(ftpChannelService.page(page, Wrappers.query(ftpChannel)));
    }
}
