package com.jiayue.ipp.idp.controller.an;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiayue.ipp.common.data.entity.an.ParsingChannel;
import com.jiayue.ipp.idp.service.an.ParsingChannelService;
import com.jiayue.ipp.idp.util.R;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/parsingChannel")
@RequiredArgsConstructor
public class ParsingChannelController {
    private final ParsingChannelService parsingChannelService;


    @ApiOperation(value = "添加通道", notes = "添加通道")
    @PostMapping()
    public Boolean add(@RequestBody ParsingChannel parsingChannel) {
        return parsingChannelService.save(parsingChannel);
    }

    @ApiOperation(value = "修改通道", notes = "修改通道")
    @PutMapping()
    public Boolean update(@RequestBody ParsingChannel parsingChannel) {
        return parsingChannelService.updateById(parsingChannel);
    }


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


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

    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R page(Page page, ParsingChannel parsingChannel) {
        return R.ok(parsingChannelService.page(page, Wrappers.query(parsingChannel)));
    }

}
